-
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.
Exercício 28: Vocabulário de estados
- Loading branch information
Showing
5 changed files
with
75 additions
and
3 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
<configure xmlns="http://namespaces.zope.org/zope"> | ||
|
||
<utility | ||
name="trepr.intranet.vocabulary.estados" | ||
component=".estados.vocab_estados" | ||
/> | ||
</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,45 @@ | ||
from trepr.intranet import _ | ||
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) |
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,23 @@ | ||
from trepr.intranet 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", | ||
["PR", "SP", "DF"], | ||
) | ||
def test_token(self, token): | ||
assert token in [x for x in self.vocab.by_token] |
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