-
-
Notifications
You must be signed in to change notification settings - Fork 108
Feature: Validação CEP #123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e103e0b
114019c
e6aacd8
519ee35
85e4d99
5bcac91
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| from random import randint | ||
|
|
||
|
|
||
| # FORMATTING | ||
| ############ | ||
|
|
||
|
|
||
| # OPERATIONS | ||
| ############ | ||
|
|
||
|
|
||
| def is_valid(cep): # type: (str) -> bool | ||
| """ | ||
| Returns when CEP is valid, input should be a digit | ||
| string of proper length. Doesn't validate if it's real, | ||
| 'cause only the "Correios" Base does. | ||
|
|
||
| Source: https://en.wikipedia.org/wiki/C%C3%B3digo_de_Endere%C3%A7amento_Postal | ||
|
|
||
| """ | ||
|
|
||
| return isinstance(cep, str) and len(cep) == 8 and cep.isdigit() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| from os import pardir | ||
| from os.path import abspath, join, dirname | ||
| from sys import path, version_info, dont_write_bytecode | ||
| from inspect import getsourcefile | ||
| from unittest.mock import patch | ||
|
|
||
| dont_write_bytecode = True | ||
| range = range if version_info.major >= 3 else xrange | ||
| path.insert( | ||
| 1, abspath(join(dirname(abspath(getsourcefile(lambda: 0))), pardir)) | ||
| ) | ||
| from brutils.cep import ( | ||
| is_valid, | ||
| ) | ||
| from unittest import TestCase, main | ||
|
|
||
|
|
||
| class CEP(TestCase): | ||
| def test_is_valid(self): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👏👏👏 |
||
| # When CEP is not string, returns False | ||
| assert not is_valid(1) | ||
|
|
||
| # When CEP's len is different of 8, returns False | ||
| assert not is_valid("1") | ||
|
|
||
| # When CEP does not contain only digits, returns False | ||
| assert not is_valid("1234567-") | ||
|
|
||
| # When CEP is valid | ||
| assert is_valid("99999999") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Um CEP pode ter tudo o mesmo número?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. é dificil, mas o pior é que pode kkkk 😵💫 pesquisei alguns casos:
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Caraca, que loucura!! Deve ser bem bom para decorar hahah |
||
| assert is_valid("88390000") | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Esse disclaimer podia estar na documentação (READMEs) também. O quê achas? Assim a pessoa que for utilizar já fica ciente de como a função funciona.