Skip to content

Commit 8b9289d

Browse files
committed
Update tests for test_integration_service_subscriptions. Add Service Plan resources.
1 parent c11872a commit 8b9289d

File tree

3 files changed

+28
-48
lines changed

3 files changed

+28
-48
lines changed

tests/integration/conftest.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
Proxy, Backend, Metric, MappingRule,
1414
BackendMappingRule, Account, BackendUsage,
1515
ActiveDoc, Webhooks, InvoiceState,
16-
ApplicationKey, ApplicationPlans, AccountUser, AccountUsers, ServiceSubscription)
16+
ApplicationKey, ApplicationPlans, AccountUser, AccountUsers, ServiceSubscription,
17+
ServicePlan)
1718

1819
load_dotenv()
1920

@@ -149,9 +150,20 @@ def account_user(account,account_user_params) -> AccountUser:
149150
cleanup(user)
150151

151152
@pytest.fixture(scope='module')
152-
def service_subscription_params(account) -> dict:
153-
#suffix = get_suffix()
154-
return dict(plan_id=account['id'])
153+
def service_plan_params() -> dict:
154+
suffix = get_suffix()
155+
return dict(name=f"test-{suffix}")
156+
157+
@pytest.fixture(scope='module')
158+
def service_plan(service, service_plan_params) -> ServicePlan:
159+
160+
resource = service.service_plans.create(params=service_plan_params)
161+
yield resource
162+
163+
@pytest.fixture(scope='module')
164+
def service_subscription_params(service_plan) -> dict:
165+
suffix = get_suffix()
166+
return dict(plan_id=service_plan['id'])
155167

156168
@pytest.fixture(scope='module')
157169
def service_subscription(account, service_subscription_params) -> ServiceSubscription:

tests/integration/test_integration_service_subscriptions.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,21 @@
66

77
from tests.integration import asserts
88

9+
def test_list_service_subscriptions(account, service_subscription):
10+
resource = account.service_subscriptions.list()
11+
assert len(resource) >= 1
12+
913
def test_should_create_service_subscription(account, service_subscription, service_subscription_params):
1014

11-
account.service_subscriptions.create(params=service_subscription_params)
12-
resource = service_subscription.get(service_subscription_params)
13-
asserts.assert_resource(resource)
14-
asserts.assert_resource_params(account, service_subscription_params, [param for param in service_subscription_params.keys() if param != 'id'])
15+
asserts.assert_resource(service_subscription)
16+
asserts.assert_resource_params(service_subscription, service_subscription_params)
1517

1618
def test_should_read_service_subscription(account, service_subscription, service_subscription_params):
17-
resource = account.service_subscriptions.get(params=service_subscription_params)
19+
20+
21+
resource = account.service_subscriptions.read(service_subscription.entity_id)
1822
asserts.assert_resource(resource)
19-
asserts.assert_resource_params(resource, service_subscription_params, [param for param in service_subscription_params.keys() if param != 'id'])
23+
asserts.assert_resource_params(service_subscription,service_subscription_params)
2024

2125
#def test_should_update_service_subscription(account, service_subscription, service_subscription_params):
2226
# service_subscription_params['plan_id'] = 100
@@ -33,7 +37,4 @@ def test_should_read_service_subscription(account, service_subscription, service
3337
# read = account.service_subscriptions.read(service_subscription.entity_id)
3438
# asserts.assert_resource(read)
3539

36-
def test_list_service_subscriptions(account):
37-
resource = account.service_subscriptions.list()
38-
assert len(resource) >= 1
3940

threescale_api/resources.py

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -305,30 +305,10 @@ def __init__(self, *args, entity_name='service_plan',
305305
super().__init__(*args, entity_name=entity_name,
306306
entity_collection=entity_collection, **kwargs)
307307

308+
@property
308309
def url(self) -> str:
309-
if type(self.parent) is Service:
310-
return self.parent.url + '/service_plans'
311-
return self.threescale_client.admin_api_url + '/service_plans'
312-
313-
def service_plans_features_list(self, entity_id: int, **kwargs):
314-
url = self.url + f"/{entity_id}/features.xml"
315-
response = self.rest.get(url=url)
316-
instance = utils.extract_response(response)
317-
return instance
318-
319-
def service_plan_add_feature(self, entity_id: int, feature_id: int, **kwargs):
320-
params = dict(feature_id=feature_id)
321-
url = self.url + f"/{entity_id}/features.xml"
322-
response = self.rest.post(url=url, json=params, **kwargs)
323-
instance = utils.extract_response(response=response)
324-
return instance
310+
return self.parent.url + '/service_plans'
325311

326-
def service_plan_delete_feature(self, entity_id: int, id: int, **kwargs):
327-
params = dict(id=id)
328-
url = self.url + f"/{entity_id}/features/{id}.xml"
329-
response = self.rest.delete(url=url, json=params, **kwargs)
330-
instance = utils.extract_response(response=response)
331-
return instance
332312

333313

334314
class Applications(DefaultStateClient):
@@ -1532,19 +1512,6 @@ class ServicePlan(DefaultResource):
15321512
def __init__(self, **kwargs):
15331513
super().__init__(**kwargs)
15341514

1535-
def service_plan_list(self, **kwargs):
1536-
return self.client.service_plan_list(self, **kwargs)
1537-
1538-
def service_plan_features_list(self, entity_id: int, **kwargs):
1539-
return self.client.service_plan_features_list(entity_id=self.entity_id, **kwargs)
1540-
1541-
def service_plan_add_feature(self, entity_id: int, id: int, **kwargs):
1542-
return self.client.service_plan_add_feature(entity_id=id, id=id, **kwargs)
1543-
1544-
def service_plan_delete_feature(self, entity_id: int, id: int, **kwargs):
1545-
return self.client.service_plan_delete_feature(entity_id=entity_id, id=id, **kwargs)
1546-
1547-
15481515
class ApplicationKey(DefaultResource):
15491516
def __init__(self, entity_name='', **kwargs):
15501517
super().__init__(entity_name=entity_name, **kwargs)

0 commit comments

Comments
 (0)