diff --git a/backend/src/portal/governo/behaviors/__init__.py b/backend/src/portal/governo/behaviors/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/src/portal/governo/behaviors/configure.zcml b/backend/src/portal/governo/behaviors/configure.zcml new file mode 100644 index 0000000..b843778 --- /dev/null +++ b/backend/src/portal/governo/behaviors/configure.zcml @@ -0,0 +1,22 @@ + + + + + + + + + diff --git a/backend/src/portal/governo/behaviors/contato.py b/backend/src/portal/governo/behaviors/contato.py new file mode 100644 index 0000000..75d02e9 --- /dev/null +++ b/backend/src/portal/governo/behaviors/contato.py @@ -0,0 +1,33 @@ +from plone.autoform.interfaces import IFormFieldProvider +from plone.schema.email import Email +from plone.supermodel import model +from portal.governo import _ +from portal.governo.utils import validadores +from zope import schema +from zope.interface import provider + + +@provider(IFormFieldProvider) +class IContato(model.Schema): + """Provê campos de contato.""" + + model.fieldset( + "contato", + _("Contato"), + fields=[ + "email", + "telefone", + ], + ) + email = Email( + title=_("Email"), + required=True, + constraint=validadores.is_valid_email, + ) + + telefone = schema.TextLine( + title=_("Telefone"), + description=_("Informe o telefone de contato"), + required=False, + constraint=validadores.is_valid_telefone, + ) diff --git a/backend/src/portal/governo/behaviors/endereco.py b/backend/src/portal/governo/behaviors/endereco.py new file mode 100644 index 0000000..2f3492c --- /dev/null +++ b/backend/src/portal/governo/behaviors/endereco.py @@ -0,0 +1,48 @@ +from plone.autoform.interfaces import IFormFieldProvider +from plone.supermodel import model +from portal.governo import _ +from zope import schema +from zope.interface import provider + + +@provider(IFormFieldProvider) +class IEndereco(model.Schema): + """Provê campos de endereço.""" + + model.fieldset( + "endereco", + _("Endereço"), + fields=[ + "endereco", + "complemento", + "cidade", + "estado", + "cep", + ], + ) + endereco = schema.TextLine( + title=_("Endereço"), + required=False, + default="", + ) + complemento = schema.TextLine( + title=_("Complemento"), + description=_("Ex. Anexo, Sala"), + required=False, + default="", + ) + cidade = schema.TextLine( + title=_("Cidade"), + required=False, + default="", + ) + estado = schema.Choice( + title=_("Estado"), + vocabulary="portal.governo.vocabulary.estados", + required=False, + ) + cep = schema.TextLine( + title=_("CEP"), + required=False, + default="", + ) diff --git a/backend/src/portal/governo/configure.zcml b/backend/src/portal/governo/configure.zcml index 934c6ba..9f31588 100644 --- a/backend/src/portal/governo/configure.zcml +++ b/backend/src/portal/governo/configure.zcml @@ -15,10 +15,11 @@ + - + diff --git a/backend/src/portal/governo/content/secretaria.py b/backend/src/portal/governo/content/secretaria.py index 02ea372..db27989 100644 --- a/backend/src/portal/governo/content/secretaria.py +++ b/backend/src/portal/governo/content/secretaria.py @@ -1,78 +1,11 @@ from plone.dexterity.content import Container -from plone.schema.email import Email from plone.supermodel import model -from portal.governo import _ -from portal.governo.utils import validadores -from zope import schema from zope.interface import implementer class ISecretaria(model.Schema): """Definição de uma Secretaria de governo.""" - model.fieldset( - "contato", - _("Contato"), - fields=[ - "email", - "telefone", - ], - ) - email = Email( - title=_("Email"), - required=True, - constraint=validadores.is_valid_email, - ) - - telefone = schema.TextLine( - title=_("Telefone"), - description=_("Informe o telefone de contato"), - required=False, - constraint=validadores.is_valid_telefone, - ) - - model.fieldset( - "endereco", - _("Endereço"), - fields=[ - "endereco", - "complemento", - "cidade", - "estado", - "cep", - ], - ) - endereco = schema.TextLine( - title=_("Endereço"), - description=_("Informe o endereço"), - required=False, - default="", - ) - - complemento = schema.TextLine( - title=_("Complemento"), - description=_("Informe o complemento"), - required=False, - ) - - cidade = schema.TextLine( - title=_("Cidade"), - description=_("Informe a cidade"), - required=False, - ) - - estado = schema.Choice( - title=_("Estado"), - vocabulary="portal.governo.vocabulary.estados", - required=False, - ) - - cep = schema.TextLine( - title=_("CEP"), - description=_("Informe o CEP"), - required=False, - ) - @implementer(ISecretaria) class Secretaria(Container): diff --git a/backend/src/portal/governo/profiles/default/metadata.xml b/backend/src/portal/governo/profiles/default/metadata.xml index eec40a3..a49763d 100644 --- a/backend/src/portal/governo/profiles/default/metadata.xml +++ b/backend/src/portal/governo/profiles/default/metadata.xml @@ -1,6 +1,6 @@ - 1000 + 1001 profile-plone.volto:default diff --git a/backend/src/portal/governo/profiles/default/types/Secretaria.xml b/backend/src/portal/governo/profiles/default/types/Secretaria.xml index 2f5ab91..d8c1f71 100644 --- a/backend/src/portal/governo/profiles/default/types/Secretaria.xml +++ b/backend/src/portal/governo/profiles/default/types/Secretaria.xml @@ -34,6 +34,8 @@ + + diff --git a/backend/src/portal/governo/upgrades/configure.zcml b/backend/src/portal/governo/upgrades/configure.zcml index 3e2a74e..9f63e93 100644 --- a/backend/src/portal/governo/upgrades/configure.zcml +++ b/backend/src/portal/governo/upgrades/configure.zcml @@ -3,17 +3,15 @@ xmlns:genericsetup="http://namespaces.zope.org/genericsetup" > - diff --git a/backend/tests/behaviors/conftest.py b/backend/tests/behaviors/conftest.py new file mode 100644 index 0000000..3be8ec5 --- /dev/null +++ b/backend/tests/behaviors/conftest.py @@ -0,0 +1,80 @@ +from plone.app.testing import setRoles +from plone.app.testing import SITE_OWNER_NAME +from plone.app.testing import SITE_OWNER_PASSWORD +from plone.app.testing import TEST_USER_ID +from plone.dexterity.fti import DexterityFTI +from plone.restapi.testing import RelativeSession +from zope.component.hooks import setSite + +import pytest +import transaction + + +@pytest.fixture() +def request_factory(portal): + def factory(): + url = portal.absolute_url() + api_session = RelativeSession(url) + api_session.headers.update({"Accept": "application/json"}) + return api_session + + return factory + + +@pytest.fixture() +def anon_request(request_factory): + return request_factory() + + +@pytest.fixture() +def manager_request(request_factory): + request = request_factory() + request.auth = (SITE_OWNER_NAME, SITE_OWNER_PASSWORD) + yield request + request.auth = () + + +@pytest.fixture +def portal(functional): + return functional["portal"] + + +@pytest.fixture +def portal_integration(integration): + return integration["portal"] + + +@pytest.fixture +def portal_factory(functional): + def func(behavior: str): + portal = functional["portal"] + setRoles(portal, TEST_USER_ID, ["Manager"]) + fti = DexterityFTI("DummyType") + fti.behaviors = (behavior,) + portal.portal_types._setObject("DummyType", fti) + setSite(portal) + transaction.commit() + return portal + + return func + + +@pytest.fixture +def dummy_type_schema(manager_request): + def func(): + url = "/@types/DummyType" + response = manager_request.get(url) + data = response.json() + return data + + return func + + +@pytest.fixture +def create_dummy_content(manager_request): + def func(payload: dict): + payload["@type"] = "DummyType" + response = manager_request.post("/", json=payload) + return response + + return func diff --git a/backend/tests/behaviors/test_behavior_contato.py b/backend/tests/behaviors/test_behavior_contato.py new file mode 100644 index 0000000..d2779ee --- /dev/null +++ b/backend/tests/behaviors/test_behavior_contato.py @@ -0,0 +1,28 @@ +from portal.governo import PACKAGE_NAME + +import pytest + + +@pytest.fixture +def payload() -> dict: + return { + "email": "foo@rs.gov.br", + "telefone": "51999528312", + } + + +class TestBehaviorContato: + name: str = f"{PACKAGE_NAME}.behavior.contato" + + @pytest.fixture(autouse=True) + def _setup(self, portal_factory, dummy_type_schema): + self.portal = portal_factory(behavior=self.name) + self.schema = dummy_type_schema() + + def test_behavior_schema(self, payload): + for key in payload: + assert key in self.schema["properties"] + + def test_behavior_data(self, payload, create_dummy_content): + response = create_dummy_content(payload) + assert response.status_code == 201 diff --git a/backend/tests/content/test_ct_secretaria.py b/backend/tests/content/test_ct_secretaria.py index 74fa5c9..799d117 100644 --- a/backend/tests/content/test_ct_secretaria.py +++ b/backend/tests/content/test_ct_secretaria.py @@ -53,6 +53,8 @@ def test_factory(self): "plone.constraintypes", "plone.navigationroot", "volto.preview_image", + "portal.governo.behavior.contato", + "portal.governo.behavior.endereco", ], ) def test_has_behavior(self, get_behaviors, behavior): diff --git a/backend/tests/setup/test_setup_install.py b/backend/tests/setup/test_setup_install.py index 91ef9ed..52a6119 100644 --- a/backend/tests/setup/test_setup_install.py +++ b/backend/tests/setup/test_setup_install.py @@ -14,4 +14,4 @@ def test_browserlayer(self, browser_layers): def test_latest_version(self, profile_last_version): """Test latest version of default profile.""" - assert profile_last_version(f"{PACKAGE_NAME}:default") == "1000" + assert profile_last_version(f"{PACKAGE_NAME}:default") == "1001"