3scale-api
Advanced tools
| Metadata-Version: 2.1 | ||
| Name: 3scale-api | ||
| Version: 0.30.0 | ||
| Version: 0.31.0 | ||
| Summary: 3scale API python client | ||
@@ -5,0 +5,0 @@ Home-page: https://github.com/pestanko/3scale-api-python |
+1
-1
| Metadata-Version: 2.1 | ||
| Name: 3scale-api | ||
| Version: 0.30.0 | ||
| Version: 0.31.0 | ||
| Summary: 3scale API python client | ||
@@ -5,0 +5,0 @@ Home-page: https://github.com/pestanko/3scale-api-python |
@@ -525,5 +525,7 @@ import os | ||
| @pytest.fixture(scope="module") | ||
| def cms_section_params(): | ||
| def cms_section_params(api): | ||
| """CMS section fixture params""" | ||
| return {"title": f"title-{get_suffix()}", "public": True, "partial_path": f"/path-{get_suffix()}"} | ||
| parent_id = api.cms_sections.list()[0]['id'] | ||
| return {"title": f"title-{get_suffix()}", "public": True, | ||
| "partial_path": f"/path-{get_suffix()}", "parent_id": parent_id} | ||
@@ -554,6 +556,6 @@ | ||
| @pytest.fixture(scope="module") | ||
| def cms_layout_params(cms_section): | ||
| def cms_layout_params(): | ||
| """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']} | ||
| "title": f"title-{get_suffix()}", "liquid_enabled": True} | ||
@@ -560,0 +562,0 @@ @pytest.fixture(scope="module") |
@@ -0,1 +1,3 @@ | ||
| """ Test CMS API """ | ||
| import pytest | ||
@@ -38,3 +40,3 @@ from tests.integration import asserts | ||
| cms_file['path'] = cms_file['path'] + 'up' | ||
| # TODO https://issues.redhat.com/browse/THREESCALE-9571 | ||
| # https://issues.redhat.com/browse/THREESCALE-9571 | ||
| for item in "created_at", "updated_at", "url", "title", "content_type": | ||
@@ -74,3 +76,3 @@ cms_file.pop(item) | ||
| cms_section['title'] = cms_section['title'] + 'up' | ||
| # TODO https://issues.redhat.com/browse/THREESCALE-9571 | ||
| # https://issues.redhat.com/browse/THREESCALE-9571 | ||
| for item in "created_at", "updated_at": | ||
@@ -85,10 +87,7 @@ cms_section.pop(item) | ||
| # # 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 | ||
| 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 == 422 | ||
@@ -115,5 +114,3 @@ | ||
| 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 | ||
| assert exc_info.value.code == 422 | ||
@@ -125,3 +122,6 @@ # user | ||
| """ List all user defined partials. """ | ||
| assert len(api.cms_partials.list()) >= 1 | ||
| parts_list = api.cms_partials.list() | ||
| assert len(parts_list) >= 1 | ||
| assert all('draft' in part.entity.keys() and 'published' in part.entity.keys() | ||
| for part in parts_list) | ||
@@ -146,3 +146,3 @@ | ||
| cms_partial['draft'] = cms_partial['draft'] + 'up' | ||
| # TODO https://issues.redhat.com/browse/THREESCALE-9571 | ||
| # https://issues.redhat.com/browse/THREESCALE-9571 | ||
| for item in "created_at", "updated_at", "published": | ||
@@ -162,4 +162,3 @@ cms_partial.pop(item) | ||
| cms_partial = cms_partial.publish() | ||
| # assert draft == cms_partial['draft'] bug | ||
| # assert cms_partial['published'] == cms_partial['draft'] bug | ||
| assert cms_partial['draft'] == None | ||
| assert draft == cms_partial['published'] | ||
@@ -188,5 +187,3 @@ | ||
| 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 | ||
| assert exc_info.value.code == 422 | ||
@@ -219,3 +216,3 @@ | ||
| cms_page['draft'] = cms_page['draft'] + 'up' | ||
| # TODO https://issues.redhat.com/browse/THREESCALE-9571 | ||
| # https://issues.redhat.com/browse/THREESCALE-9571 | ||
| for item in "created_at", "updated_at", "hidden", "published": | ||
@@ -235,4 +232,2 @@ cms_page.pop(item) | ||
| cms_page = cms_page.publish() | ||
| # assert draft == cms_page['draft'] bug | ||
| # assert cms_page['published'] == cms_page['draft'] bug | ||
| assert draft == cms_page['published'] | ||
@@ -266,3 +261,3 @@ | ||
| cms_layout['draft'] = cms_layout['draft'] + 'up' | ||
| # TODO https://issues.redhat.com/browse/THREESCALE-9571 | ||
| # https://issues.redhat.com/browse/THREESCALE-9571 | ||
| for item in "created_at", "updated_at", "published": | ||
@@ -282,4 +277,30 @@ cms_layout.pop(item) | ||
| cms_layout = cms_layout.publish() | ||
| # assert draft == cms_layout['draft'] bug | ||
| # assert cms_layout['published'] == cms_layout['draft'] bug | ||
| assert draft == cms_layout['published'] | ||
| # filters | ||
| def test_section_filter(api, cms_section): | ||
| """ Test section filtering """ | ||
| assert all(sec['parent_id'] == cms_section['parent_id'] | ||
| for sec in api.cms_sections.select_by(parent_id=cms_section['parent_id'])) | ||
| assert api.cms_sections.select_by(title=cms_section['title'])[0] == cms_section | ||
| def test_files_filter(api, cms_file, cms_section): | ||
| """ Test files filtering """ | ||
| assert api.cms_files.select_by(section_id=cms_section['id'])[0] == cms_file | ||
| assert api.cms_files.select_by(path=cms_file['path'])[0] == cms_file | ||
| # https://issues.redhat.com/browse/THREESCALE-9191?focusedId=22406548&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-22406548 | ||
| #def test_partial_filter(api, cms_partial, cms_section): | ||
| # """ Test partial filtering """ | ||
| # assert api.cms_partials.select_by(section_id=cms_section['id'])[0] == cms_partial | ||
| # assert api.cms_partials.select_by(system_name=cms_partial['system_name'])[0] == cms_partial | ||
| #def test_layout_filter(api, cms_layout, cms_section): | ||
| # """ Test layout filtering """ | ||
| # assert api.cms_layouts.select_by(section_id=cms_section['id'])[0] == cms_layout | ||
| # assert api.cms_layouts.select_by(title=cms_layout['title'])[0] == cms_layout | ||
| def test_page_filter(api, cms_section, cms_page): | ||
| """ Test page filtering """ | ||
| assert api.cms_pages.select_by(section_id=cms_section['id'])[0] == cms_page | ||
| assert api.cms_pages.select_by(title=cms_page['title'])[0] == cms_page |
@@ -913,4 +913,35 @@ import logging | ||
| def select_by(self, **params): | ||
| """Select by params - logical "and" Usage example: select_by(role='admin') | ||
| Filtering by some params can be done on the backend. | ||
| Filters for each class are stored in class variable FILTERS. | ||
| Filters are removed because they are not part of function "predicate". | ||
| ------------------------------------- | ||
| | Endpoint | Filters | | ||
| ------------------------------------- | ||
| | Sections #index | parent_id | | ||
| | Files #index | section_id | | ||
| | Templates #index | type, section_id | | ||
| ------------------------------------- | ||
| Args: | ||
| **params: params used for selection | ||
| Returns: List of resources | ||
| """ | ||
| log.debug("[SELECT] By params: %s", params) | ||
| filters = {fil: params.pop(fil) for fil in self.FILTERS if fil in params} | ||
| def predicate(item): | ||
| for (key, val) in params.items(): | ||
| if item[key] != val: | ||
| return False | ||
| return True | ||
| if filters: | ||
| return self.select(predicate=predicate, params=filters) | ||
| return self.select(predicate=predicate) | ||
| class CmsFiles(CmsClient): | ||
| FILTERS = ['parent_id'] | ||
| """ Client for files. """ | ||
@@ -927,2 +958,4 @@ def __init__(self, *args, entity_name='file', entity_collection='collection', **kwargs): | ||
| class CmsSections(CmsClient): | ||
| FILTERS = ['section_id'] | ||
| """ Client for sections. """ | ||
@@ -939,2 +972,4 @@ def __init__(self, *args, entity_name='section', entity_collection='collection', **kwargs): | ||
| class CmsTemplates(CmsClient): | ||
| FILTERS = ['type'] # , 'section_id'] | ||
| """ Client for templates. """ | ||
@@ -963,9 +998,24 @@ def __init__(self, *args, entity_collection='collection', **kwargs): | ||
| log.info(self._log_message("[LIST] List", args=kwargs)) | ||
| instance = self.select_by(type=self._entity_name, **kwargs) | ||
| kwargs.setdefault("params", {}) | ||
| kwargs["params"].setdefault("content", "true") | ||
| kwargs["params"].setdefault("type", self._entity_name) | ||
| instance = self._list(**kwargs) | ||
| return instance | ||
| def select(self, predicate, **kwargs) -> List['DefaultResource']: | ||
| """Select resource s based on the predicate | ||
| Args: | ||
| predicate: Predicate | ||
| **kwargs: Optional args | ||
| Returns: List of resources | ||
| """ | ||
| kwargs.setdefault("params", {}) | ||
| kwargs["params"].setdefault("content", "true") | ||
| kwargs["params"].setdefault("type", self._entity_name) | ||
| return [item for item in self._list(**kwargs) if predicate(item)] | ||
| def create(self, params: dict = None, | ||
| *args, **kwargs) -> 'DefaultResource': | ||
| params.update({'type': self._entity_name}) | ||
| return super().create(params=params, **kwargs) | ||
| return super().create(params=params, *args, **kwargs) | ||
@@ -972,0 +1022,0 @@ |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
190497
1.6%3937
1.55%