-
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 23: adiciona vocabulario para estados
- Loading branch information
1 parent
721927a
commit c6b1ea4
Showing
5 changed files
with
78 additions
and
6 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="portal.governo.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,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) |
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 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] |
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