Skip to content

Commit f7a6249

Browse files
committed
Update tests to have the same content available in portal, add doc strings
1 parent 998fb58 commit f7a6249

File tree

2 files changed

+27
-24
lines changed

2 files changed

+27
-24
lines changed

tests/services/blocktypes/test_blocktypes_get.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,29 @@ def portal(portal_class):
99
yield portal_class
1010

1111

12+
@pytest.fixture(scope="class")
13+
def contents(portal):
14+
with api.env.adopt_roles(["Manager"]):
15+
doc = api.content.create(portal, type="Document", id="lorem-ipsum")
16+
doc.blocks = {
17+
"1": {"@type": "title"},
18+
"2": {"@type": "teaser"},
19+
"3": {
20+
"@type": "gridBlock",
21+
"blocks": {
22+
"1": {"@type": "teaser"},
23+
"2": {"@type": "teaser"},
24+
"3": {"@type": "teaser"},
25+
},
26+
},
27+
}
28+
doc.reindexObject(idxs=["block_types"])
29+
transaction.commit()
30+
31+
1232
class TestBlockTypesGet:
1333
@pytest.fixture(autouse=True)
14-
def _setup(self, portal, api_manager_request):
34+
def _setup(self, contents, portal, api_manager_request):
1535
self.portal = portal
1636
self.api_session = api_manager_request
1737

@@ -26,28 +46,11 @@ def test_response_type_with_id(self):
2646
assert isinstance(data, list)
2747

2848
def test_filtered(self):
29-
with api.env.adopt_roles(["Manager"]):
30-
doc = api.content.create(self.portal, type="Document", id="lorem-ipsum")
31-
doc.blocks = {
32-
"1": {"@type": "title"},
33-
"2": {"@type": "teaser"},
34-
"3": {
35-
"@type": "gridBlock",
36-
"blocks": {
37-
"1": {"@type": "teaser"},
38-
"2": {"@type": "teaser"},
39-
"3": {"@type": "teaser"},
40-
},
41-
},
42-
}
43-
doc.reindexObject(idxs=["block_types"])
44-
transaction.commit()
45-
4649
response = self.api_session.get("/@blocktypes?path=/plone/lorem-ipsum")
4750
data = response.json()
4851
assert len(data) == 3
4952

5053
def test_filtered_with_id(self):
5154
response = self.api_session.get("/@blocktypes/teaser?path=/plone/lorem-ipsum")
5255
data = response.json()
53-
assert len(data) == 4
56+
assert len(data) == 1

tests/services/conftest.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88

99
@pytest.fixture()
1010
def portal(functional):
11-
""""""
11+
"""Provide the Plone portal instance for functional tests."""
1212
yield functional["portal"]
1313

1414

1515
@pytest.fixture(scope="class")
1616
def portal_class(functional_class):
17-
""""""
17+
"""Provide the Plone portal instance for class-scoped functional tests."""
1818
if hasattr(functional_class, "testSetUp"):
1919
functional_class.testSetUp()
2020
portal = functional_class["portal"]
@@ -26,7 +26,7 @@ def portal_class(functional_class):
2626

2727
@pytest.fixture()
2828
def request_api_factory(portal):
29-
""""""
29+
"""Provide a factory function for creating Plone REST API session objects."""
3030

3131
def factory():
3232
url = portal.absolute_url()
@@ -38,14 +38,14 @@ def factory():
3838

3939
@pytest.fixture()
4040
def api_anon_request(request_api_factory):
41-
""""""
41+
"""Provide an unauthenticated REST API session for anonymous requests."""
4242
request = request_api_factory()
4343
yield request
4444

4545

4646
@pytest.fixture()
4747
def api_manager_request(request_api_factory):
48-
""""""
48+
"""Provide an authenticated REST API session with manager privileges."""
4949
request = request_api_factory()
5050
request.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD)
5151
yield request

0 commit comments

Comments
 (0)