Skip to content

Commit

Permalink
Exercicio 23: adiciona vocabulario para estados
Browse files Browse the repository at this point in the history
  • Loading branch information
samoel-silva committed Sep 16, 2024
1 parent 721927a commit c6b1ea4
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 6 deletions.
4 changes: 2 additions & 2 deletions backend/src/portal/governo/content/secretaria.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ class ISecretaria(model.Schema):
required=False,
)

estado = schema.TextLine(
estado = schema.Choice(
title=_("Estado"),
description=_("Informe o estado"),
vocabulary="portal.governo.vocabulary.estados",
required=False,
)

Expand Down
5 changes: 4 additions & 1 deletion backend/src/portal/governo/vocabularies/configure.zcml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<configure xmlns="http://namespaces.zope.org/zope">

<utility
name="portal.governo.vocabulary.estados"
component=".estados.vocab_estados"
/>
</configure>
44 changes: 44 additions & 0 deletions backend/src/portal/governo/vocabularies/estados.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from zope.interface import provider
from zope.schema.interfaces import IVocabularyFactory
from zope.schema.vocabulary import SimpleTerm
from zope.schema.vocabulary import SimpleVocabulary


OPCOES = [
("AC", "Acre"),
("AL", "Alagoas"),
("AP", "Amapá"),
("AM", "Amazonas"),
("BA", "Bahia"),
("CE", "Ceará"),
("DF", "Distrito Federal"),
("ES", "Espírito Santo"),
("GO", "Goiás"),
("MA", "Maranhão"),
("MT", "Mato Grosso"),
("MS", "Mato Grosso do Sul"),
("MG", "Minas Gerais"),
("PA", "Pará"),
("PB", "Paraíba"),
("PR", "Paraná"),
("PE", "Pernambuco"),
("PI", "Piauí"),
("RJ", "Rio de Janeiro"),
("RN", "Rio Grande do Norte"),
("RS", "Rio Grande do Sul"),
("RO", "Rondônia"),
("RR", "Roraima"),
("SC", "Santa Catarina"),
("SP", "São Paulo"),
("SE", "Sergipe"),
("TO", "Tocantins"),
]


@provider(IVocabularyFactory)
def vocab_estados(context) -> SimpleVocabulary:
"""Estados do Brasil."""
terms = []
for token, title in OPCOES:
terms.append(SimpleTerm(token, token, title))
return SimpleVocabulary(terms)
23 changes: 23 additions & 0 deletions backend/tests/vocabularies/test_voc_estados.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from portal.governo import PACKAGE_NAME
from zope.schema.vocabulary import SimpleVocabulary

import pytest


class TestVocabEstados:
name = f"{PACKAGE_NAME}.vocabulary.estados"

@pytest.fixture(autouse=True)
def _vocab(self, get_vocabulary, portal):
self.vocab = get_vocabulary(self.name, portal)

def test_vocabulary(self):
assert self.vocab is not None
assert isinstance(self.vocab, SimpleVocabulary)

@pytest.mark.parametrize(
"token",
["RS", "SP", "DF"],
)
def test_token(self, token):
assert token in [x for x in self.vocab.by_token]
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ const Endereco = (props) => {
</Container>
<Container className="endereco">
<span>Cidade</span>: <span>{cidade}</span>
</Container>
<Container className="endereco">
<span>Estado</span>: <span>{estado}</span>
{estado && (
<>
- <span className="estado">{estado.token}</span>
</>
)}
</Container>
<Container className="endereco">
<span>CEP</span>: <span>{cep}</span>
Expand Down

0 comments on commit c6b1ea4

Please sign in to comment.