Skip to content

Commit

Permalink
Exercício 18: Teste de permissão de secretaria
Browse files Browse the repository at this point in the history
  • Loading branch information
samoel-silva committed Sep 12, 2024
1 parent dd44f30 commit 3b80a7c
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions backend/tests/content/test_ct_secretaria.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from AccessControl import Unauthorized
from plone import api
from plone.dexterity.fti import DexterityFTI
from portal.governo.content.secretaria import Secretaria
Expand Down Expand Up @@ -57,8 +58,25 @@ def test_factory(self):
def test_has_behavior(self, get_behaviors, behavior):
assert behavior in get_behaviors(CONTENT_TYPE)

def test_create(self, secretaria_payload):
with api.env.adopt_roles(["Manager"]):
content = api.content.create(container=self.portal, **secretaria_payload)
assert content.portal_type == CONTENT_TYPE
assert isinstance(content, Secretaria)
@pytest.mark.parametrize(
"role, allowed",
[
["Manager", True],
["Site Administrator", True],
["Member", False],
["Editor", False],
],
)
def test_create(self, secretaria_payload, role, allowed):
if allowed:
with api.env.adopt_roles(role):
content = api.content.create(
container=self.portal, **secretaria_payload
)
assert content.portal_type == CONTENT_TYPE
assert isinstance(content, Secretaria)
else:
with pytest.raises(Unauthorized):
content = api.content.create(
container=self.portal, **secretaria_payload
)

0 comments on commit 3b80a7c

Please sign in to comment.