Repository: brazilian-utils/brutils-python (2023-07-08 ~ 2023-07-23)

problem_statement: Formatação de CEPs
Implementar um utilitário que recebe um CEP apenas com dígitos e retorna o CEP com símbolos (ponto e traço)
date: 2023-07-08
patch: diff --git a/README.md b/README.md
index 807b7e8..686d27d 100644
--- a/README.md
+++ b/README.md
@@ -46,6 +46,7 @@ False
   - [generate_cnpj](#generate_cnpj)
 - [CEP](#cep)
   - [is_valid_cep](#is_valid_cep)
+  - [format_cep](#format_cep)
   - [generate_cep](#generate_cep)  
 
 ## CPF
@@ -139,10 +140,20 @@ Verifica se o CEP é valido. Apenas números, formatados como string. Não verif
 
 ```python
 >>> from brutils import is_valid_cep
->>> is_valid_cep('88390000')
+>>> is_valid_cep('01310200')
 True
 ```
 
+### format_cep
+
+Formata o CEP. Retorna None se o CEP for inválido.
+
+```python
+>>> from brutils import format_cep
+>>> format_cep('01310200')
+'01310-200'
+```
+
 ### generate_cep
 
 Gera um CEP válido aleatório.
diff --git a/README_EN.md b/README_EN.md
index d461943..9d9422f 100644
--- a/README_EN.md
+++ b/README_EN.md
@@ -45,7 +45,8 @@ False
   - [remove_symbols_cnpj](#remove_symbols_cnpj)
   - [generate_cnpj](#generate_cnpj)
 - [CEP](#cep)
-  - [is_valid_cep](#is_valid_cep)  
+  - [is_valid_cep](#is_valid_cep)
+  - [format_cep](#format_cep)   
   - [generate_cep](#generate_cep)
 
 ## CPF
@@ -144,10 +145,20 @@ Check if CEP is valid. Numbers only, formatted as strings. Does not check if CEP
 
 ```python
 >>> from brutils import is_valid_cep
->>> is_valid_cep('88390000')
+>>> is_valid_cep('01310200')
 True
 ```
 
+### format_cep
+
+Format CEP. Returns None if CEP is invalid.
+
+```python
+>>> from brutils import format_cep
+>>> format_cpf('01310200')
+'01310-200'
+```
+
 ### generate_cep
 
 Generate a valid random CEP.
diff --git a/brutils/__init__.py b/brutils/__init__.py
index e2f1aee..e51068c 100644
--- a/brutils/__init__.py
+++ b/brutils/__init__.py
@@ -12,5 +12,6 @@ from brutils.cnpj import (
 )
 from brutils.cep import (
     is_valid as is_valid_cep,
+    format_cep,
     generate as generate_cep,
 )
diff --git a/brutils/cep.py b/brutils/cep.py
index 0b17012..cd86408 100644
--- a/brutils/cep.py
+++ b/brutils/cep.py
@@ -5,6 +5,18 @@ from random import randint
 ############
 
 
+def format_cep(cep):  # type: (str) -> str
+    """
+    Will format an adequately formatted numbers-only CEP string,
+    adding in standard formatting visual aid symbols for display.
+    """
+
+    if not is_valid(cep):
+        return None
+
+    return "{}-{}".format(cep[:5], cep[5:8])
+
+
 # OPERATIONS
 ############
 

test_patch: diff --git a/tests/test_cep.py b/tests/test_cep.py
index e023061..a2a2eca 100644
--- a/tests/test_cep.py
+++ b/tests/test_cep.py
@@ -11,12 +11,25 @@ path.insert(
 )
 from brutils.cep import (
     is_valid,
+    format_cep,
     generate,
 )
 from unittest import TestCase, main
 
 
 class CEP(TestCase):
+    def test_format_cep(self):
+        with patch("brutils.cep.is_valid", return_value=True) as mock_is_valid:
+            # When cep is_valid, returns formatted cep
+            assert format_cep("01310200") == "01310-200"
+
+        # Checks if function is_valid_cnpj is called
+        mock_is_valid.assert_called_once_with("01310200")
+
+        with patch("brutils.cep.is_valid", return_value=False) as mock_is_valid:
+            # When cep isn't valid, returns None
+            assert format_cep("013102009") is None
+
     def test_is_valid(self):
         # When CEP is not string, returns False
         assert not is_valid(1)


----

problem_statement: Gerar CEPs aleatórios e válidos
Implementar um utilitário que retorna um CEP aleatório válido
date: 2023-07-08
patch: diff --git a/brutils/__init__.py b/brutils/__init__.py
--- a/brutils/__init__.py
+++ b/brutils/__init__.py
@@ -13,4 +13,5 @@
 from brutils.cep import (
     is_valid as is_valid_cep,
     format_cep,
+    generate as generate_cep,
 )


----

problem_statement: Remover Símbolos de CEPs
Implementar um utilitário que recebe um CEP com símbolos (ponto e traço) e retorna esse CEP apenas com dígitos
date: 2023-07-23
patch: diff --git a/README.md b/README.md
index 686d27d..b546bba 100644
--- a/README.md
+++ b/README.md
@@ -47,6 +47,7 @@ False
 - [CEP](#cep)
   - [is_valid_cep](#is_valid_cep)
   - [format_cep](#format_cep)
+  - [remove_symbols_cep](#remove_symbols_cep)
   - [generate_cep](#generate_cep)  
 
 ## CPF
@@ -80,6 +81,7 @@ Remove os símbolos de formatação do CPF e retorna somente números. Filtra ap
 >>> remove_symbols_cpf('000.111.222-33')
 '00011122233'
 ```
+
 ### generate_cpf
 
 Gera um CPF válido aleatório.
@@ -154,6 +156,16 @@ Formata o CEP. Retorna None se o CEP for inválido.
 '01310-200'
 ```
 
+### remove_symbols_cep
+
+Remove os símbolos de formatação do CEP e retorna somente números. Filtra apenas os símbolos utilizados para a validação do CEP. Propositalmente não remove outros símbolos.
+
+```python
+>>> from brutils import remove_symbols_cep
+>>> remove_symbols_cep('01310-200')
+'01310200'
+```
+
 ### generate_cep
 
 Gera um CEP válido aleatório.
diff --git a/README_EN.md b/README_EN.md
index 9d9422f..f1d5621 100644
--- a/README_EN.md
+++ b/README_EN.md
@@ -46,7 +46,8 @@ False
   - [generate_cnpj](#generate_cnpj)
 - [CEP](#cep)
   - [is_valid_cep](#is_valid_cep)
-  - [format_cep](#format_cep)   
+  - [format_cep](#format_cep)
+  - [remove_symbols_cep](#remove_symbols_cep)   
   - [generate_cep](#generate_cep)
 
 ## CPF
@@ -159,6 +160,18 @@ Format CEP. Returns None if CEP is invalid.
 '01310-200'
 ```
 
+### remove_symbols_cep
+
+Remove formatting symbols from CEP and return only digits.
+It only filters out the symbols used for CEP validation.
+It purposefully doesn't remove other symbols.
+
+```python
+>>> from brutils import remove_symbols_cep
+>>> remove_symbols_cep('01310-200')
+'01310200'
+```
+
 ### generate_cep
 
 Generate a valid random CEP.
diff --git a/brutils/__init__.py b/brutils/__init__.py
index e51068c..839548a 100644
--- a/brutils/__init__.py
+++ b/brutils/__init__.py
@@ -14,4 +14,5 @@ from brutils.cep import (
     is_valid as is_valid_cep,
     format_cep,
     generate as generate_cep,
+    remove_symbols as remove_symbols_cep,
 )
diff --git a/brutils/cep.py b/brutils/cep.py
index cd86408..ecf67a0 100644
--- a/brutils/cep.py
+++ b/brutils/cep.py
@@ -5,6 +5,16 @@ from random import randint
 ############
 
 
+def remove_symbols(dirty):  # type: (str) -> str
+    """
+    Filters out CEP formatting symbols. Symbols that are not used
+    in the CEP formatting are left unfiltered on purpose so that
+    if fails other tests, because their presence indicate that the
+    input was somehow corrupted.
+    """
+    return "".join(filter(lambda char: char not in ".-", dirty))
+
+
 def format_cep(cep):  # type: (str) -> str
     """
     Will format an adequately formatted numbers-only CEP string,

test_patch: diff --git a/tests/test_cep.py b/tests/test_cep.py
index a2a2eca..56b12a6 100644
--- a/tests/test_cep.py
+++ b/tests/test_cep.py
@@ -13,11 +13,22 @@ from brutils.cep import (
     is_valid,
     format_cep,
     generate,
+    remove_symbols,
 )
 from unittest import TestCase, main
 
 
 class CEP(TestCase):
+    def test_remove_symbols(self):
+        assert remove_symbols("00000000") == "00000000"
+        assert remove_symbols("01310-200") == "01310200"
+        assert remove_symbols("01..310.-200.-") == "01310200"
+        assert remove_symbols("abc01310200*!*&#") == "abc01310200*!*&#"
+        assert (
+            remove_symbols("ab.c1.--.3-102.-0-.0-.*.-!*&#") == "abc1310200*!*&#"
+        )
+        assert remove_symbols("...---...") == ""
+
     def test_format_cep(self):
         with patch("brutils.cep.is_valid", return_value=True) as mock_is_valid:
             # When cep is_valid, returns formatted cep