|
| 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 Colocation |
| 28 | +from tests.utils import load_responses_fixtures |
| 29 | + |
| 30 | + |
| 31 | +class ColocationsTest(unittest.TestCase): |
| 32 | + """Test the ColocationService.""" |
| 33 | + |
| 34 | + client: TransIP |
| 35 | + |
| 36 | + @classmethod |
| 37 | + def setUpClass(cls) -> None: |
| 38 | + """Set up a minimal TransIP client for using the colocation services.""" |
| 39 | + cls.client = TransIP(access_token='ACCESS_TOKEN') |
| 40 | + |
| 41 | + def setUp(self) -> None: |
| 42 | + """Setup mocked responses for the '/colocations' endpoint.""" |
| 43 | + load_responses_fixtures("colocations.json") |
| 44 | + |
| 45 | + @responses.activate |
| 46 | + def test_list(self) -> None: |
| 47 | + colocations: List[Colocation] = self.client.colocations.list() # type: ignore |
| 48 | + self.assertEqual(len(colocations), 1) |
| 49 | + self.assertEqual(colocations[0].get_id(), "example2") # type: ignore |
| 50 | + |
| 51 | + @responses.activate |
| 52 | + def test_get(self) -> None: |
| 53 | + colocation_name: str = "example2" |
| 54 | + colocation: Colocation = self.client.colocations.get(colocation_name) # type: ignore |
| 55 | + self.assertEqual(colocation.get_id(), colocation_name) # type: ignore |
0 commit comments