def test_deveria_lancar_excecao_se_ha_caracteres_nao_esperado_no_numero(self): with self.assertRaises(ValidationError): utils.CPF([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, "a"]) with self.assertRaises(ValidationError): utils.CPF([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, "*"]) with self.assertRaises(ValidationError): utils.CPF([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, "^"])
def test_deveria_lancar_excecao_se_nao_houver_todos_os_numeros(self): with self.assertRaises(ValidationError): utils.CPF(["1" * 10])
def test_deveria_definir_numeros_no_atributo_cpf(self): cpf = utils.CPF("1" * 11) self.assertEqual("1" * 11, cpf.cpf)
def test_deveria_ser_diferente_para_numero_invalido(self): self.assertTrue("2" * 10 != utils.CPF("1" * 11))
def test_getitem_deveria_numero_da_posicao_correspondente(self): self.assertEqual("7", utils.CPF("67594476387")[1])
def test_repr_deveria_numero_com_nome_da_classe(self): self.assertEqual("CPF('67594476387')", repr(utils.CPF("67594476387")))
def test_str_deveria_retornar_o_numero_formatado(self): self.assertEqual("675.944.763-87", str(utils.CPF("67594476387")))
def test_avaliacao_booleana_deveria_ser_valido(self): self.assertTrue(bool(utils.CPF("675.944.763-87")))
def test_deveria_ser_diferente(self): self.assertFalse("2" * 11 == utils.CPF("1" * 11))
def test_deveria_ser_igual(self): self.assertTrue("1" * 11 == utils.CPF("1" * 11))
def test_numero_deveria_ser_invalido(self): self.assertFalse(utils.CPF("675.944.763-80").valido())
def test_numero_deveria_ser_valido(self): self.assertTrue(utils.CPF("675.944.763-87").valido())
def test_format_deveria_adicionar_pontos_e_traco_no_numero(self): self.assertEqual("111.111.111-11", utils.CPF("11111111111").format())
def test_deveria_remover_caracteres_ponto_e_traco_do_numero(self): cpf = utils.CPF("111.111.111-11") self.assertEqual("11111111111", cpf.cpf)
def test_deveria_transformar_lista_de_numeros_em_string_unica(self): cpf = utils.CPF([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) self.assertEqual("1" * 11, cpf.cpf)
def test_deveria_lancar_excecao_se_houver_numeros_a_mais(self): with self.assertRaises(ValidationError): utils.CPF("1" * 12)