Skip to content

Commit

Permalink
add pages; change client pager and some lints
Browse files Browse the repository at this point in the history
  • Loading branch information
mkudlej committed Apr 4, 2023
1 parent 99d4ee1 commit bc22044
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 15 deletions.
42 changes: 37 additions & 5 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,15 +502,15 @@ 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")
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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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)
96 changes: 89 additions & 7 deletions tests/integration/test_integration_cms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)

Expand All @@ -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()
Expand All @@ -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)

Expand All @@ -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
7 changes: 4 additions & 3 deletions threescale_api/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit bc22044

Please sign in to comment.