-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
97 lines (56 loc) · 2.51 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# -*- coding : utf-8 -*-
import unittest
from exceptions import AddressNotFound, InvalidCepException
from models import CEP , Address
from pycep import PyCEP as pycep
class TestBehaviorCEPModel(unittest.TestCase):
def test_cep_must_be_right_format_with_string(self):
cep = CEP("00000111")
def test_cep_must_be_wrong_format_with_string(self):
with self.assertRaises(InvalidCepException):
cep = CEP("999999999")
def test_cep_must_be_wrong_using_integers_without_separator(self):
with self.assertRaises(InvalidCepException):
cep = CEP(12345111)
def test_cep_must_be_wrong_with_separator(self):
with self.assertRaises(InvalidCepException):
cep = CEP("99999-9999")
def test_must_return_your_value_normalized(self):
cep = CEP("12345-678")
self.assertEqual("12345678",cep.value)
class TestBehaviorWrapperRequestAPI(unittest.TestCase):
def test_wrapper_must_raise_exception_with_cep_is_wrong_format(self):
with self.assertRaises(InvalidCepException):
cep = pycep.get("999999999")
def test_wrapper_must_raise_exception_when_cep_is_not_found(self):
with self.assertRaises(AddressNotFound):
cep = pycep.get("99999999")
def test_wrapper_must_request_a_cep_correct_with_separator(self):
address = pycep.get("01001-000")
self.assertIsInstance(address,Address)
def test_wrapper_must_return_object_address_by_request_right(self):
address = pycep.get("01001000")
self.assertIsInstance(address,Address)
class TestBehaviorAddressFieldsWithRequest(unittest.TestCase):
def setUp(self):
self.address = pycep.get("01001-000")
def test_model_address_must_return_cep_formatted(self):
self.assertEqual("01001-000",self.address.cep)
def test_model_address_must_return_logradouro(self):
self.assertEqual("Praça da Sé",self.address.logradouro)
def test_model_address_must_return_complemento(self):
self.assertEqual("lado ímpar",self.address.complemento)
def test_model_address_must_return_bairro(self):
self.assertEqual("Sé",self.address.bairro)
def test_model_address_must_return_localidade(self):
self.assertEqual("São Paulo",self.address.localidade)
def test_model_address_must_return_uf(self):
self.assertEqual("SP",self.address.uf)
def test_model_address_must_return_unidade(self):
self.assertEqual("",self.address.unidade)
def test_model_address_must_return_ibge(self):
self.assertEqual(3550308,self.address.ibge)
def test_model_address_must_return_gia(self):
self.assertEqual(1004,self.address.gia)
if __name__ == "__main__":
unittest.main(verbosity=2)