|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# |
| 3 | +# Copyright (C) 2021 Roald Nefs <info@roaldnefs.com> |
| 4 | +# |
| 5 | +# This file is part of python-transip. |
| 6 | +# |
| 7 | +# python-transip is free software: you can redistribute it and/or modify |
| 8 | +# it under the terms of the GNU Lesser General Public License as published by |
| 9 | +# the Free Software Foundation, either version 3 of the License, or |
| 10 | +# (at your option) any later version. |
| 11 | +# |
| 12 | +# python-transip is distributed in the hope that it will be useful, |
| 13 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | +# GNU Lesser General Public License for more details. |
| 16 | +# |
| 17 | +# You should have received a copy of the GNU Lesser General Public License |
| 18 | +# along with python-transip. If not, see <https://www.gnu.org/licenses/>. |
| 19 | + |
| 20 | +from typing import List, Tuple, Any, Dict, Optional |
| 21 | +import responses # type: ignore |
| 22 | +import unittest |
| 23 | +import tempfile |
| 24 | +import os |
| 25 | + |
| 26 | +from transip import TransIP |
| 27 | +from transip.v6.objects import Product, ProductElement |
| 28 | +from tests.utils import load_responses_fixtures |
| 29 | + |
| 30 | + |
| 31 | +class ProductsTest(unittest.TestCase): |
| 32 | + """Test the ProductsService.""" |
| 33 | + |
| 34 | + client: TransIP |
| 35 | + |
| 36 | + @classmethod |
| 37 | + def setUpClass(cls) -> None: |
| 38 | + """Set up a minimal TransIP client for using the invoice services.""" |
| 39 | + cls.client = TransIP(access_token='ACCESS_TOKEN') |
| 40 | + |
| 41 | + def setUp(self) -> None: |
| 42 | + """Setup mocked responses for the '/products' endpoint.""" |
| 43 | + load_responses_fixtures("general.json") |
| 44 | + |
| 45 | + @responses.activate |
| 46 | + def test_list(self) -> None: |
| 47 | + """Check if the products can be listed.""" |
| 48 | + products: List[Product] = self.client.products.list() # type: ignore |
| 49 | + |
| 50 | + self.assertEqual(len(products), 5) |
| 51 | + |
| 52 | + @responses.activate |
| 53 | + def test_elements_list(self) -> None: |
| 54 | + """Check if the elements of a product can be listed.""" |
| 55 | + products: List[Product] = self.client.products.list() # type: ignore |
| 56 | + product: Optional[Product] = None |
| 57 | + |
| 58 | + # Find the correct product as the API doesn't provide an option to |
| 59 | + # retrieve a single product |
| 60 | + for entry in products: |
| 61 | + if entry.get_id() == 'vps-bladevps-x4': |
| 62 | + product = entry |
| 63 | + break |
| 64 | + |
| 65 | + self.assertIsNotNone(product) |
| 66 | + |
| 67 | + elements = product.elements.list() # type: ignore |
| 68 | + self.assertEqual(len(elements), 1) |
| 69 | + self.assertEqual(elements[0].get_id(), 'ipv4Addresses') # type: ignore |
0 commit comments