-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Exercicio 26: Cria comportamento endereço e econtato
- Loading branch information
1 parent
79a9928
commit 99805a8
Showing
13 changed files
with
221 additions
and
74 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<configure | ||
xmlns="http://namespaces.zope.org/zope" | ||
xmlns:plone="http://namespaces.plone.org/plone" | ||
> | ||
|
||
<plone:behavior | ||
name="portal.governo.behavior.contato" | ||
title="Informações de Contato" | ||
description="Adiciona campos de informações de contato." | ||
provides=".contato.IContato" | ||
/> | ||
|
||
|
||
<plone:behavior | ||
name="portal.governo.behavior.endereco" | ||
title="Informações de Endereço" | ||
description="Adiciona campos de informações de endereço." | ||
provides=".endereco.IEndereco" | ||
/> | ||
|
||
|
||
</configure> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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="", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from portal.governo import PACKAGE_NAME | ||
|
||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def payload() -> dict: | ||
return { | ||
"email": "[email protected]", | ||
"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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters