|
| 1 | +from plone import api |
| 2 | + |
| 3 | +import json |
| 4 | +import pytest |
| 5 | +import transaction |
| 6 | + |
| 7 | + |
| 8 | +@pytest.fixture(scope="class") |
| 9 | +def portal(portal_class): |
| 10 | + yield portal_class |
| 11 | + |
| 12 | + |
| 13 | +@pytest.fixture(scope="class") |
| 14 | +def contents(portal): |
| 15 | + with api.env.adopt_roles(["Manager"]): |
| 16 | + doc = api.content.create(portal, type="Document", id="doc1") |
| 17 | + doc.Subject = ["doc"] |
| 18 | + api.content.transition(obj=doc, transition="publish") |
| 19 | + transaction.commit() |
| 20 | + |
| 21 | + |
| 22 | +class TestKeywordsPatch: |
| 23 | + @pytest.fixture(autouse=True) |
| 24 | + def _setup(self, contents, api_manager_request, api_anon_request): |
| 25 | + self.api_session = api_manager_request |
| 26 | + self.anon_api_session = api_anon_request |
| 27 | + |
| 28 | + def test_response(self): |
| 29 | + resp = self.api_session.patch( |
| 30 | + "/@keywords", |
| 31 | + data=json.dumps({"new_keyword": "document", "old_keywords": ["doc"]}), |
| 32 | + headers={"Accept": "application/json"}, |
| 33 | + ) |
| 34 | + assert resp.status_code == 204 |
| 35 | + |
| 36 | + def test_response_non_root(self): |
| 37 | + resp = self.api_session.patch("/doc1/@keywords") |
| 38 | + assert resp.status_code == 404 |
| 39 | + |
| 40 | + def test_response_anonymous(self): |
| 41 | + resp = self.anon_api_session.patch("/doc1/@keywords") |
| 42 | + assert resp.status_code == 404 |
0 commit comments