diff --git a/backend/src/trepr/intranet/behaviors/__init__.py b/backend/src/trepr/intranet/behaviors/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/src/trepr/intranet/behaviors/configure.zcml b/backend/src/trepr/intranet/behaviors/configure.zcml new file mode 100644 index 0000000..6c3359d --- /dev/null +++ b/backend/src/trepr/intranet/behaviors/configure.zcml @@ -0,0 +1,20 @@ + + + + + + + diff --git a/backend/src/trepr/intranet/behaviors/contato.py b/backend/src/trepr/intranet/behaviors/contato.py new file mode 100644 index 0000000..243a8ea --- /dev/null +++ b/backend/src/trepr/intranet/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 trepr.intranet import _ +from trepr.intranet.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/trepr/intranet/behaviors/endereco.py b/backend/src/trepr/intranet/behaviors/endereco.py new file mode 100644 index 0000000..bb1b395 --- /dev/null +++ b/backend/src/trepr/intranet/behaviors/endereco.py @@ -0,0 +1,48 @@ +from plone.autoform.interfaces import IFormFieldProvider +from plone.supermodel import model +from trepr.intranet 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="trepr.intranet.vocabulary.estados", + required=False, + ) + cep = schema.TextLine( + title=_("CEP"), + required=False, + default="", + ) diff --git a/backend/src/trepr/intranet/configure.zcml b/backend/src/trepr/intranet/configure.zcml index eafb880..eea0354 100644 --- a/backend/src/trepr/intranet/configure.zcml +++ b/backend/src/trepr/intranet/configure.zcml @@ -16,6 +16,7 @@ + diff --git a/backend/src/trepr/intranet/content/area.py b/backend/src/trepr/intranet/content/area.py index 7fb4064..9a26d95 100644 --- a/backend/src/trepr/intranet/content/area.py +++ b/backend/src/trepr/intranet/content/area.py @@ -1,73 +1,11 @@ from plone.dexterity.content import Container -from plone.schema.email import Email from plone.supermodel import model -from trepr.intranet import _ -from trepr.intranet.utils import validadores -from zope import schema from zope.interface import implementer class IArea(model.Schema): """Definição de uma Área.""" - 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"), - required=False, - ) - - complemento = schema.TextLine( - title=_("Complemento"), - required=False, - ) - - cidade = schema.TextLine( - title=_("Cidade"), - required=False, - ) - - estado = schema.Choice( - title=_("Estado"), - vocabulary="trepr.intranet.vocabulary.estados", - required=False, - ) - - cep = schema.TextLine( - title=_("CEP"), - required=False, - ) - @implementer(IArea) class Area(Container): diff --git a/backend/src/trepr/intranet/profiles/default/metadata.xml b/backend/src/trepr/intranet/profiles/default/metadata.xml index c237516..e78048f 100644 --- a/backend/src/trepr/intranet/profiles/default/metadata.xml +++ b/backend/src/trepr/intranet/profiles/default/metadata.xml @@ -1,6 +1,6 @@ - 1003 + 1004 profile-plone.volto:default diff --git a/backend/src/trepr/intranet/profiles/default/types/Area.xml b/backend/src/trepr/intranet/profiles/default/types/Area.xml index be78aab..fe44739 100644 --- a/backend/src/trepr/intranet/profiles/default/types/Area.xml +++ b/backend/src/trepr/intranet/profiles/default/types/Area.xml @@ -34,6 +34,8 @@ + + diff --git a/backend/src/trepr/intranet/upgrades/configure.zcml b/backend/src/trepr/intranet/upgrades/configure.zcml index 4f37878..ca24fb4 100644 --- a/backend/src/trepr/intranet/upgrades/configure.zcml +++ b/backend/src/trepr/intranet/upgrades/configure.zcml @@ -44,4 +44,15 @@ /> + + + + 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..3711c64 --- /dev/null +++ b/backend/tests/behaviors/test_behavior_contato.py @@ -0,0 +1,28 @@ +from trepr.intranet import PACKAGE_NAME + +import pytest + + +@pytest.fixture +def payload() -> dict: + return { + "email": "foo@tre-pr.jus.br", + "telefone": "41999528312", + } + + +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/behaviors/test_behavior_endereco.py b/backend/tests/behaviors/test_behavior_endereco.py new file mode 100644 index 0000000..a11aa46 --- /dev/null +++ b/backend/tests/behaviors/test_behavior_endereco.py @@ -0,0 +1,31 @@ +from trepr.intranet import PACKAGE_NAME + +import pytest + + +@pytest.fixture +def payload() -> dict: + return { + "endereco": "R. João Parolin, 224", + "complemento": "Prado Velho", + "cidade": "Curitiba", + "estado": "PR", + "cep": "80220-902", + } + + +class TestBehaviorEndereco: + name: str = f"{PACKAGE_NAME}.behavior.endereco" + + @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_content_area.py b/backend/tests/content/test_content_area.py index 700c70d..29f727e 100644 --- a/backend/tests/content/test_content_area.py +++ b/backend/tests/content/test_content_area.py @@ -46,6 +46,8 @@ def test_factory(self): "plone.shortname", "plone.excludefromnavigation", "plone.versioning", + "trepr.intranet.behavior.contato", + "trepr.intranet.behavior.endereco", "volto.blocks", "plone.constraintypes", "volto.preview_image", diff --git a/backend/tests/setup/test_setup_install.py b/backend/tests/setup/test_setup_install.py index 9ef98da..1c6d7d8 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") == "1003" + assert profile_last_version(f"{PACKAGE_NAME}:default") == "1004"