diff --git a/tests/integration/test_integration_cms.py b/tests/integration/test_integration_cms.py index 53b6494..4b10bb8 100644 --- a/tests/integration/test_integration_cms.py +++ b/tests/integration/test_integration_cms.py @@ -5,7 +5,7 @@ # Files def test_file_list(api, cms_file): """ List all files. """ - assert len(list(api.cms_files.list())) >= 1 + assert len(api.cms_files.list()) >= 1 def test_file_can_be_created(cms_file_data, cms_file): @@ -59,7 +59,7 @@ def test_builtin_section_can_be_read(api): def test_section_list(api, cms_section): """ List all sections. """ - assert len(list(api.cms_sections.list())) >= 1 + assert len(api.cms_sections.list()) >= 1 def test_section_can_be_created(cms_section_params, cms_section): @@ -91,7 +91,7 @@ def test_section_can_be_updated(cms_section_params, cms_section): def test_builtin_partials_list(api): """ List all sections. """ - assert len(list(api.cms_builtin_partials.list())) >= 1 + assert len(api.cms_builtin_partials.list()) >= 1 def test_builtin_partial_can_be_read(api): @@ -105,7 +105,7 @@ def test_builtin_partial_can_be_read(api): def test_partial_list(api, cms_partial): """ List all user defined partials. """ - assert len(list(api.cms_partials.list())) >= 1 + assert len(api.cms_partials.list()) >= 1 def test_partial_can_be_created(cms_partial_params, cms_partial): @@ -131,7 +131,16 @@ def test_partial_can_be_updated(cms_partial_params, cms_partial): assert updated['draft'] == updated_draft assert cms_partial['draft'] == updated_draft -# TODO template publishing + +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 @@ -139,7 +148,7 @@ def test_partial_can_be_updated(cms_partial_params, cms_partial): def test_builtin_pages_list(api): """ List all sections. """ - assert len(list(api.cms_builtin_pages.list())) >= 1 + assert len(api.cms_builtin_pages.list()) >= 1 def test_builtin_page_can_be_read(api): @@ -154,7 +163,7 @@ def test_builtin_page_can_be_read(api): def test_page_list(api, cms_page): """ List all user defined pages. """ - assert len(list(api.cms_pages.list())) >= 1 + assert len(api.cms_pages.list()) >= 1 def test_page_can_be_created(cms_page_params, cms_page): @@ -181,12 +190,22 @@ def test_page_can_be_updated(cms_page_params, cms_page): 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(list(api.cms_layouts.list())) >= 1 + assert len(api.cms_layouts.list()) >= 1 def test_layout_can_be_created(cms_layout_params, cms_layout): @@ -211,3 +230,13 @@ def test_layout_can_be_updated(cms_layout_params, cms_layout): 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'] diff --git a/threescale_api/client.py b/threescale_api/client.py index dfc3f3f..6ccc5ea 100644 --- a/threescale_api/client.py +++ b/threescale_api/client.py @@ -52,11 +52,13 @@ def __init__(self, url: str, token: str, 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_builtin_sections = resources.CmsBuiltinSections(self, instance_klass=resources.CmsSection) + self._cms_builtin_sections =\ + resources.CmsBuiltinSections(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_builtin_partials =\ + resources.CmsBuiltinPartials(self, instance_klass=resources.CmsPartial) self._cms_partials = resources.CmsPartials(self, instance_klass=resources.CmsPartial) if wait >= 0: @@ -282,11 +284,11 @@ def cms_pages(self) -> resources.CmsPages: @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 diff --git a/threescale_api/resources.py b/threescale_api/resources.py index d978443..1571fbe 100644 --- a/threescale_api/resources.py +++ b/threescale_api/resources.py @@ -915,6 +915,7 @@ def url(self) -> str: class CmsClient(DefaultClient): + """ Client for all cms api endpoints. """ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -946,6 +947,7 @@ def __iter__(self): class CmsFiles(CmsClient): + """ Client for files. """ def __init__(self, *args, entity_name='file', entity_collection='files', **kwargs): super().__init__(*args, entity_name=entity_name, entity_collection=entity_collection, **kwargs) @@ -956,6 +958,7 @@ def url(self) -> str: class CmsSections(CmsClient): + """ Client for sections. """ def __init__(self, *args, entity_name='section', entity_collection='sections', **kwargs): super().__init__(*args, entity_name=entity_name, entity_collection=entity_collection, **kwargs) @@ -964,13 +967,17 @@ def __init__(self, *args, entity_name='section', entity_collection='sections', * def url(self) -> str: return self.threescale_client.admin_api_url + '/cms/sections' + class CmsBuiltinSections(CmsSections): - def __init__(self, *args, entity_name='builtin_section', entity_collection='sections', **kwargs): + """ Client for builtin sections. """ + def __init__(self, *args, entity_name='builtin_section', entity_collection='sections', + **kwargs): super().__init__(*args, entity_name=entity_name, entity_collection=entity_collection, **kwargs) class CmsTemplates(CmsClient): + """ Client for templates. """ def __init__(self, *args, entity_collection='templates', **kwargs): super().__init__(*args, entity_collection=entity_collection, **kwargs) @@ -978,28 +985,41 @@ def __init__(self, *args, entity_collection='templates', **kwargs): 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] " + f"{entity_id}") + url = self._entity_url(entity_id) + '/publish' + response = self.rest.put(url=url, **kwargs) + instance = self._create_instance(response=response) + return instance + 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 @@ -1554,25 +1574,40 @@ def __init__(self, entity_name='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 CmsPage(DefaultResource): +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(DefaultResource): +class CmsLayout(CmsTemplate): + """ Resource for layout """ def __init__(self, entity_name='system_name', **kwargs): super().__init__(entity_name=entity_name, **kwargs) -class CmsPartial(DefaultResource): +class CmsPartial(CmsTemplate): + """ Resource for partials """ def __init__(self, entity_name='system_name', **kwargs): super().__init__(entity_name=entity_name, **kwargs)