diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index a9d4f84..77a4a33 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -502,7 +502,7 @@ def fields_definition(api, fields_definitions_params): @pytest.fixture(scope="module") def cms_file_data(): """CMS file fixture data""" - return dict(path=f"/path{get_suffix()}", downloadable=True) + return {"path": f"/path{get_suffix()}", "downloadable": True} @pytest.fixture(scope="module") @@ -510,7 +510,7 @@ 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'})} + return {"attachment": (f"name-{get_suffix()}", active_docs_body, "application/json", {"Expires": 0})} @pytest.fixture(scope="module") @@ -524,8 +524,8 @@ def cms_file(api, cms_file_data, cms_file_files): @pytest.fixture(scope="module") def cms_section_params(cms_file): """CMS section fixture params""" - return dict(title=f"title-{get_suffix()}", public=True, partial_path=f"/path-{get_suffix()}", - cms_file_ids=[cms_file['id']]) + return {"title": f"title-{get_suffix()}", "public": True, "partial_path": f"/path-{get_suffix()}", + "cms_file_ids": [cms_file['id']]} @pytest.fixture(scope="module") @@ -539,7 +539,7 @@ def cms_section(api, cms_section_params): @pytest.fixture(scope="module") def cms_partial_params(): """CMS partial fixture params""" - return dict(type='partial', system_name=f"sname-{get_suffix()}", draft=f"draft-{get_suffix()}") + return {"type": "partial", "system_name": f"sname-{get_suffix()}", "draft": f"draft-{get_suffix()}"} @pytest.fixture(scope="module") @@ -548,3 +548,35 @@ def cms_partial(api, cms_partial_params): 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 {"type": "layout", "system_name": f"sname-{get_suffix()}", "draft": f"draft-{get_suffix()}", + "title": f"title-{get_suffix()}", "liquid_enabled": True} + +@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 {"type": "page", "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", "tag_list": [1,2,3,4,5], + "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) diff --git a/tests/integration/test_integration_cms.py b/tests/integration/test_integration_cms.py index 1adb712..53b6494 100644 --- a/tests/integration/test_integration_cms.py +++ b/tests/integration/test_integration_cms.py @@ -31,7 +31,8 @@ def test_file_can_be_read_by_name(api, cms_file_data, cms_file): def test_file_can_be_updated(cms_file_data, cms_file): """ Can be file object updated? """ - updated_path = cms_file['path'] = cms_file['path'] + 'up' + updated_path = cms_file['path'] + 'up' + cms_file['path'] = cms_file['path'] + 'up' cms_file.update() assert cms_file['path'] == updated_path updated = cms_file.read() @@ -44,12 +45,12 @@ def test_file_can_be_updated(cms_file_data, cms_file): def test_builtin_section_list(api): """ List all sections. """ - assert len(list(api.cms_builtin_sections.list())) >= 1 + assert len(api.cms_builtin_sections.list()) >= 1 def test_builtin_section_can_be_read(api): """ It is possible to get section by ID? """ - cms_section = next(api.cms_builtin_sections.list()) + cms_section = api.cms_builtin_sections.list()[-1] read = api.cms_sections.read(cms_section.entity_id) asserts.assert_resource(read) @@ -76,7 +77,8 @@ def test_section_can_be_read(api, cms_section_params, cms_section): def test_section_can_be_updated(cms_section_params, cms_section): """ Can be section object updated? """ - updated_title = cms_section['title'] = cms_section['title'] + 'up' + updated_title = cms_section['title'] + 'up' + cms_section['title'] = cms_section['title'] + 'up' cms_section.update() assert cms_section['title'] == updated_title updated = cms_section.read() @@ -94,7 +96,7 @@ def test_builtin_partials_list(api): def test_builtin_partial_can_be_read(api): """ It is possible to get partial by ID? """ - cms_partial = next(api.cms_builtin_partials.list()) + cms_partial = api.cms_builtin_partials.list()[-1] read = api.cms_builtin_partials.read(cms_partial.entity_id) asserts.assert_resource(read) @@ -121,11 +123,91 @@ def test_partial_can_be_read(api, cms_partial_params, cms_partial): def test_partial_can_be_updated(cms_partial_params, cms_partial): """ Can be partial object updated? """ - updated_draft = cms_partial['draft'] = cms_partial['draft'] + 'up' + updated_draft = cms_partial['draft'] + 'up' + cms_partial['draft'] = cms_partial['draft'] + 'up' cms_partial.update() assert cms_partial['draft'] == updated_draft updated = cms_partial.read() assert updated['draft'] == updated_draft assert cms_partial['draft'] == updated_draft -# # TODO pages, builtin_pages, layouts, template publishing +# TODO template publishing + +# Pages +# builtin + + +def test_builtin_pages_list(api): + """ List all sections. """ + assert len(list(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) + + +# user + + +def test_page_list(api, cms_page): + """ List all user defined pages. """ + assert len(list(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' + cms_page.update() + assert cms_page['draft'] == updated_draft + updated = cms_page.read() + assert updated['draft'] == updated_draft + assert cms_page['draft'] == updated_draft + + +# Layouts + + +def test_layout_list(api, cms_layout): + """ List all user defined layouts. """ + assert len(list(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' + cms_layout.update() + assert cms_layout['draft'] == updated_draft + updated = cms_layout.read() + assert updated['draft'] == updated_draft + assert cms_layout['draft'] == updated_draft diff --git a/threescale_api/resources.py b/threescale_api/resources.py index 1085a3a..d978443 100644 --- a/threescale_api/resources.py +++ b/threescale_api/resources.py @@ -921,7 +921,6 @@ def __init__(self, *args, **kwargs): def _list(self, **kwargs): if "page" in kwargs.get("params", {}): return super()._list(**kwargs) - pagenum = 1 kwargs = kwargs.copy() @@ -932,13 +931,15 @@ def _list(self, **kwargs): kwargs["params"]["per_page"] = 100 page = super()._list(**kwargs) + ret_list = page while len(page): - for i in page: - yield i pagenum += 1 kwargs["params"]["page"] = pagenum page = super()._list(**kwargs) + ret_list += page + + return ret_list def __iter__(self): return self._list()