Skip to content

Commit

Permalink
Merge pull request #113 from azgabur/fields_definitions
Browse files Browse the repository at this point in the history
New client and resource Fields definitions
  • Loading branch information
mganisin authored Nov 24, 2021
2 parents f1b996c + 874af7e commit 0772d01
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,3 +482,18 @@ def invoice_line(invoice, invoice_line_params, api):
entity = invoice.line_items.create(invoice_line_params)
yield entity
cleanup(entity)


@pytest.fixture(scope='module')
def fields_definitions_params():
return dict(name=f"name-{get_suffix()}",
label=f"label-{get_suffix()}",
target="Account",
required="false")


@pytest.fixture(scope="module")
def fields_definition(api, fields_definitions_params):
entity = api.fields_definitions.create(fields_definitions_params)
yield entity
cleanup(entity)
31 changes: 31 additions & 0 deletions tests/integration/test_integration_fields_definitions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from .asserts import assert_resource, assert_resource_params


def test_fields_definitions_create(api, fields_definition, fields_definitions_params):
assert_resource(fields_definition)
assert_resource_params(fields_definition, fields_definitions_params)


def test_fields_definitions_list(api):
assert len(api.fields_definitions.list()) > 0


def test_fields_definitions_read(api):
default_field = api.fields_definitions.list()[0]
read = api.fields_definitions.read(default_field.entity_id)
assert_resource(read)
assert default_field['target'] == read['target']
assert default_field['position'] == read['position']


def test_fields_definitions_update(api, fields_definition):
update_params = dict(target="Cinstance", label="something_else",
hidden="true", read_only="true", position=1)
updated = fields_definition.update(update_params)
assert_resource_params(updated, update_params)


def test_fields_definitions_delete(api, fields_definitions_params):
fields_definitions_params.update(dict(name="something_else"))
created = api.fields_definitions.create(fields_definitions_params)
assert api.fields_definitions.delete(created.entity_id)
6 changes: 6 additions & 0 deletions threescale_api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def __init__(self, url: str, token: str, throws: bool = True, ssl_verify: bool =
self._backends = resources.Backends(self, instance_klass=resources.Backend)
self._webhooks = resources.Webhooks(self)
self._invoices = resources.Invoices(self, instance_klass=resources.Invoice)
self._fields_definitions =\
resources.FieldsDefinitions(self, instance_klass=resources.FieldsDefinition)

@property
def rest(self) -> 'RestApiClient':
Expand Down Expand Up @@ -211,6 +213,10 @@ def webhooks(self) -> resources.Webhooks:
def invoices(self) -> resources.Invoices:
return self._invoices

@property
def fields_definitions(self) -> resources.FieldsDefinitions:
return self._fields_definitions


class RestApiClient:
def __init__(self, url: str, token: str, throws: bool = True, ssl_verify: bool = True):
Expand Down
15 changes: 15 additions & 0 deletions threescale_api/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,16 @@ def charge(self, entity_id: int):
return instance


class FieldsDefinitions(DefaultClient):
def __init__(self, *args, entity_name='fields_definition',
entity_collection='fields_definitions', **kwargs):
super().__init__(*args, entity_name=entity_name,
entity_collection=entity_collection, **kwargs)

@property
def url(self) -> str:
return self.threescale_client.admin_api_url + '/fields_definitions'

# Resources


Expand Down Expand Up @@ -1418,6 +1428,11 @@ def charge(self):
return self.client.charge(entity_id=self.entity_id)


class FieldsDefinition(DefaultResource):
def __init__(self, entity_name='name', **kwargs):
super().__init__(entity_name=entity_name, **kwargs)


class AdminPortalAuthProvider(DefaultResource):
def __init__(self, entity_name='name', **kwargs):
super().__init__(entity_name=entity_name, **kwargs)
Expand Down

0 comments on commit 0772d01

Please sign in to comment.