Skip to content

Commit 64504be

Browse files
author
Martin Kudlej
committed
add pages
change client pager and some lints
1 parent 5259051 commit 64504be

File tree

3 files changed

+130
-15
lines changed

3 files changed

+130
-15
lines changed

tests/integration/conftest.py

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -502,15 +502,15 @@ def fields_definition(api, fields_definitions_params):
502502
@pytest.fixture(scope="module")
503503
def cms_file_data():
504504
"""CMS file fixture data"""
505-
return dict(path=f"/path{get_suffix()}", downloadable=True)
505+
return {"path": f"/path{get_suffix()}", "downloadable": True}
506506

507507

508508
@pytest.fixture(scope="module")
509509
def cms_file_files(active_docs_body):
510510
"""CMS file fixture files.
511511
File object can be used instead of file body 'active_docs_body',
512512
see https://requests.readthedocs.io/en/latest/user/advanced/#post-multiple-multipart-encoded-files """
513-
return {'attachment': (f"name-{get_suffix()}", active_docs_body, 'application/json', {'Expires': '0'})}
513+
return {"attachment": (f"name-{get_suffix()}", active_docs_body, "application/json", {"Expires": 0})}
514514

515515

516516
@pytest.fixture(scope="module")
@@ -524,8 +524,8 @@ def cms_file(api, cms_file_data, cms_file_files):
524524
@pytest.fixture(scope="module")
525525
def cms_section_params(cms_file):
526526
"""CMS section fixture params"""
527-
return dict(title=f"title-{get_suffix()}", public=True, partial_path=f"/path-{get_suffix()}",
528-
cms_file_ids=[cms_file['id']])
527+
return {"title": f"title-{get_suffix()}", "public": True, "partial_path": f"/path-{get_suffix()}",
528+
"cms_file_ids": [cms_file['id']]}
529529

530530

531531
@pytest.fixture(scope="module")
@@ -539,7 +539,7 @@ def cms_section(api, cms_section_params):
539539
@pytest.fixture(scope="module")
540540
def cms_partial_params():
541541
"""CMS partial fixture params"""
542-
return dict(type='partial', system_name=f"sname-{get_suffix()}", draft=f"draft-{get_suffix()}")
542+
return {"type": "partial", "system_name": f"sname-{get_suffix()}", "draft": f"draft-{get_suffix()}"}
543543

544544

545545
@pytest.fixture(scope="module")
@@ -548,3 +548,35 @@ def cms_partial(api, cms_partial_params):
548548
entity = api.cms_partials.create(cms_partial_params)
549549
yield entity
550550
cleanup(entity)
551+
552+
553+
@pytest.fixture(scope="module")
554+
def cms_layout_params(cms_section):
555+
"""CMS layout fixture params"""
556+
return {"type": "layout", "system_name": f"sname-{get_suffix()}", "draft": f"draft-{get_suffix()}",
557+
"title": f"title-{get_suffix()}", "liquid_enabled": True}
558+
559+
@pytest.fixture(scope="module")
560+
def cms_layout(api, cms_layout_params):
561+
"""CMS layout fixture"""
562+
entity = api.cms_layouts.create(cms_layout_params)
563+
yield entity
564+
cleanup(entity)
565+
566+
@pytest.fixture(scope="module")
567+
def cms_page_params(cms_section, cms_layout):
568+
"""CMS page fixture params"""
569+
return {"type": "page", "system_name": f"sname-{get_suffix()}", "draft": f"draft-{get_suffix()}",
570+
"title": f"title-{get_suffix()}", "path": f"/path-{get_suffix()}",
571+
"section_name": f"section-{get_suffix()}", "section_id": cms_section['id'],
572+
"layout_name": f"layout-{get_suffix()}", "layout_id": cms_layout['id'],
573+
"liquid_enabled": True, "handler": "markdown", "tag_list": [1,2,3,4,5],
574+
"content_type": "text/html"}
575+
576+
577+
@pytest.fixture(scope="module")
578+
def cms_page(api, cms_page_params):
579+
"""CMS page fixture"""
580+
entity = api.cms_pages.create(cms_page_params)
581+
yield entity
582+
cleanup(entity)

tests/integration/test_integration_cms.py

Lines changed: 89 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ def test_file_can_be_read_by_name(api, cms_file_data, cms_file):
3131

3232
def test_file_can_be_updated(cms_file_data, cms_file):
3333
""" Can be file object updated? """
34-
updated_path = cms_file['path'] = cms_file['path'] + 'up'
34+
updated_path = cms_file['path'] + 'up'
35+
cms_file['path'] = cms_file['path'] + 'up'
3536
cms_file.update()
3637
assert cms_file['path'] == updated_path
3738
updated = cms_file.read()
@@ -44,12 +45,12 @@ def test_file_can_be_updated(cms_file_data, cms_file):
4445

4546
def test_builtin_section_list(api):
4647
""" List all sections. """
47-
assert len(list(api.cms_builtin_sections.list())) >= 1
48+
assert len(api.cms_builtin_sections.list()) >= 1
4849

4950

5051
def test_builtin_section_can_be_read(api):
5152
""" It is possible to get section by ID? """
52-
cms_section = next(api.cms_builtin_sections.list())
53+
cms_section = api.cms_builtin_sections.list()[-1]
5354
read = api.cms_sections.read(cms_section.entity_id)
5455
asserts.assert_resource(read)
5556

@@ -76,7 +77,8 @@ def test_section_can_be_read(api, cms_section_params, cms_section):
7677

7778
def test_section_can_be_updated(cms_section_params, cms_section):
7879
""" Can be section object updated? """
79-
updated_title = cms_section['title'] = cms_section['title'] + 'up'
80+
updated_title = cms_section['title'] + 'up'
81+
cms_section['title'] = cms_section['title'] + 'up'
8082
cms_section.update()
8183
assert cms_section['title'] == updated_title
8284
updated = cms_section.read()
@@ -94,7 +96,7 @@ def test_builtin_partials_list(api):
9496

9597
def test_builtin_partial_can_be_read(api):
9698
""" It is possible to get partial by ID? """
97-
cms_partial = next(api.cms_builtin_partials.list())
99+
cms_partial = api.cms_builtin_partials.list()[-1]
98100
read = api.cms_builtin_partials.read(cms_partial.entity_id)
99101
asserts.assert_resource(read)
100102

@@ -121,11 +123,91 @@ def test_partial_can_be_read(api, cms_partial_params, cms_partial):
121123

122124
def test_partial_can_be_updated(cms_partial_params, cms_partial):
123125
""" Can be partial object updated? """
124-
updated_draft = cms_partial['draft'] = cms_partial['draft'] + 'up'
126+
updated_draft = cms_partial['draft'] + 'up'
127+
cms_partial['draft'] = cms_partial['draft'] + 'up'
125128
cms_partial.update()
126129
assert cms_partial['draft'] == updated_draft
127130
updated = cms_partial.read()
128131
assert updated['draft'] == updated_draft
129132
assert cms_partial['draft'] == updated_draft
130133

131-
# # TODO pages, builtin_pages, layouts, template publishing
134+
# TODO template publishing
135+
136+
# Pages
137+
# builtin
138+
139+
140+
def test_builtin_pages_list(api):
141+
""" List all sections. """
142+
assert len(list(api.cms_builtin_pages.list())) >= 1
143+
144+
145+
def test_builtin_page_can_be_read(api):
146+
""" It is possible to get page by ID? """
147+
cms_page = api.cms_builtin_pages.list()[-1]
148+
read = api.cms_builtin_pages.read(cms_page.entity_id)
149+
asserts.assert_resource(read)
150+
151+
152+
# user
153+
154+
155+
def test_page_list(api, cms_page):
156+
""" List all user defined pages. """
157+
assert len(list(api.cms_pages.list())) >= 1
158+
159+
160+
def test_page_can_be_created(cms_page_params, cms_page):
161+
""" Is page created properly? """
162+
assert_resource(cms_page)
163+
assert_resource_params(cms_page, cms_page_params)
164+
165+
166+
def test_page_can_be_read(api, cms_page_params, cms_page):
167+
""" It is possible to get page by ID? """
168+
read = api.cms_pages.read(cms_page.entity_id)
169+
asserts.assert_resource(read)
170+
asserts.assert_resource_params(read, cms_page_params)
171+
172+
173+
def test_page_can_be_updated(cms_page_params, cms_page):
174+
""" Can be page object updated? """
175+
updated_draft = cms_page['draft'] + 'up'
176+
cms_page['draft'] = cms_page['draft'] + 'up'
177+
cms_page.update()
178+
assert cms_page['draft'] == updated_draft
179+
updated = cms_page.read()
180+
assert updated['draft'] == updated_draft
181+
assert cms_page['draft'] == updated_draft
182+
183+
184+
# Layouts
185+
186+
187+
def test_layout_list(api, cms_layout):
188+
""" List all user defined layouts. """
189+
assert len(list(api.cms_layouts.list())) >= 1
190+
191+
192+
def test_layout_can_be_created(cms_layout_params, cms_layout):
193+
""" Is layout created properly? """
194+
assert_resource(cms_layout)
195+
assert_resource_params(cms_layout, cms_layout_params)
196+
197+
198+
def test_layout_can_be_read(api, cms_layout_params, cms_layout):
199+
""" It is possible to get layout by ID? """
200+
read = api.cms_layouts.read(cms_layout.entity_id)
201+
asserts.assert_resource(read)
202+
asserts.assert_resource_params(read, cms_layout_params)
203+
204+
205+
def test_layout_can_be_updated(cms_layout_params, cms_layout):
206+
""" Can be layout object updated? """
207+
updated_draft = cms_layout['draft'] + 'up'
208+
cms_layout['draft'] = cms_layout['draft'] + 'up'
209+
cms_layout.update()
210+
assert cms_layout['draft'] == updated_draft
211+
updated = cms_layout.read()
212+
assert updated['draft'] == updated_draft
213+
assert cms_layout['draft'] == updated_draft

threescale_api/resources.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,6 @@ def __init__(self, *args, **kwargs):
921921
def _list(self, **kwargs):
922922
if "page" in kwargs.get("params", {}):
923923
return super()._list(**kwargs)
924-
925924
pagenum = 1
926925

927926
kwargs = kwargs.copy()
@@ -932,13 +931,15 @@ def _list(self, **kwargs):
932931
kwargs["params"]["per_page"] = 100
933932

934933
page = super()._list(**kwargs)
934+
ret_list = page
935935

936936
while len(page):
937-
for i in page:
938-
yield i
939937
pagenum += 1
940938
kwargs["params"]["page"] = pagenum
941939
page = super()._list(**kwargs)
940+
ret_list += page
941+
942+
return ret_list
942943

943944
def __iter__(self):
944945
return self._list()

0 commit comments

Comments
 (0)