|
| 1 | +import responses # https://github.com/getsentry/responses |
| 2 | + |
| 3 | +from verda.long_term import LongTermPeriod, LongTermService |
| 4 | + |
| 5 | +PERIODS_PAYLOAD = [ |
| 6 | + { |
| 7 | + 'code': '1-month', |
| 8 | + 'name': '1 Month', |
| 9 | + 'is_enabled': True, |
| 10 | + 'unit_name': 'month', |
| 11 | + 'unit_value': 1, |
| 12 | + 'discount_percentage': 5, |
| 13 | + } |
| 14 | +] |
| 15 | + |
| 16 | + |
| 17 | +class TestLongTermService: |
| 18 | + @responses.activate |
| 19 | + def test_get_periods(self, http_client): |
| 20 | + endpoint = http_client._base_url + '/long-term/periods' |
| 21 | + responses.add(responses.GET, endpoint, json=PERIODS_PAYLOAD, status=200) |
| 22 | + |
| 23 | + service = LongTermService(http_client) |
| 24 | + |
| 25 | + periods = service.get() |
| 26 | + |
| 27 | + assert isinstance(periods, list) |
| 28 | + assert len(periods) == 1 |
| 29 | + assert isinstance(periods[0], LongTermPeriod) |
| 30 | + assert periods[0].code == '1-month' |
| 31 | + assert periods[0].discount_percentage == 5 |
| 32 | + assert responses.assert_call_count(endpoint, 1) is True |
| 33 | + |
| 34 | + @responses.activate |
| 35 | + def test_get_instance_periods(self, http_client): |
| 36 | + endpoint = http_client._base_url + '/long-term/periods/instances' |
| 37 | + responses.add(responses.GET, endpoint, json=PERIODS_PAYLOAD, status=200) |
| 38 | + |
| 39 | + service = LongTermService(http_client) |
| 40 | + |
| 41 | + periods = service.get_instances() |
| 42 | + |
| 43 | + assert len(periods) == 1 |
| 44 | + assert periods[0].unit_name == 'month' |
| 45 | + assert responses.assert_call_count(endpoint, 1) is True |
| 46 | + |
| 47 | + @responses.activate |
| 48 | + def test_get_cluster_periods(self, http_client): |
| 49 | + endpoint = http_client._base_url + '/long-term/periods/clusters' |
| 50 | + responses.add(responses.GET, endpoint, json=PERIODS_PAYLOAD, status=200) |
| 51 | + |
| 52 | + service = LongTermService(http_client) |
| 53 | + |
| 54 | + periods = service.get_clusters() |
| 55 | + |
| 56 | + assert len(periods) == 1 |
| 57 | + assert periods[0].is_enabled is True |
| 58 | + assert responses.assert_call_count(endpoint, 1) is True |
0 commit comments