Skip to content

Commit 0772d01

Browse files
author
mganisin
authored
Merge pull request 3scale-qe#113 from azgabur/fields_definitions
New client and resource Fields definitions
2 parents f1b996c + 874af7e commit 0772d01

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed

tests/integration/conftest.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,3 +482,18 @@ def invoice_line(invoice, invoice_line_params, api):
482482
entity = invoice.line_items.create(invoice_line_params)
483483
yield entity
484484
cleanup(entity)
485+
486+
487+
@pytest.fixture(scope='module')
488+
def fields_definitions_params():
489+
return dict(name=f"name-{get_suffix()}",
490+
label=f"label-{get_suffix()}",
491+
target="Account",
492+
required="false")
493+
494+
495+
@pytest.fixture(scope="module")
496+
def fields_definition(api, fields_definitions_params):
497+
entity = api.fields_definitions.create(fields_definitions_params)
498+
yield entity
499+
cleanup(entity)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from .asserts import assert_resource, assert_resource_params
2+
3+
4+
def test_fields_definitions_create(api, fields_definition, fields_definitions_params):
5+
assert_resource(fields_definition)
6+
assert_resource_params(fields_definition, fields_definitions_params)
7+
8+
9+
def test_fields_definitions_list(api):
10+
assert len(api.fields_definitions.list()) > 0
11+
12+
13+
def test_fields_definitions_read(api):
14+
default_field = api.fields_definitions.list()[0]
15+
read = api.fields_definitions.read(default_field.entity_id)
16+
assert_resource(read)
17+
assert default_field['target'] == read['target']
18+
assert default_field['position'] == read['position']
19+
20+
21+
def test_fields_definitions_update(api, fields_definition):
22+
update_params = dict(target="Cinstance", label="something_else",
23+
hidden="true", read_only="true", position=1)
24+
updated = fields_definition.update(update_params)
25+
assert_resource_params(updated, update_params)
26+
27+
28+
def test_fields_definitions_delete(api, fields_definitions_params):
29+
fields_definitions_params.update(dict(name="something_else"))
30+
created = api.fields_definitions.create(fields_definitions_params)
31+
assert api.fields_definitions.delete(created.entity_id)

threescale_api/client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ def __init__(self, url: str, token: str, throws: bool = True, ssl_verify: bool =
4343
self._backends = resources.Backends(self, instance_klass=resources.Backend)
4444
self._webhooks = resources.Webhooks(self)
4545
self._invoices = resources.Invoices(self, instance_klass=resources.Invoice)
46+
self._fields_definitions =\
47+
resources.FieldsDefinitions(self, instance_klass=resources.FieldsDefinition)
4648

4749
@property
4850
def rest(self) -> 'RestApiClient':
@@ -211,6 +213,10 @@ def webhooks(self) -> resources.Webhooks:
211213
def invoices(self) -> resources.Invoices:
212214
return self._invoices
213215

216+
@property
217+
def fields_definitions(self) -> resources.FieldsDefinitions:
218+
return self._fields_definitions
219+
214220

215221
class RestApiClient:
216222
def __init__(self, url: str, token: str, throws: bool = True, ssl_verify: bool = True):

threescale_api/resources.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,16 @@ def charge(self, entity_id: int):
890890
return instance
891891

892892

893+
class FieldsDefinitions(DefaultClient):
894+
def __init__(self, *args, entity_name='fields_definition',
895+
entity_collection='fields_definitions', **kwargs):
896+
super().__init__(*args, entity_name=entity_name,
897+
entity_collection=entity_collection, **kwargs)
898+
899+
@property
900+
def url(self) -> str:
901+
return self.threescale_client.admin_api_url + '/fields_definitions'
902+
893903
# Resources
894904

895905

@@ -1418,6 +1428,11 @@ def charge(self):
14181428
return self.client.charge(entity_id=self.entity_id)
14191429

14201430

1431+
class FieldsDefinition(DefaultResource):
1432+
def __init__(self, entity_name='name', **kwargs):
1433+
super().__init__(entity_name=entity_name, **kwargs)
1434+
1435+
14211436
class AdminPortalAuthProvider(DefaultResource):
14221437
def __init__(self, entity_name='name', **kwargs):
14231438
super().__init__(entity_name=entity_name, **kwargs)

0 commit comments

Comments
 (0)