Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

3scale-api

Package Overview
Dependencies
Maintainers
4
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

3scale-api - npm Package Compare versions

Comparing version
0.29.0
to
0.30.0
+273
tests/integration/test_integration_cms.py
import pytest
from tests.integration import asserts
from threescale_api import errors
from .asserts import assert_resource, assert_resource_params
# Files
def test_file_list(api, cms_file):
""" List all files. """
assert len(api.cms_files.list()) >= 1
def test_file_can_be_created(cms_file_data, cms_file):
""" Is file created properly? """
assert_resource(cms_file)
assert_resource_params(cms_file, cms_file_data)
def test_file_can_be_read(api, cms_file_data, cms_file):
""" It is possible to get file by ID? """
read = api.cms_files.read(cms_file.entity_id)
asserts.assert_resource(read)
asserts.assert_resource_params(read, cms_file_data)
def test_file_can_be_read_by_name(api, cms_file_data, cms_file):
""" It is possible to get file by name? """
file_path = cms_file['path']
read = api.cms_files[file_path]
asserts.assert_resource(read)
asserts.assert_resource_params(read, cms_file_data)
def test_file_can_be_updated(cms_file_data, cms_file):
""" Can be file object updated? """
updated_path = cms_file['path'] + 'up'
cms_file['path'] = cms_file['path'] + 'up'
# TODO https://issues.redhat.com/browse/THREESCALE-9571
for item in "created_at", "updated_at", "url", "title", "content_type":
cms_file.pop(item)
cms_file.update()
assert cms_file['path'] == updated_path
updated = cms_file.read()
assert updated['path'] == updated_path
assert cms_file['path'] == updated_path
# Sections
def test_section_list(api, cms_section):
""" List all sections. """
assert len(api.cms_sections.list()) >= 1
def test_section_can_be_created(cms_section_params, cms_section):
""" Is section created properly? """
assert_resource(cms_section)
assert_resource_params(cms_section, cms_section_params)
def test_section_can_be_read(api, cms_section_params, cms_section):
""" It is possible to get section by ID? """
read = api.cms_sections.read(cms_section.entity_id)
asserts.assert_resource(read)
asserts.assert_resource_params(read, cms_section_params)
def test_section_can_be_updated(cms_section_params, cms_section):
""" Can be section object updated? """
updated_title = cms_section['title'] + 'up'
cms_section['title'] = cms_section['title'] + 'up'
# TODO https://issues.redhat.com/browse/THREESCALE-9571
for item in "created_at", "updated_at":
cms_section.pop(item)
cms_section.update()
assert cms_section['title'] == updated_title
updated = cms_section.read()
assert updated['title'] == updated_title
assert cms_section['title'] == updated_title
# # bug!!! TODO https://issues.redhat.com/browse/THREESCALE-9572
# def test_builtin_section_delete(api):
# """It is not possible to delete section partial."""
# with pytest.raises(errors.ApiClientError) as exc_info:
# api.cms_sections.list()[0].delete()
# assert exc_info.value.code == 423
# # TODO
# # assert exc_info.value.code == 400
# Partials
# builtin
def test_builtin_partials_list(api):
""" List all sections. """
assert len(api.cms_builtin_partials.list()) >= 1
def test_builtin_partial_can_be_read(api):
""" It is possible to get partial by ID? """
cms_partial = api.cms_builtin_partials.list()[-1]
read = api.cms_builtin_partials.read(cms_partial.entity_id)
asserts.assert_resource(read)
def test_builtin_partial_delete(api):
"""It is not possible to delete builtin partial."""
with pytest.raises(errors.ApiClientError) as exc_info:
api.cms_builtin_partials.list()[0].delete()
assert exc_info.value.code == 423
# TODO https://issues.redhat.com/browse/THREESCALE-9572
# assert exc_info.value.code == 400
# user
def test_partial_list(api, cms_partial):
""" List all user defined partials. """
assert len(api.cms_partials.list()) >= 1
def test_partial_can_be_created(cms_partial_params, cms_partial):
""" Is partial created properly? """
assert_resource(cms_partial)
assert_resource_params(cms_partial, cms_partial_params)
def test_partial_can_be_read(api, cms_partial_params, cms_partial):
""" It is possible to get partial by ID? """
read = api.cms_partials.read(cms_partial.entity_id)
asserts.assert_resource(read)
asserts.assert_resource_params(read, cms_partial_params)
def test_partial_can_be_updated(cms_partial_params, cms_partial):
""" Can be partial object updated? """
updated_draft = cms_partial['draft'] + 'up'
cms_partial['draft'] = cms_partial['draft'] + 'up'
# TODO https://issues.redhat.com/browse/THREESCALE-9571
for item in "created_at", "updated_at", "published":
cms_partial.pop(item)
cms_partial.update()
assert cms_partial['draft'] == updated_draft
updated = cms_partial.read()
assert updated['draft'] == updated_draft
assert cms_partial['draft'] == updated_draft
def test_partial_publish(cms_partial):
""" Test publishing of partials. """
assert cms_partial.entity.get('published', None) is None
draft = cms_partial['draft']
cms_partial = cms_partial.publish()
# assert draft == cms_partial['draft'] bug
# assert cms_partial['published'] == cms_partial['draft'] bug
assert draft == cms_partial['published']
# Pages
# builtin
def test_builtin_pages_list(api):
""" List all sections. """
assert len(api.cms_builtin_pages.list()) >= 1
def test_builtin_page_can_be_read(api):
""" It is possible to get page by ID? """
cms_page = api.cms_builtin_pages.list()[-1]
read = api.cms_builtin_pages.read(cms_page.entity_id)
asserts.assert_resource(read)
def test_builtin_page_delete(api):
"""It is not possible to delete builtin page."""
with pytest.raises(errors.ApiClientError) as exc_info:
api.cms_builtin_pages.list()[0].delete()
assert exc_info.value.code == 423
# TODO https://issues.redhat.com/browse/THREESCALE-9572
# assert exc_info.value.code == 400
# user
def test_page_list(api, cms_page):
""" List all user defined pages. """
assert len(api.cms_pages.list()) >= 1
def test_page_can_be_created(cms_page_params, cms_page):
""" Is page created properly? """
assert_resource(cms_page)
assert_resource_params(cms_page, cms_page_params)
def test_page_can_be_read(api, cms_page_params, cms_page):
""" It is possible to get page by ID? """
read = api.cms_pages.read(cms_page.entity_id)
asserts.assert_resource(read)
asserts.assert_resource_params(read, cms_page_params)
def test_page_can_be_updated(cms_page_params, cms_page):
""" Can be page object updated? """
updated_draft = cms_page['draft'] + 'up'
cms_page['draft'] = cms_page['draft'] + 'up'
# TODO https://issues.redhat.com/browse/THREESCALE-9571
for item in "created_at", "updated_at", "hidden", "published":
cms_page.pop(item)
cms_page.update()
assert cms_page['draft'] == updated_draft
updated = cms_page.read()
assert updated['draft'] == updated_draft
assert cms_page['draft'] == updated_draft
def test_page_publish(cms_page):
""" Test publishing of pages. """
assert cms_page.entity.get('published', None) is None
draft = cms_page['draft']
cms_page = cms_page.publish()
# assert draft == cms_page['draft'] bug
# assert cms_page['published'] == cms_page['draft'] bug
assert draft == cms_page['published']
# Layouts
def test_layout_list(api, cms_layout):
""" List all user defined layouts. """
assert len(api.cms_layouts.list()) >= 1
def test_layout_can_be_created(cms_layout_params, cms_layout):
""" Is layout created properly? """
assert_resource(cms_layout)
assert_resource_params(cms_layout, cms_layout_params)
def test_layout_can_be_read(api, cms_layout_params, cms_layout):
""" It is possible to get layout by ID? """
read = api.cms_layouts.read(cms_layout.entity_id)
asserts.assert_resource(read)
asserts.assert_resource_params(read, cms_layout_params)
def test_layout_can_be_updated(cms_layout_params, cms_layout):
""" Can be layout object updated? """
updated_draft = cms_layout['draft'] + 'up'
cms_layout['draft'] = cms_layout['draft'] + 'up'
# TODO https://issues.redhat.com/browse/THREESCALE-9571
for item in "created_at", "updated_at", "published":
cms_layout.pop(item)
cms_layout.update()
assert cms_layout['draft'] == updated_draft
updated = cms_layout.read()
assert updated['draft'] == updated_draft
assert cms_layout['draft'] == updated_draft
def test_layout_publish(cms_layout):
""" Test publishing of layouts. """
assert cms_layout.entity.get('published', None) is None
draft = cms_layout['draft']
cms_layout = cms_layout.publish()
# assert draft == cms_layout['draft'] bug
# assert cms_layout['published'] == cms_layout['draft'] bug
assert draft == cms_layout['published']
+1
-1
Metadata-Version: 2.1
Name: 3scale-api
Version: 0.29.0
Version: 0.30.0
Summary: 3scale API python client

@@ -5,0 +5,0 @@ Home-page: https://github.com/pestanko/3scale-api-python

@@ -21,2 +21,3 @@ README.md

tests/integration/test_integration_backends.py
tests/integration/test_integration_cms.py
tests/integration/test_integration_custom_tenant.py

@@ -23,0 +24,0 @@ tests/integration/test_integration_default_client.py

Metadata-Version: 2.1
Name: 3scale-api
Version: 0.29.0
Version: 0.30.0
Summary: 3scale API python client

@@ -5,0 +5,0 @@ Home-page: https://github.com/pestanko/3scale-api-python

@@ -500,1 +500,82 @@ import os

cleanup(entity)
@pytest.fixture(scope="module")
def cms_file_data(cms_section):
"""CMS file fixture data"""
return {"path": f"/path{get_suffix()}", "downloadable": True, 'section_id': cms_section['id']}
@pytest.fixture(scope="module")
def cms_file_files(active_docs_body):
"""CMS file fixture files.
File object can be used instead of file body 'active_docs_body',
see https://requests.readthedocs.io/en/latest/user/advanced/#post-multiple-multipart-encoded-files """
return {"attachment": (f"name-{get_suffix()}", active_docs_body, "application/json", {"Expires": 0})}
@pytest.fixture(scope="module")
def cms_file(api, cms_file_data, cms_file_files):
"""CMS file fixture"""
entity = api.cms_files.create(params={}, files=cms_file_files, data=cms_file_data)
yield entity
cleanup(entity)
@pytest.fixture(scope="module")
def cms_section_params():
"""CMS section fixture params"""
return {"title": f"title-{get_suffix()}", "public": True, "partial_path": f"/path-{get_suffix()}"}
@pytest.fixture(scope="module")
def cms_section(api, cms_section_params):
"""CMS section fixture"""
entity = api.cms_sections.create(cms_section_params)
yield entity
cleanup(entity)
@pytest.fixture(scope="module")
def cms_partial_params():
"""CMS partial fixture params"""
return {"system_name": f"sname-{get_suffix()}", "draft": f"draft-{get_suffix()}"}
@pytest.fixture(scope="module")
def cms_partial(api, cms_partial_params):
"""CMS partial fixture"""
entity = api.cms_partials.create(cms_partial_params)
yield entity
cleanup(entity)
@pytest.fixture(scope="module")
def cms_layout_params(cms_section):
"""CMS layout fixture params"""
return {"system_name": f"sname-{get_suffix()}", "draft": f"draft-{get_suffix()}",
"title": f"title-{get_suffix()}", "liquid_enabled": True, "section_id": cms_section['id']}
@pytest.fixture(scope="module")
def cms_layout(api, cms_layout_params):
"""CMS layout fixture"""
entity = api.cms_layouts.create(cms_layout_params)
yield entity
cleanup(entity)
@pytest.fixture(scope="module")
def cms_page_params(cms_section, cms_layout):
"""CMS page fixture params"""
return {"system_name": f"sname-{get_suffix()}", "draft": f"draft-{get_suffix()}",
"title": f"title-{get_suffix()}", "path": f"/path-{get_suffix()}",
"section_name": f"section-{get_suffix()}", "section_id": cms_section['id'],
"layout_name": f"layout-{get_suffix()}", "layout_id": cms_layout['id'],
"liquid_enabled": True, "handler": "markdown", "content_type": "text/html"}
@pytest.fixture(scope="module")
def cms_page(api, cms_page_params):
"""CMS page fixture"""
entity = api.cms_pages.create(cms_page_params)
yield entity
cleanup(entity)
from tests.integration import asserts
def test_accounts_list(api):
services = api.accounts.list()
assert len(services) >= 1
def test_accounts_list(api, account):
accounts = api.accounts.list()
assert len(accounts) >= 1

@@ -25,1 +25,4 @@

asserts.assert_resource_params(read, account_params)
def test_users_list(api, account):
assert len(account.users.list()) >= 1

@@ -19,3 +19,3 @@ import pytest

def test_application_list(account):
def test_application_list(account, application):
applications = account.applications.list()

@@ -22,0 +22,0 @@ assert len(applications) > 0

@@ -7,4 +7,4 @@ import pytest

def test_should_list_mapping_rules(backend, backend_mapping_rule):
resource = backend.mapping_rules.list()
assert resource
resources = backend.mapping_rules.list()
assert len(resources) >= 1

@@ -11,0 +11,0 @@ def test_should_create_mapping_rule(backend_mapping_rule, backend_mapping_rule_params):

@@ -48,5 +48,5 @@ import pytest

def test_should_list_metrics(backend):
def test_should_list_metrics(backend, backend_metric):
resources = backend.metrics.list()
assert len(resources) > 1
assert len(resources) >= 1

@@ -53,0 +53,0 @@ def test_should_apicast_return_403_when_metric_is_disabled(

@@ -12,3 +12,3 @@ from tests.integration import asserts

def test_backends_list(api):
def test_backends_list(api, backend):
backends = api.backends.list()

@@ -15,0 +15,0 @@ assert len(backends) >= 1

@@ -7,2 +7,4 @@ import pytest

def test_list_methods(metric, method):
assert len(metric.methods.list()) >= 1

@@ -9,0 +11,0 @@ def test_should_create_method(method, method_params):

@@ -8,2 +8,4 @@ import pytest

def test_list_metrics(service, metric):
assert len(service.metrics.list()) >= 1

@@ -10,0 +12,0 @@ def test_should_create_metric(metric, metric_params):

@@ -12,3 +12,3 @@ from tests.integration import asserts

def test_services_list(api):
def test_services_list(api, service):
services = api.services.list()

@@ -111,2 +111,5 @@ assert len(services) >= 1

def test_service_backend_usages_list(service, backend_usage):
back_usages = service.backend_usages.list()
assert len(back_usages) >= 1

@@ -113,0 +116,0 @@ def test_service_backend_usages_backend(backend_usage, backend):

@@ -53,2 +53,10 @@ import logging

resources.FieldsDefinitions(self, instance_klass=resources.FieldsDefinition)
self._cms_files = resources.CmsFiles(self, instance_klass=resources.CmsFile)
self._cms_sections = resources.CmsSections(self, instance_klass=resources.CmsSection)
self._cms_pages = resources.CmsPages(self, instance_klass=resources.CmsPage)
self._cms_builtin_pages = resources.CmsBuiltinPages(self, instance_klass=resources.CmsPage)
self._cms_layouts = resources.CmsLayouts(self, instance_klass=resources.CmsLayout)
self._cms_builtin_partials =\
resources.CmsBuiltinPartials(self, instance_klass=resources.CmsPartial)
self._cms_partials = resources.CmsPartials(self, instance_klass=resources.CmsPartial)

@@ -259,3 +267,31 @@ if wait >= 0:

@property
def cms_files(self) -> resources.CmsFiles:
return self._cms_files
@property
def cms_sections(self) -> resources.CmsSections:
return self._cms_sections
@property
def cms_pages(self) -> resources.CmsPages:
return self._cms_pages
@property
def cms_builtin_pages(self) -> resources.CmsBuiltinPages:
return self._cms_builtin_pages
@property
def cms_layouts(self) -> resources.CmsLayouts:
return self._cms_layouts
@property
def cms_partials(self) -> resources.CmsPartials:
return self._cms_partials
@property
def cms_builtin_partials(self) -> resources.CmsBuiltinPartials:
return self._cms_builtin_partials
class RestApiClient:

@@ -262,0 +298,0 @@ def __init__(self, url: str, token: str, throws: bool = True, ssl_verify: bool = True):

@@ -389,2 +389,47 @@ import logging

class DefaultPaginationClient(DefaultClient):
""" Client to handle API endpoints with pagination.
List of endpoints supporting pagination with per_page size:
- accounts 500
limits per app plan 50 - not implemented in client
application list for all services 500 - not implemented in client
- backend mapping rules 500
- backend method list 500
- backend metric 500
- backend 500
- service 500
invoice list by account 20 - not implemented by standard "list" method
- invoice list 20
- all cms 100
"""
def __init__(self, *args, per_page=500, **kwargs):
self.per_page = per_page
super().__init__(*args, **kwargs)
def _list(self, **kwargs):
""" List all objects via paginated API endpoint """
kwargs = kwargs.copy()
kwargs.setdefault("params", {})
if "page" in kwargs["params"] or self.per_page is None:
return super()._list(**kwargs)
pagenum = 1
kwargs["params"]["page"] = pagenum
kwargs["params"]["per_page"] = self.per_page
page = super()._list(**kwargs)
ret_list = page
while len(page):
pagenum += 1
kwargs["params"]["page"] = pagenum
page = super()._list(**kwargs)
ret_list += page
return ret_list
def __iter__(self):
return self._list()
class DefaultPlanClient(DefaultClient):

@@ -433,3 +478,3 @@ def set_default(self, entity_id: int, **kwargs) -> 'DefaultPlanResource':

class DefaultStateClient(DefaultClient):
class DefaultStateClient(DefaultPaginationClient):
def set_state(self, entity_id, state: str, **kwargs):

@@ -436,0 +481,0 @@ """Sets the state for the resource

@@ -9,3 +9,4 @@ import logging

from threescale_api.defaults import DefaultClient, DefaultPlanClient, DefaultPlanResource, \
DefaultResource, DefaultStateClient, DefaultUserResource, DefaultStateResource
DefaultResource, DefaultStateClient, DefaultUserResource, DefaultStateResource, \
DefaultPaginationClient
from threescale_api import client

@@ -16,6 +17,7 @@

class Services(DefaultClient):
def __init__(self, *args, entity_name='service', entity_collection='services', **kwargs):
class Services(DefaultPaginationClient):
def __init__(self, *args, entity_name='service', entity_collection='services',
per_page=500, **kwargs):
super().__init__(*args, entity_name=entity_name,
entity_collection=entity_collection, **kwargs)
entity_collection=entity_collection, per_page=per_page, **kwargs)

@@ -27,7 +29,8 @@ @property

class MappingRules(DefaultClient):
class MappingRules(DefaultPaginationClient):
def __init__(self, *args, entity_name='mapping_rule', entity_collection='mapping_rules',
**kwargs):
per_page=None, **kwargs):
super().__init__(*args, entity_name=entity_name,
entity_collection=entity_collection, **kwargs)
entity_collection=entity_collection, per_page=per_page,
**kwargs)

@@ -39,6 +42,7 @@ @property

class Metrics(DefaultClient):
def __init__(self, *args, entity_name='metric', entity_collection='metrics', **kwargs):
class Metrics(DefaultPaginationClient):
def __init__(self, *args, entity_name='metric', entity_collection='metrics', per_page=None,
**kwargs):
super().__init__(*args, entity_name=entity_name,
entity_collection=entity_collection, **kwargs)
entity_collection=entity_collection, per_page=per_page, **kwargs)

@@ -105,6 +109,7 @@ @property

class Methods(DefaultClient):
def __init__(self, *args, entity_name='method', entity_collection='methods', **kwargs):
class Methods(DefaultPaginationClient):
def __init__(self, *args, entity_name='method', entity_collection='methods', per_page=None,
**kwargs):
super().__init__(*args, entity_name=entity_name,
entity_collection=entity_collection, **kwargs)
entity_collection=entity_collection, per_page=per_page, **kwargs)

@@ -141,5 +146,6 @@ @property

class AccountUsers(DefaultStateClient):
def __init__(self, *args, entity_name='user', entity_collection='users', **kwargs):
def __init__(self, *args, entity_name='user', entity_collection='users', per_page=None,
**kwargs):
super().__init__(*args, entity_name=entity_name,
entity_collection=entity_collection, **kwargs)
entity_collection=entity_collection, per_page=per_page, **kwargs)

@@ -162,5 +168,7 @@ @property

class Accounts(DefaultStateClient):
def __init__(self, *args, entity_name='account', entity_collection='accounts', **kwargs):
def __init__(self, *args, entity_name='account', entity_collection='accounts', per_page=500,
**kwargs):
super().__init__(*args, entity_name=entity_name,
entity_collection=entity_collection, **kwargs)
entity_collection=entity_collection, per_page=per_page,
**kwargs)

@@ -255,5 +263,5 @@ @property

def __init__(self, *args, entity_name='application', entity_collection='applications',
**kwargs):
per_page=None, **kwargs):
super().__init__(*args, entity_name=entity_name,
entity_collection=entity_collection, **kwargs)
entity_collection=entity_collection, per_page=per_page, **kwargs)

@@ -590,7 +598,7 @@ @property

class Backends(DefaultClient):
class Backends(DefaultPaginationClient):
def __init__(self, *args, entity_name='backend_api',
entity_collection='backend_apis', **kwargs):
entity_collection='backend_apis', per_page=500, **kwargs):
super().__init__(*args, entity_name=entity_name,
entity_collection=entity_collection, **kwargs)
entity_collection=entity_collection, per_page=per_page, **kwargs)

@@ -601,35 +609,9 @@ @property

def list(self, **kwargs):
return list(super().list(**kwargs))
def _list(self, **kwargs):
if "page" in kwargs.get("params", {}):
return super()._list(**kwargs)
pagenum = 1
kwargs = kwargs.copy()
if "params" not in kwargs:
kwargs["params"] = {}
kwargs["params"]["page"] = pagenum
kwargs["params"]["per_page"] = 500
page = super()._list(**kwargs)
while len(page):
for i in page:
yield i
pagenum += 1
kwargs["params"]["page"] = pagenum
page = super()._list(**kwargs)
def __iter__(self):
return self._list()
class BackendMetrics(Metrics):
def __init__(self, *args, entity_name='metric', entity_collection='metrics', **kwargs):
def __init__(self, *args, entity_name='metric', entity_collection='metrics', per_page=500,
**kwargs):
super().__init__(*args, entity_name=entity_name,
entity_collection=entity_collection, **kwargs)
entity_collection=entity_collection, per_page=per_page,
**kwargs)

@@ -639,5 +621,6 @@

def __init__(self, *args, entity_name='mapping_rule',
entity_collection='mapping_rules', **kwargs):
entity_collection='mapping_rules', per_page=500, **kwargs):
super().__init__(*args, entity_name=entity_name,
entity_collection=entity_collection, **kwargs)
entity_collection=entity_collection, per_page=per_page,
**kwargs)

@@ -698,5 +681,6 @@

"""
def __init__(self, *args, entity_name='user', entity_collection='users', **kwargs):
def __init__(self, *args, entity_name='user', entity_collection='users', per_page=None,
**kwargs):
super().__init__(*args, entity_name=entity_name,
entity_collection=entity_collection, **kwargs)
entity_collection=entity_collection, per_page=per_page, **kwargs)

@@ -857,7 +841,8 @@ @property

class Invoices(DefaultClient):
class Invoices(DefaultPaginationClient):
"""Default client for Invoices"""
def __init__(self, *args, entity_name='invoice', entity_collection='invoices', **kwargs):
def __init__(self, *args, entity_name='invoice', entity_collection='invoices',
per_page=20, **kwargs):
super().__init__(*args, entity_name=entity_name,
entity_collection=entity_collection, **kwargs)
entity_collection=entity_collection, per_page=per_page, **kwargs)

@@ -929,2 +914,98 @@ @property

class CmsClient(DefaultPaginationClient):
""" Client for all cms api endpoints. """
def __init__(self, *args, per_page=100, **kwargs):
super().__init__(*args, per_page=per_page, **kwargs)
def _extract_resource(self, response, collection) -> Union[List, Dict]:
extracted = response.json()
if self._entity_collection and self._entity_collection in extracted:
extracted = extracted.get(self._entity_collection)
return extracted
class CmsFiles(CmsClient):
""" Client for files. """
def __init__(self, *args, entity_name='file', entity_collection='collection', **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 + '/cms/files'
class CmsSections(CmsClient):
""" Client for sections. """
def __init__(self, *args, entity_name='section', entity_collection='collection', **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 + '/cms/sections'
class CmsTemplates(CmsClient):
""" Client for templates. """
def __init__(self, *args, entity_collection='collection', **kwargs):
super().__init__(*args, entity_collection=entity_collection, **kwargs)
@property
def url(self) -> str:
return self.threescale_client.admin_api_url + '/cms/templates'
def publish(self, entity_id, **kwargs):
""" Publish template with entity_id """
log.info("[PUBLISH] %s", entity_id)
url = self._entity_url(entity_id) + '/publish'
response = self.rest.put(url=url, **kwargs)
instance = self._create_instance(response=response)
return instance
def list(self, **kwargs) -> List['DefaultResource']:
"""List all entities
Args:
**kwargs: Optional parameters
Returns(List['DefaultResource]): List of resources
"""
log.info(self._log_message("[LIST] List", args=kwargs))
instance = self.select_by(type=self._entity_name, **kwargs)
return instance
def create(self, params: dict = None,
*args, **kwargs) -> 'DefaultResource':
params.update({'type': self._entity_name})
return super().create(params=params, **kwargs)
class CmsPages(CmsTemplates):
""" Client for pages """
def __init__(self, *args, entity_name='page', **kwargs):
super().__init__(*args, entity_name=entity_name, **kwargs)
class CmsBuiltinPages(CmsTemplates):
""" Client for builtin pages. """
def __init__(self, *args, entity_name='builtin_page', **kwargs):
super().__init__(*args, entity_name=entity_name, **kwargs)
class CmsLayouts(CmsTemplates):
""" Client for layouts """
def __init__(self, *args, entity_name='layout', **kwargs):
super().__init__(*args, entity_name=entity_name, **kwargs)
class CmsPartials(CmsTemplates):
""" Client for partials """
def __init__(self, *args, entity_name='partial', **kwargs):
super().__init__(*args, entity_name=entity_name, **kwargs)
class CmsBuiltinPartials(CmsTemplates):
""" Client for builtin partials """
def __init__(self, *args, entity_name='builtin_partial', **kwargs):
super().__init__(*args, entity_name=entity_name, **kwargs)
# Resources

@@ -975,3 +1056,3 @@

def methods(self) -> 'Methods':
return Methods(parent=self, instance_klass=Method)
return Methods(parent=self, instance_klass=Method, per_page=self.client.per_page)

@@ -1172,3 +1253,15 @@

def plan_upgrade(self, plan_id):
"""Upgrade plan to given plan_id"""
return self.client.rest.put(f"{self.url}/plan_upgrade", params={"plan_id": plan_id})
@property
def account(self):
"""Return account of this tenant"""
return Account(
client=self.threescale_client.accounts,
entity=self.entity["signup"]["account"]
)
class Application(DefaultResource):

@@ -1481,1 +1574,41 @@ def __init__(self, entity_name='name', **kwargs):

super().__init__(entity_name=entity_name, **kwargs)
class CmsFile(DefaultResource):
""" Resource for file """
def __init__(self, entity_name='path', **kwargs):
super().__init__(entity_name=entity_name, **kwargs)
class CmsSection(DefaultResource):
""" Resource for section. """
def __init__(self, entity_name='id', **kwargs):
super().__init__(entity_name=entity_name, **kwargs)
class CmsTemplate(DefaultResource):
""" Resource for templates """
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def publish(self, **kwargs):
""" Publish template resource """
return self.client.publish(entity_id=self.entity_id, **kwargs)
class CmsPage(CmsTemplate):
""" Resource for page """
def __init__(self, entity_name='system_name', **kwargs):
super().__init__(entity_name=entity_name, **kwargs)
class CmsLayout(CmsTemplate):
""" Resource for layout """
def __init__(self, entity_name='system_name', **kwargs):
super().__init__(entity_name=entity_name, **kwargs)
class CmsPartial(CmsTemplate):
""" Resource for partials """
def __init__(self, entity_name='system_name', **kwargs):
super().__init__(entity_name=entity_name, **kwargs)