|
1 | | -def test_seo_behavior_fields(manager_plone_client): |
2 | | - # Enable behavior for pages |
3 | | - manager_plone_client.patch( |
4 | | - "++api++/@controlpanels/dexterity-types/Document", |
5 | | - json={"kitconcept.seo": True}, |
6 | | - ) |
7 | | - |
8 | | - # Check schema |
9 | | - schema = manager_plone_client.get("++api++/@types/Document").json() |
10 | | - assert schema["fieldsets"][-1] == { |
11 | | - "behavior": "plone", |
12 | | - "description": "", |
13 | | - "fields": [ |
14 | | - "seo_title", |
15 | | - "seo_description", |
16 | | - "seo_noindex", |
17 | | - "seo_canonical_url", |
18 | | - "opengraph_title", |
19 | | - "opengraph_description", |
20 | | - "opengraph_image", |
21 | | - ], |
22 | | - "id": "seo", |
23 | | - "title": "SEO", |
24 | | - } |
25 | | - |
26 | | - |
27 | | -def test_noindex_sets_response_header(manager_plone_client): |
28 | | - # Enable behavior for pages |
29 | | - manager_plone_client.patch( |
30 | | - "++api++/@controlpanels/dexterity-types/Document", |
31 | | - json={"kitconcept.seo": True}, |
32 | | - ) |
33 | | - |
34 | | - # Add page |
35 | | - resp = manager_plone_client.post( |
36 | | - "++api++/", |
37 | | - json={"@type": "Document", "title": "Test page", "seo_noindex": True}, |
38 | | - ) |
39 | | - assert resp.status_code == 201 |
40 | | - |
41 | | - # Confirm the page is served with X-Robots-Tag header |
42 | | - resp = manager_plone_client.get("/test-page") |
43 | | - assert resp.status_code == 200 |
44 | | - assert resp.headers["X-Robots-Tag"] == "noindex" |
45 | | - |
46 | | - # Confirm views of the page are served with X-Robots-Tag header |
47 | | - resp = manager_plone_client.get("/test-page/@@view") |
48 | | - assert resp.status_code == 200 |
49 | | - assert resp.headers["X-Robots-Tag"] == "noindex" |
| 1 | +from copy import deepcopy |
| 2 | +from kitconcept.seo import PACKAGE_NAME |
| 3 | + |
| 4 | +import pytest |
| 5 | + |
| 6 | + |
| 7 | +PAYLOAD = { |
| 8 | + "seo_title": "Foo Bar", |
| 9 | + "seo_description": "Lorem ipsum dolor sit amet", |
| 10 | + "seo_noindex": False, |
| 11 | + "seo_canonical_url": "https://example.com/canonical-url", |
| 12 | + "opengraph_title": "Open Graph Title", |
| 13 | + "opengraph_description": "Open Graph Description", |
| 14 | + "opengraph_image": None, |
| 15 | +} |
| 16 | + |
| 17 | + |
| 18 | +@pytest.fixture |
| 19 | +def payload() -> dict: |
| 20 | + data = deepcopy(PAYLOAD) |
| 21 | + return data |
| 22 | + |
| 23 | + |
| 24 | +class TestBehaviorContato: |
| 25 | + name: str = f"{PACKAGE_NAME}" |
| 26 | + |
| 27 | + @pytest.fixture(autouse=True) |
| 28 | + def _setup(self, portal_factory, dummy_type_schema, manager_html_request): |
| 29 | + self.portal = portal_factory(behavior=self.name) |
| 30 | + self.schema = dummy_type_schema() |
| 31 | + self.request = manager_html_request |
| 32 | + |
| 33 | + @pytest.mark.parametrize("key", PAYLOAD.keys()) |
| 34 | + def test_behavior_schema(self, key: str): |
| 35 | + assert key in self.schema["properties"] |
| 36 | + |
| 37 | + def test_behavior_data(self, payload: dict, create_dummy_content): |
| 38 | + response = create_dummy_content(payload) |
| 39 | + assert response.status_code == 201 |
| 40 | + |
| 41 | + def test_noindex_sets_response_header(self): |
| 42 | + # Add page |
| 43 | + resp = self.request.post( |
| 44 | + "++api++/", |
| 45 | + json={"@type": "DummyType", "title": "Test page", "seo_noindex": True}, |
| 46 | + ) |
| 47 | + assert resp.status_code == 201 |
| 48 | + |
| 49 | + # Confirm the page is served with X-Robots-Tag header |
| 50 | + resp = self.request.get("/test-page") |
| 51 | + assert resp.status_code == 200 |
| 52 | + assert resp.headers["X-Robots-Tag"] == "noindex" |
| 53 | + |
| 54 | + # Confirm views of the page are served with X-Robots-Tag header |
| 55 | + resp = self.request.get("/test-page/@@view") |
| 56 | + assert resp.status_code == 200 |
| 57 | + assert resp.headers["X-Robots-Tag"] == "noindex" |
0 commit comments