From 1beaa1f1d655b8c55f69742f9d4407777e761fcf Mon Sep 17 00:00:00 2001 From: Carloshbfreire Date: Thu, 11 Aug 2022 14:33:59 -0300 Subject: [PATCH 01/17] =?UTF-8?q?Adicionada=20informa=C3=A7=C3=A3o=20sobre?= =?UTF-8?q?=20contribui=C3=A7=C3=A3o=20a=20projetos=20de=20c=C3=B3digo=20a?= =?UTF-8?q?bertos.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 676c14d7f..d6a5adaff 100644 --- a/README.md +++ b/README.md @@ -32,4 +32,5 @@ Tópicos a serem abordados: 3. Pip 4. Mock 5. Pipenv - \ No newline at end of file + +Revisando aula sobre Fork. \ No newline at end of file From 2b375615ede88a3ddd0e07c831fa8e6cfdf2a61c Mon Sep 17 00:00:00 2001 From: Carloshbfreire Date: Thu, 11 Aug 2022 15:02:00 -0300 Subject: [PATCH 02/17] Inserido a melhoria para o curos no Readme Carlos. close #724 --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d6a5adaff..aa4572619 100644 --- a/README.md +++ b/README.md @@ -33,4 +33,6 @@ Tópicos a serem abordados: 4. Mock 5. Pipenv -Revisando aula sobre Fork. \ No newline at end of file +Revisando aula sobre Fork. + +Link do Curso [Python pro](https://pythonpro.com.br/) \ No newline at end of file From 1381d9919327746f7fd3711f5c037af3a5bc1c21 Mon Sep 17 00:00:00 2001 From: Carloshbfreire Date: Thu, 18 Aug 2022 19:00:01 -0300 Subject: [PATCH 03/17] Suportada python 3 Carlinhos --- README.md | 2 +- libpythonpro/__init__.py | 1 - libpythonpro/github_api.py | 13 ----- libpythonpro/spam/__init__.py | 0 libpythonpro/spam/db.py | 31 ------------ libpythonpro/spam/enviador_de_email.py | 9 ---- libpythonpro/spam/main.py | 13 ----- libpythonpro/spam/modelos.py | 5 -- libpythonpro/tests/__init__.py | 0 libpythonpro/tests/test_exemplo.py | 2 - libpythonpro/tests/test_spam/__init__.py | 0 libpythonpro/tests/test_spam/conftest.py | 20 -------- .../tests/test_spam/test_enviador_de_email.py | 38 -------------- .../test_envio_para_base_de_usuarios.py | 49 ------------------- .../tests/test_spam/test_github_api.py | 28 ----------- libpythonpro/tests/test_spam/test_usuarios.py | 17 ------- 16 files changed, 1 insertion(+), 227 deletions(-) delete mode 100644 libpythonpro/__init__.py delete mode 100644 libpythonpro/github_api.py delete mode 100644 libpythonpro/spam/__init__.py delete mode 100644 libpythonpro/spam/db.py delete mode 100644 libpythonpro/spam/enviador_de_email.py delete mode 100644 libpythonpro/spam/main.py delete mode 100644 libpythonpro/spam/modelos.py delete mode 100644 libpythonpro/tests/__init__.py delete mode 100644 libpythonpro/tests/test_exemplo.py delete mode 100644 libpythonpro/tests/test_spam/__init__.py delete mode 100644 libpythonpro/tests/test_spam/conftest.py delete mode 100644 libpythonpro/tests/test_spam/test_enviador_de_email.py delete mode 100644 libpythonpro/tests/test_spam/test_envio_para_base_de_usuarios.py delete mode 100644 libpythonpro/tests/test_spam/test_github_api.py delete mode 100644 libpythonpro/tests/test_spam/test_usuarios.py diff --git a/README.md b/README.md index aa4572619..4458e74f9 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Link para o curso [Python Pro](https://www.python.pro.br/) [![Python 3](https://pyup.io/repos/github/pythonprobr/libpythonpro/python-3-shield.svg)](https://pyup.io/repos/github/pythonprobr/libpythonpro/) [![codecov](https://codecov.io/gh/pythonprobr/libpythonpro/branch/master/graph/badge.svg)](https://codecov.io/gh/pythonprobr/libpythonpro) -Suportada versão 3 de Python +Suportada versão 3 de Python Carlinhos Para instalar: diff --git a/libpythonpro/__init__.py b/libpythonpro/__init__.py deleted file mode 100644 index b650ceb08..000000000 --- a/libpythonpro/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__version__ = '0.2' diff --git a/libpythonpro/github_api.py b/libpythonpro/github_api.py deleted file mode 100644 index 8b0fbafb9..000000000 --- a/libpythonpro/github_api.py +++ /dev/null @@ -1,13 +0,0 @@ -import requests - - -def buscar_avatar(usuario): - """ - Busca o avatar de um usuário no Github - - :param usuario: str com o nome de usuário no github - :return: str com o link do avatar - """ - url = f'https://api.github.com/users/{usuario}' - resp = requests.get(url) - return resp.json()['avatar_url'] diff --git a/libpythonpro/spam/__init__.py b/libpythonpro/spam/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/libpythonpro/spam/db.py b/libpythonpro/spam/db.py deleted file mode 100644 index ce90ca60b..000000000 --- a/libpythonpro/spam/db.py +++ /dev/null @@ -1,31 +0,0 @@ -from time import sleep - - -class Sessao: - contador = 0 - usuarios = [] - - def salvar(self, usuario): - Sessao.contador += 1 - usuario.id = Sessao.contador - self.usuarios.append(usuario) - - def listar(self): - return self.usuarios - - def roll_back(self): - self.usuarios.clear() - - def fechar(self): - pass - - -class Conexao: - def __init__(self): - sleep(1) - - def gerar_sessao(self): - return Sessao() - - def fechar(self): - pass diff --git a/libpythonpro/spam/enviador_de_email.py b/libpythonpro/spam/enviador_de_email.py deleted file mode 100644 index fa0952223..000000000 --- a/libpythonpro/spam/enviador_de_email.py +++ /dev/null @@ -1,9 +0,0 @@ -class Enviador: - def enviar(self, remetente, destinatario, assunto, corpo): - if '@' not in remetente: - raise EmailInvalido(f'Email de remetente inválido: {remetente}') - return remetente - - -class EmailInvalido(Exception): - pass diff --git a/libpythonpro/spam/main.py b/libpythonpro/spam/main.py deleted file mode 100644 index f81821ae4..000000000 --- a/libpythonpro/spam/main.py +++ /dev/null @@ -1,13 +0,0 @@ -class EnviadorDeSpam: - def __init__(self, sessao, enviador): - self.sessao = sessao - self.enviador = enviador - - def enviar_emails(self, remetente, assunto, corpo): - for usuario in self.sessao.listar(): - self.enviador.enviar( - remetente, - usuario.email, - assunto, - corpo - ) diff --git a/libpythonpro/spam/modelos.py b/libpythonpro/spam/modelos.py deleted file mode 100644 index 093b35a2a..000000000 --- a/libpythonpro/spam/modelos.py +++ /dev/null @@ -1,5 +0,0 @@ -class Usuario: - def __init__(self, nome, email): - self.email = email - self.nome = nome - self.id = None diff --git a/libpythonpro/tests/__init__.py b/libpythonpro/tests/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/libpythonpro/tests/test_exemplo.py b/libpythonpro/tests/test_exemplo.py deleted file mode 100644 index 78cd50236..000000000 --- a/libpythonpro/tests/test_exemplo.py +++ /dev/null @@ -1,2 +0,0 @@ -def test_int(): - assert 1 == 1 diff --git a/libpythonpro/tests/test_spam/__init__.py b/libpythonpro/tests/test_spam/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/libpythonpro/tests/test_spam/conftest.py b/libpythonpro/tests/test_spam/conftest.py deleted file mode 100644 index a16f3970a..000000000 --- a/libpythonpro/tests/test_spam/conftest.py +++ /dev/null @@ -1,20 +0,0 @@ -import pytest - -from libpythonpro.spam.db import Conexao - - -@pytest.fixture(scope='session') -def conexao(): - # Setup - conexao_obj = Conexao() - yield conexao_obj - # Tear Down - conexao_obj.fechar() - - -@pytest.fixture -def sessao(conexao): - sessao_obj = conexao.gerar_sessao() - yield sessao_obj - sessao_obj.roll_back() - sessao_obj.fechar() diff --git a/libpythonpro/tests/test_spam/test_enviador_de_email.py b/libpythonpro/tests/test_spam/test_enviador_de_email.py deleted file mode 100644 index c72a0bbe9..000000000 --- a/libpythonpro/tests/test_spam/test_enviador_de_email.py +++ /dev/null @@ -1,38 +0,0 @@ -import pytest - -from libpythonpro.spam.enviador_de_email import EmailInvalido, Enviador - - -def test_criar_enviador_de_email(): - enviador = Enviador() - assert enviador is not None - - -@pytest.mark.parametrize( - 'remetente', - ['foo@bar.com.br', 'renzo@python.pro.br'] -) -def test_remetente(remetente): - enviador = Enviador() - resultado = enviador.enviar( - remetente, - 'luciano@python.pro.br', - 'Cursos Python Pro', - 'Primeira turma Guido Von Rossum aberta.' - ) - assert remetente in resultado - - -@pytest.mark.parametrize( - 'remetente', - ['', 'renzo'] -) -def test_remetente_invalido(remetente): - enviador = Enviador() - with pytest.raises(EmailInvalido): - enviador.enviar( - remetente, - 'luciano@python.pro.br', - 'Cursos Python Pro', - 'Primeira turma Guido Von Rossum aberta.' - ) diff --git a/libpythonpro/tests/test_spam/test_envio_para_base_de_usuarios.py b/libpythonpro/tests/test_spam/test_envio_para_base_de_usuarios.py deleted file mode 100644 index d2db43893..000000000 --- a/libpythonpro/tests/test_spam/test_envio_para_base_de_usuarios.py +++ /dev/null @@ -1,49 +0,0 @@ -from unittest.mock import Mock - -import pytest - -from libpythonpro.spam.main import EnviadorDeSpam -from libpythonpro.spam.modelos import Usuario - - -@pytest.mark.parametrize( - 'usuarios', - [ - [ - Usuario(nome='Renzo', email='renzo@python.pro.br'), - Usuario(nome='Luciano', email='renzo@python.pro.br') - ], - [ - Usuario(nome='Renzo', email='renzo@python.pro.br') - ] - ] -) -def test_qde_de_spam(sessao, usuarios): - for usuario in usuarios: - sessao.salvar(usuario) - enviador = Mock() - enviador_de_spam = EnviadorDeSpam(sessao, enviador) - enviador_de_spam.enviar_emails( - 'renzo@python.pro.br', - 'Curso Python Pro', - 'Confira os módulos fantásticos' - ) - assert len(usuarios) == enviador.enviar.call_count - - -def test_parametros_de_spam(sessao): - usuario = Usuario(nome='Renzo', email='renzo@python.pro.br') - sessao.salvar(usuario) - enviador = Mock() - enviador_de_spam = EnviadorDeSpam(sessao, enviador) - enviador_de_spam.enviar_emails( - 'luciano@python.pro.br', - 'Curso Python Pro', - 'Confira os módulos fantásticos' - ) - enviador.enviar.assert_called_once_with( - 'luciano@python.pro.br', - 'renzo@python.pro.br', - 'Curso Python Pro', - 'Confira os módulos fantásticos' - ) diff --git a/libpythonpro/tests/test_spam/test_github_api.py b/libpythonpro/tests/test_spam/test_github_api.py deleted file mode 100644 index 21ce9c5d0..000000000 --- a/libpythonpro/tests/test_spam/test_github_api.py +++ /dev/null @@ -1,28 +0,0 @@ -from unittest.mock import Mock - -import pytest - -from libpythonpro import github_api - - -@pytest.fixture -def avatar_url(mocker): - resp_mock = Mock() - url = 'https://avatars3.githubusercontent.com/u/402714?v=4' - resp_mock.json.return_value = { - 'login': 'renzo', 'id': 402714, - 'avatar_url': url, - } - get_mock = mocker.patch('libpythonpro.github_api.requests.get') - get_mock.return_value = resp_mock - return url - - -def test_buscar_avatar(avatar_url): - url = github_api.buscar_avatar('renzo') - assert avatar_url == url - - -def test_buscar_avatar_integracao(): - url = github_api.buscar_avatar('renzon') - assert 'https://avatars3.githubusercontent.com/u/3457115?v=4' == url diff --git a/libpythonpro/tests/test_spam/test_usuarios.py b/libpythonpro/tests/test_spam/test_usuarios.py deleted file mode 100644 index 09b523445..000000000 --- a/libpythonpro/tests/test_spam/test_usuarios.py +++ /dev/null @@ -1,17 +0,0 @@ -from libpythonpro.spam.modelos import Usuario - - -def test_salvar_usuario(sessao): - usuario = Usuario(nome='Renzo', email='renzo@python.pro.br') - sessao.salvar(usuario) - assert isinstance(usuario.id, int) - - -def test_listar_usuarios(sessao): - usuarios = [ - Usuario(nome='Renzo', email='renzo@python.pro.br'), - Usuario(nome='Luciano', email='renzo@python.pro.br') - ] - for usuario in usuarios: - sessao.salvar(usuario) - assert usuarios == sessao.listar() From b424cd73b2434a2c68af6566a0b00f51e52fccb2 Mon Sep 17 00:00:00 2001 From: Carloshbfreire Date: Mon, 22 Aug 2022 16:21:35 -0300 Subject: [PATCH 04/17] =?UTF-8?q?Adicionada=20flake8=20como=20depend=C3=AA?= =?UTF-8?q?ncia?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit close #12 --- Libpythonpro/__init__.py | 0 Libpythonpro/github_api.py | 16 ++++++++++++++++ README.md | 7 ++++--- 3 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 Libpythonpro/__init__.py create mode 100644 Libpythonpro/github_api.py diff --git a/Libpythonpro/__init__.py b/Libpythonpro/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Libpythonpro/github_api.py b/Libpythonpro/github_api.py new file mode 100644 index 000000000..abc64ed4d --- /dev/null +++ b/Libpythonpro/github_api.py @@ -0,0 +1,16 @@ +import requests + + +def buscar_avatar(usuario): + """ + Busca o avatar de um usuário no Github + :Param usuário: str com o nome usuário no github + :return: str com o link do avatar + """ + url = f'https://api.github.com/users/{usuario}' + resp = requests.get(url) + return resp.json()['avatar_url'] + + +if __name__ == '__main__': + print(buscar_avatar('Carloshbfreire')) diff --git a/README.md b/README.md index 4458e74f9..b7a10cea4 100644 --- a/README.md +++ b/README.md @@ -16,14 +16,15 @@ Suportada versão 3 de Python Carlinhos Para instalar: ```console -pip install pipenv -pipenv install --dev +python3 -m venv .venv +source .venv/bin/activete +pip install -r requirements-dev.txt ``` Para conferir qualidade de código: ```console -pipenv run flake8 +flake8 ``` Tópicos a serem abordados: From e4d778c4c1565a0f7157ca196e5586809123f3d0 Mon Sep 17 00:00:00 2001 From: Carloshbfreire Date: Mon, 29 Aug 2022 15:57:54 -0300 Subject: [PATCH 05/17] Criado setup.py, para release 0.1 close #18 --- .travis.yml | 12 ++++-------- Libpythonpro/__init__.py | 1 + README.md | 3 ++- setup.py | 6 +++--- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6694375b7..09bc50a74 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,7 @@ language: python python: - - 3.7 -install: - - pip install -q pipenv codecov - - pipenv sync --dev -script: + - 3.10 + + install: + - pip install -q -r requirements-dev.txt - flake8 - - pytest libpythonpro --cov=libpythonpro -after_success: - - codecov \ No newline at end of file diff --git a/Libpythonpro/__init__.py b/Libpythonpro/__init__.py index e69de29bb..5e3048b21 100644 --- a/Libpythonpro/__init__.py +++ b/Libpythonpro/__init__.py @@ -0,0 +1 @@ +__version__ = '0.1' \ No newline at end of file diff --git a/README.md b/README.md index b7a10cea4..9971f75e1 100644 --- a/README.md +++ b/README.md @@ -11,13 +11,14 @@ Link para o curso [Python Pro](https://www.python.pro.br/) [![Python 3](https://pyup.io/repos/github/pythonprobr/libpythonpro/python-3-shield.svg)](https://pyup.io/repos/github/pythonprobr/libpythonpro/) [![codecov](https://codecov.io/gh/pythonprobr/libpythonpro/branch/master/graph/badge.svg)](https://codecov.io/gh/pythonprobr/libpythonpro) + Suportada versão 3 de Python Carlinhos Para instalar: ```console python3 -m venv .venv -source .venv/bin/activete +source .venv/bin/activate pip install -r requirements-dev.txt ``` diff --git a/setup.py b/setup.py index 1fea97a65..895662a98 100644 --- a/setup.py +++ b/setup.py @@ -101,7 +101,7 @@ def find_package_data( return out -PACKAGE = "libpythonpro" +PACKAGE = "Libpythonpro" NAME = PACKAGE DESCRIPTION = "Módulo para exemplificar construção de projetos Python no curso PyTools" AUTHOR = "Renzo Nuccitelli" @@ -117,7 +117,7 @@ def find_package_data( long_description_content_type='text/markdown', author=AUTHOR, author_email=AUTHOR_EMAIL, - license="GNU AFFERO GENERAL PUBLIC LICENSE", + license=read('LICENSE'), url=URL, packages=find_packages(exclude=["tests.*", "tests"]), package_data=find_package_data(PACKAGE, only_in_packages=False), @@ -128,7 +128,7 @@ def find_package_data( "License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)", "Operating System :: OS Independent", "Programming Language :: Python", - "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.10", "Framework :: Pytest", ], install_requires=[ From 3a4e36bccde16c1ed6bb1409ae002e42f0cff49d Mon Sep 17 00:00:00 2001 From: Carloshbfreire Date: Thu, 8 Sep 2022 15:51:27 -0300 Subject: [PATCH 06/17] Inserido teste com pytest close #21 --- .travis.yml | 1 + Libpythonpro/__init__.py | 2 +- Libpythonpro/tests/__init__.py | 0 Libpythonpro/tests/test_exemplo.py | 2 ++ setup.py | 2 +- 5 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 Libpythonpro/tests/__init__.py create mode 100644 Libpythonpro/tests/test_exemplo.py diff --git a/.travis.yml b/.travis.yml index 09bc50a74..e9a9a9bef 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,3 +5,4 @@ python: install: - pip install -q -r requirements-dev.txt - flake8 + - pytest Libpythonpro \ No newline at end of file diff --git a/Libpythonpro/__init__.py b/Libpythonpro/__init__.py index 5e3048b21..edcfd0dd7 100644 --- a/Libpythonpro/__init__.py +++ b/Libpythonpro/__init__.py @@ -1 +1 @@ -__version__ = '0.1' \ No newline at end of file +__version__ = '0.2' \ No newline at end of file diff --git a/Libpythonpro/tests/__init__.py b/Libpythonpro/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Libpythonpro/tests/test_exemplo.py b/Libpythonpro/tests/test_exemplo.py new file mode 100644 index 000000000..41c6a2761 --- /dev/null +++ b/Libpythonpro/tests/test_exemplo.py @@ -0,0 +1,2 @@ +def test_int(): + assert 1 == 0 \ No newline at end of file diff --git a/setup.py b/setup.py index 895662a98..f4c5b0992 100644 --- a/setup.py +++ b/setup.py @@ -117,7 +117,7 @@ def find_package_data( long_description_content_type='text/markdown', author=AUTHOR, author_email=AUTHOR_EMAIL, - license=read('LICENSE'), + license=read('GNU AFFERO GENERAL PUBLIC LICENSE'), url=URL, packages=find_packages(exclude=["tests.*", "tests"]), package_data=find_package_data(PACKAGE, only_in_packages=False), From 2f75febfc0dfe09476c11c41c97457824cebe473 Mon Sep 17 00:00:00 2001 From: Carloshbfreire Date: Fri, 9 Sep 2022 18:49:12 -0300 Subject: [PATCH 07/17] Inserido teste com pytest close #731 --- .travis.yml | 2 +- Libpythonpro/tests/test_exemplo.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index e9a9a9bef..70948b69b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,4 +5,4 @@ python: install: - pip install -q -r requirements-dev.txt - flake8 - - pytest Libpythonpro \ No newline at end of file + - pytest Libpythonpro Carlos \ No newline at end of file diff --git a/Libpythonpro/tests/test_exemplo.py b/Libpythonpro/tests/test_exemplo.py index 41c6a2761..470a3111a 100644 --- a/Libpythonpro/tests/test_exemplo.py +++ b/Libpythonpro/tests/test_exemplo.py @@ -1,2 +1,2 @@ def test_int(): - assert 1 == 0 \ No newline at end of file + assert 1 == 1 \ No newline at end of file From ac4327e10af880ec8c0df19504b816155bf35b84 Mon Sep 17 00:00:00 2001 From: Carloshbfreire Date: Sun, 11 Sep 2022 15:03:42 -0300 Subject: [PATCH 08/17] Configurado Travis CI close #733 --- .travis.yml | 2 +- README.md | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 70948b69b..0eb430124 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: python python: - 3.10 - + - 2.7 install: - pip install -q -r requirements-dev.txt - flake8 diff --git a/README.md b/README.md index 9971f75e1..3deff37c6 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,8 @@ Nesse curso é ensinado como contribuir com projetos de código aberto Link para o curso [Python Pro](https://www.python.pro.br/) -[![Build Status](https://travis-ci.org/pythonprobr/libpythonpro.svg?branch=master)](https://travis-ci.org/pythonprobr/libpythonpro) +[![Build Status](https://app.travis-ci.com/Carloshbfreire/libpythonpro-1.svg?branch=master)](https://app.travis-ci.com/Carloshbfreire/libpythonpro-1) + [![Updates](https://pyup.io/repos/github/pythonprobr/libpythonpro/shield.svg)](https://pyup.io/repos/github/pythonprobr/libpythonpro/) [![Python 3](https://pyup.io/repos/github/pythonprobr/libpythonpro/python-3-shield.svg)](https://pyup.io/repos/github/pythonprobr/libpythonpro/) [![codecov](https://codecov.io/gh/pythonprobr/libpythonpro/branch/master/graph/badge.svg)](https://codecov.io/gh/pythonprobr/libpythonpro) From 570c012951493c4e54417e359359f47438416e9c Mon Sep 17 00:00:00 2001 From: Carloshbfreire Date: Mon, 12 Sep 2022 13:58:54 -0300 Subject: [PATCH 09/17] =?UTF-8?q?Acrecentada=20cobertura=20de=20c=C3=B3dig?= =?UTF-8?q?o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit close #735 --- .travis.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0eb430124..829dfd719 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,8 @@ python: - 3.10 - 2.7 install: - - pip install -q -r requirements-dev.txt + - pip install -q -r requirements-dev.txt codecov - flake8 - - pytest Libpythonpro Carlos \ No newline at end of file + - pytest Libpythonpro --cov=libpythonpro-1 +after_success: + - codecov \ No newline at end of file From 23a0cff69bb839a6af16b83f8dc1c3de55d74360 Mon Sep 17 00:00:00 2001 From: Carloshbfreire Date: Wed, 21 Sep 2022 11:43:55 -0300 Subject: [PATCH 10/17] =?UTF-8?q?Aula=20de=20implementa=C3=A7=C3=A3o=20de?= =?UTF-8?q?=20conex=C3=A3o,=20Sess=C3=A3o=20e=20usu=C3=A1rio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Libpythonpro/spam/__init__.py | 0 Libpythonpro/spam/db.py | 25 ++++++++++++ Libpythonpro/spam/modelos.py | 4 ++ Libpythonpro/spam/test_spam/__init__.py | 0 .../spam/test_spam/enviador_de_email.py | 9 +++++ .../spam/test_spam/testes_usuarios.py | 25 ++++++++++++ Libpythonpro/tests/test_spam/__init__.py | 0 .../tests/test_spam/test_enviador_de_email.py | 38 +++++++++++++++++++ 8 files changed, 101 insertions(+) create mode 100644 Libpythonpro/spam/__init__.py create mode 100644 Libpythonpro/spam/db.py create mode 100644 Libpythonpro/spam/modelos.py create mode 100644 Libpythonpro/spam/test_spam/__init__.py create mode 100644 Libpythonpro/spam/test_spam/enviador_de_email.py create mode 100644 Libpythonpro/spam/test_spam/testes_usuarios.py create mode 100644 Libpythonpro/tests/test_spam/__init__.py create mode 100644 Libpythonpro/tests/test_spam/test_enviador_de_email.py diff --git a/Libpythonpro/spam/__init__.py b/Libpythonpro/spam/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Libpythonpro/spam/db.py b/Libpythonpro/spam/db.py new file mode 100644 index 000000000..3a0f55656 --- /dev/null +++ b/Libpythonpro/spam/db.py @@ -0,0 +1,25 @@ +class Sessao: + contador = 0 + usuarios = [] + + def salvar(self, usuario): + Sessao.contador += 1 + usuario.id = Sessao.contador + self.usuarios.append(usuario) + + def listar(self): + return self.usuarios + + def roll_back(self): + pass + + def fechar(self): + pass + + +class Conexao: + def gerar_sessao(self): + return Sessao() + + def fechar(self): + pass diff --git a/Libpythonpro/spam/modelos.py b/Libpythonpro/spam/modelos.py new file mode 100644 index 000000000..60cb0068e --- /dev/null +++ b/Libpythonpro/spam/modelos.py @@ -0,0 +1,4 @@ +class Usuario: + def __init__(self, nome): + self.nome = nome + self.id = None diff --git a/Libpythonpro/spam/test_spam/__init__.py b/Libpythonpro/spam/test_spam/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Libpythonpro/spam/test_spam/enviador_de_email.py b/Libpythonpro/spam/test_spam/enviador_de_email.py new file mode 100644 index 000000000..add1ac3b4 --- /dev/null +++ b/Libpythonpro/spam/test_spam/enviador_de_email.py @@ -0,0 +1,9 @@ +class Enviador: + def enviar(self, remetente, destinatário, assunto, corpo): + if '@' not in remetente: + raise EmailInvalido(f'Email de Remetente Inválido:{remetente}') + return remetente + + +class EmailInvalido(Exception): + pass diff --git a/Libpythonpro/spam/test_spam/testes_usuarios.py b/Libpythonpro/spam/test_spam/testes_usuarios.py new file mode 100644 index 000000000..ff680f87a --- /dev/null +++ b/Libpythonpro/spam/test_spam/testes_usuarios.py @@ -0,0 +1,25 @@ +from Libpythonpro.spam.db import Conexao +from Libpythonpro.spam.modelos import Usuario + + +def test_salvar_usuario(): + conexao = Conexao() + sessao = conexao.gerar_sessao() + usuario= Usuario(nome='Carlos') + sessao.salvar(usuario) + assert isinstance(usuario.id, int) + sessao.roll_back() + sessao.fechar() + conexao.fechar() + + +def test_listar_usuario(): + conexao = Conexao() + sessao = conexao.gerar_sessao() + usuarios = [Usuario(nome='Carlos'), Usuario(nome='Givani')] + for usuario in usuarios: + sessao.salvar(usuario) + assert usuarios == sessao.listar() + sessao.roll_back() + sessao.fechar() + conexao.fechar() \ No newline at end of file diff --git a/Libpythonpro/tests/test_spam/__init__.py b/Libpythonpro/tests/test_spam/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/Libpythonpro/tests/test_spam/test_enviador_de_email.py b/Libpythonpro/tests/test_spam/test_enviador_de_email.py new file mode 100644 index 000000000..7567eff71 --- /dev/null +++ b/Libpythonpro/tests/test_spam/test_enviador_de_email.py @@ -0,0 +1,38 @@ +import pytest + +from Libpythonpro.spam.test_spam.enviador_de_email import Enviador, EmailInvalido + + +def test_criar_enviador_de_email(): + enviador= Enviador() + assert enviador is not None + +@pytest.mark.parametrize( + 'destinatario', + ['foo@bar.com.br','renzo@python.pro.br'] +) +def test_remetente(destinatario): + enviador = Enviador() + destinatario + resultado = enviador.enviar( + destinatario, + 'luciano@python.pro.br', + 'Cursos Python Pro', + 'Primeira Turma Guido Von Rossum aberta.') + assert destinatario in resultado + + +@pytest.mark.parametrize( + 'remetente', + ['','renzo'] +) +def test_remetente_invalido(remetente): + enviador = Enviador() + with pytest.raises(EmailInvalido): + enviador.enviar( + remetente, + 'luciano@python.pro.br', + 'Cursos Python Pro', + 'Primeira Turma Guido Von Rossum aberta.' + ) + From a23a6e16ccc4533e9bfd81fcedcf294d24a78e23 Mon Sep 17 00:00:00 2001 From: Carloshbfreire Date: Mon, 26 Sep 2022 16:23:02 -0300 Subject: [PATCH 11/17] =?UTF-8?q?Terminado=20o=20M=C3=B3dulo=20Pytest=20Fi?= =?UTF-8?q?xtures=20do=20Pytools?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Libpythonpro/spam/db.py | 22 -------- Libpythonpro/spam/main.py | 8 +++ .../spam/test_spam/testes_usuarios.py | 18 ++----- Libpythonpro/tests/test_spam/conftest.py | 51 +++++++++++++++++++ .../test_envio_para_base_de_usuarios.py | 11 ++++ 5 files changed, 75 insertions(+), 35 deletions(-) create mode 100644 Libpythonpro/spam/main.py create mode 100644 Libpythonpro/tests/test_spam/conftest.py create mode 100644 Libpythonpro/tests/test_spam/test_envio_para_base_de_usuarios.py diff --git a/Libpythonpro/spam/db.py b/Libpythonpro/spam/db.py index 3a0f55656..b28b04f64 100644 --- a/Libpythonpro/spam/db.py +++ b/Libpythonpro/spam/db.py @@ -1,25 +1,3 @@ -class Sessao: - contador = 0 - usuarios = [] - def salvar(self, usuario): - Sessao.contador += 1 - usuario.id = Sessao.contador - self.usuarios.append(usuario) - def listar(self): - return self.usuarios - def roll_back(self): - pass - - def fechar(self): - pass - - -class Conexao: - def gerar_sessao(self): - return Sessao() - - def fechar(self): - pass diff --git a/Libpythonpro/spam/main.py b/Libpythonpro/spam/main.py new file mode 100644 index 000000000..fd0a64903 --- /dev/null +++ b/Libpythonpro/spam/main.py @@ -0,0 +1,8 @@ +class EnviadorDeSpam: + def __init__(self, sessao, enviador): + self.enviador = enviador + self.sessao = sessao + + def enviar_emails(self, remetente, assunto, corpo): + pass + diff --git a/Libpythonpro/spam/test_spam/testes_usuarios.py b/Libpythonpro/spam/test_spam/testes_usuarios.py index ff680f87a..660342142 100644 --- a/Libpythonpro/spam/test_spam/testes_usuarios.py +++ b/Libpythonpro/spam/test_spam/testes_usuarios.py @@ -1,25 +1,17 @@ -from Libpythonpro.spam.db import Conexao from Libpythonpro.spam.modelos import Usuario -def test_salvar_usuario(): - conexao = Conexao() - sessao = conexao.gerar_sessao() +def test_salvar_usuario(sessao): usuario= Usuario(nome='Carlos') sessao.salvar(usuario) assert isinstance(usuario.id, int) - sessao.roll_back() - sessao.fechar() - conexao.fechar() -def test_listar_usuario(): - conexao = Conexao() - sessao = conexao.gerar_sessao() +def test_listar_usuario(sessao): usuarios = [Usuario(nome='Carlos'), Usuario(nome='Givani')] for usuario in usuarios: sessao.salvar(usuario) assert usuarios == sessao.listar() - sessao.roll_back() - sessao.fechar() - conexao.fechar() \ No newline at end of file + + + diff --git a/Libpythonpro/tests/test_spam/conftest.py b/Libpythonpro/tests/test_spam/conftest.py new file mode 100644 index 000000000..bbb25c720 --- /dev/null +++ b/Libpythonpro/tests/test_spam/conftest.py @@ -0,0 +1,51 @@ +from time import sleep + +import pytest + + +class Sessao: + contador = 0 + usuarios = [] + + def salvar(self, usuario): + Sessao.contador += 1 + usuario.id = Sessao.contador + self.usuarios.append(usuario) + + def listar(self): + return self.usuarios + + def roll_back(self): + self.usuarios.clear() + + def fechar(self): + pass + + +class Conexao: + + def __init__(self): + sleep(1) + + def gerar_sessao(self): + return Sessao() + + def fechar(self): + pass + + +@pytest.fixture(scope= 'session') +def conexao(): + #Setup + conexao_obj = Conexao() + yield conexao_obj + #Tear Down + conexao_obj.fechar() + + +@pytest.fixture +def sessao(conexao): + sessao_obj = conexao.gerar_sessao() + yield sessao_obj + sessao_obj.roll_back() + sessao_obj.fechar() diff --git a/Libpythonpro/tests/test_spam/test_envio_para_base_de_usuarios.py b/Libpythonpro/tests/test_spam/test_envio_para_base_de_usuarios.py new file mode 100644 index 000000000..9978480d5 --- /dev/null +++ b/Libpythonpro/tests/test_spam/test_envio_para_base_de_usuarios.py @@ -0,0 +1,11 @@ +from Libpythonpro.spam.main import EnviadorDeSpam +from Libpythonpro.spam.test_spam.enviador_de_email import Enviador + + +def test_envio_de_spam(sessao): + enviador_de_spam= EnviadorDeSpam(sessao, Enviador()) + enviador_de_spam.enviar_emails( + 'carhb@outlook.com', + 'Curso Pythonpro', + 'Confira os módulos fantásticos' + ) From ff62408a2508f8b3b9b2954e362f39b84d83d4af Mon Sep 17 00:00:00 2001 From: Carloshbfreire Date: Tue, 27 Sep 2022 16:51:00 -0300 Subject: [PATCH 12/17] =?UTF-8?q?Terminado=20o=20Exercicio=20de=20produ?= =?UTF-8?q?=C3=A7ao=20de=20c=C3=B3digo=20testavel.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Libpythonpro/spam/db.py | 22 ++++++++++++++++ Libpythonpro/spam/main.py | 9 ++++++- Libpythonpro/spam/modelos.py | 3 ++- .../spam/test_spam/enviador_de_email.py | 4 +++ .../spam/test_spam/testes_usuarios.py | 7 +++-- Libpythonpro/tests/test_spam/conftest.py | 15 ++++++++--- .../test_envio_para_base_de_usuarios.py | 26 ++++++++++++++++--- 7 files changed, 76 insertions(+), 10 deletions(-) diff --git a/Libpythonpro/spam/db.py b/Libpythonpro/spam/db.py index b28b04f64..3a0f55656 100644 --- a/Libpythonpro/spam/db.py +++ b/Libpythonpro/spam/db.py @@ -1,3 +1,25 @@ +class Sessao: + contador = 0 + usuarios = [] + def salvar(self, usuario): + Sessao.contador += 1 + usuario.id = Sessao.contador + self.usuarios.append(usuario) + def listar(self): + return self.usuarios + def roll_back(self): + pass + + def fechar(self): + pass + + +class Conexao: + def gerar_sessao(self): + return Sessao() + + def fechar(self): + pass diff --git a/Libpythonpro/spam/main.py b/Libpythonpro/spam/main.py index fd0a64903..3d45e0b07 100644 --- a/Libpythonpro/spam/main.py +++ b/Libpythonpro/spam/main.py @@ -4,5 +4,12 @@ def __init__(self, sessao, enviador): self.sessao = sessao def enviar_emails(self, remetente, assunto, corpo): - pass + for usuario in self.sessao.listar(): + self.enviador.enviar( + remetente, + usuario.email, + assunto, + corpo + ) + diff --git a/Libpythonpro/spam/modelos.py b/Libpythonpro/spam/modelos.py index 60cb0068e..093b35a2a 100644 --- a/Libpythonpro/spam/modelos.py +++ b/Libpythonpro/spam/modelos.py @@ -1,4 +1,5 @@ class Usuario: - def __init__(self, nome): + def __init__(self, nome, email): + self.email = email self.nome = nome self.id = None diff --git a/Libpythonpro/spam/test_spam/enviador_de_email.py b/Libpythonpro/spam/test_spam/enviador_de_email.py index add1ac3b4..426b2bf13 100644 --- a/Libpythonpro/spam/test_spam/enviador_de_email.py +++ b/Libpythonpro/spam/test_spam/enviador_de_email.py @@ -1,7 +1,11 @@ class Enviador: + def __init__(self): + self.qtd_email_enviados = 0 + def enviar(self, remetente, destinatário, assunto, corpo): if '@' not in remetente: raise EmailInvalido(f'Email de Remetente Inválido:{remetente}') + self.qtd_email_enviados += 1 return remetente diff --git a/Libpythonpro/spam/test_spam/testes_usuarios.py b/Libpythonpro/spam/test_spam/testes_usuarios.py index 660342142..f13572d73 100644 --- a/Libpythonpro/spam/test_spam/testes_usuarios.py +++ b/Libpythonpro/spam/test_spam/testes_usuarios.py @@ -2,13 +2,16 @@ def test_salvar_usuario(sessao): - usuario= Usuario(nome='Carlos') + usuario= Usuario(nome='Carlos', email= 'carhb@outlook.com' ) sessao.salvar(usuario) assert isinstance(usuario.id, int) def test_listar_usuario(sessao): - usuarios = [Usuario(nome='Carlos'), Usuario(nome='Givani')] + usuarios = [ + Usuario(nome='Carlos', email='carhb@outlook.com'), + Usuario(nome='Givani', email='carhb@outlook.com') + ] for usuario in usuarios: sessao.salvar(usuario) assert usuarios == sessao.listar() diff --git a/Libpythonpro/tests/test_spam/conftest.py b/Libpythonpro/tests/test_spam/conftest.py index bbb25c720..494d6ed25 100644 --- a/Libpythonpro/tests/test_spam/conftest.py +++ b/Libpythonpro/tests/test_spam/conftest.py @@ -34,12 +34,12 @@ def fechar(self): pass -@pytest.fixture(scope= 'session') +@pytest.fixture(scope='session') def conexao(): - #Setup + # Setup conexao_obj = Conexao() yield conexao_obj - #Tear Down + # Tear Down conexao_obj.fechar() @@ -49,3 +49,12 @@ def sessao(conexao): yield sessao_obj sessao_obj.roll_back() sessao_obj.fechar() + + + + + + + + + diff --git a/Libpythonpro/tests/test_spam/test_envio_para_base_de_usuarios.py b/Libpythonpro/tests/test_spam/test_envio_para_base_de_usuarios.py index 9978480d5..e71334c04 100644 --- a/Libpythonpro/tests/test_spam/test_envio_para_base_de_usuarios.py +++ b/Libpythonpro/tests/test_spam/test_envio_para_base_de_usuarios.py @@ -1,11 +1,31 @@ +import pytest + from Libpythonpro.spam.main import EnviadorDeSpam +from Libpythonpro.spam.modelos import Usuario from Libpythonpro.spam.test_spam.enviador_de_email import Enviador - -def test_envio_de_spam(sessao): - enviador_de_spam= EnviadorDeSpam(sessao, Enviador()) +@pytest.mark.parametrize( + 'usuarios', + [ + [ + Usuario(nome='Carlos', email='carhb@outlook.com'), + Usuario(nome='Givani', email='carhb@outlook.com') + ], + [ + Usuario(nome='Carlos', email='carhb@outlook.com') + ] + ] +) +def test_qde_de_spam(sessao, usuarios): + for usuario in usuarios: + sessao.salvar(usuario) + enviador = Enviador() + enviador_de_spam= EnviadorDeSpam(sessao, enviador) enviador_de_spam.enviar_emails( 'carhb@outlook.com', 'Curso Pythonpro', 'Confira os módulos fantásticos' ) + assert len(usuarios) == enviador.qtd_email_enviados + + From 992fc186ec27a7898e81d8c43782c5b4b79dd61d Mon Sep 17 00:00:00 2001 From: Carloshbfreire Date: Wed, 28 Sep 2022 15:07:16 -0300 Subject: [PATCH 13/17] =?UTF-8?q?Terminado=20o=20Exercicio=20de=20Inje?= =?UTF-8?q?=C3=A7=C3=A3o=20de=20depend=C3=AAncia.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../spam/test_spam/enviador_de_email.py | 6 +-- .../test_envio_para_base_de_usuarios.py | 40 +++++++++++++++++-- .../test_spam/testes_usuarios.py | 0 3 files changed, 38 insertions(+), 8 deletions(-) rename Libpythonpro/{spam => tests}/test_spam/testes_usuarios.py (100%) diff --git a/Libpythonpro/spam/test_spam/enviador_de_email.py b/Libpythonpro/spam/test_spam/enviador_de_email.py index 426b2bf13..b500c4f27 100644 --- a/Libpythonpro/spam/test_spam/enviador_de_email.py +++ b/Libpythonpro/spam/test_spam/enviador_de_email.py @@ -1,11 +1,7 @@ class Enviador: - def __init__(self): - self.qtd_email_enviados = 0 - - def enviar(self, remetente, destinatário, assunto, corpo): + def enviar(self, remetente, destinatário, assunto, corpo): if '@' not in remetente: raise EmailInvalido(f'Email de Remetente Inválido:{remetente}') - self.qtd_email_enviados += 1 return remetente diff --git a/Libpythonpro/tests/test_spam/test_envio_para_base_de_usuarios.py b/Libpythonpro/tests/test_spam/test_envio_para_base_de_usuarios.py index e71334c04..690e86fac 100644 --- a/Libpythonpro/tests/test_spam/test_envio_para_base_de_usuarios.py +++ b/Libpythonpro/tests/test_spam/test_envio_para_base_de_usuarios.py @@ -4,22 +4,37 @@ from Libpythonpro.spam.modelos import Usuario from Libpythonpro.spam.test_spam.enviador_de_email import Enviador + +def test_envio_de_spam(sessao): + enviador_de_spam= EnviadorDeSpam(sessao, Enviador()) + + +class EnviadorMock(Enviador): + def __init__(self): + super().__init__() + self.qtd_email_enviados = 0 + self.parametros_de_envio = None + + def enviar(self, remetente, destinatário, assunto, corpo): + self.parametros_de_envio = (remetente, destinatário, assunto, corpo) + self.qtd_email_enviados += 1 + @pytest.mark.parametrize( 'usuarios', [ [ Usuario(nome='Carlos', email='carhb@outlook.com'), - Usuario(nome='Givani', email='carhb@outlook.com') + Usuario(nome='Givani', email='givanifcf@hotmail.com') ], [ Usuario(nome='Carlos', email='carhb@outlook.com') ] ] ) -def test_qde_de_spam(sessao, usuarios): +def test_qtd_de_spam(sessao, usuarios): for usuario in usuarios: sessao.salvar(usuario) - enviador = Enviador() + enviador = EnviadorMock() enviador_de_spam= EnviadorDeSpam(sessao, enviador) enviador_de_spam.enviar_emails( 'carhb@outlook.com', @@ -29,3 +44,22 @@ def test_qde_de_spam(sessao, usuarios): assert len(usuarios) == enviador.qtd_email_enviados +def test_parametros_de_spam(sessao): + usuario = Usuario(nome='Carlos', email='carhb@outlook.com') + sessao.salvar(usuario) + enviador = EnviadorMock() + enviador_de_spam= EnviadorDeSpam(sessao, enviador) + enviador_de_spam.enviar_emails( + 'givanifcf@hotmail.com', + 'Curso Pythonpro', + 'Confira os módulos fantásticos' + ) + assert enviador.parametros_de_envio ==( + 'givanifcf@hotmail.com', + 'carhb@outlook.com', + 'Curso Pythonpro', + 'Confira os módulos fantásticos' + ) + + + diff --git a/Libpythonpro/spam/test_spam/testes_usuarios.py b/Libpythonpro/tests/test_spam/testes_usuarios.py similarity index 100% rename from Libpythonpro/spam/test_spam/testes_usuarios.py rename to Libpythonpro/tests/test_spam/testes_usuarios.py From 8fc0fbda17f6fad0da14e5a671c37040fcdf672a Mon Sep 17 00:00:00 2001 From: Carloshbfreire Date: Thu, 29 Sep 2022 15:49:52 -0300 Subject: [PATCH 14/17] Terminado o Exercicio sobre o uso do Mock --- .../test_envio_para_base_de_usuarios.py | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/Libpythonpro/tests/test_spam/test_envio_para_base_de_usuarios.py b/Libpythonpro/tests/test_spam/test_envio_para_base_de_usuarios.py index 690e86fac..6eb8c09a9 100644 --- a/Libpythonpro/tests/test_spam/test_envio_para_base_de_usuarios.py +++ b/Libpythonpro/tests/test_spam/test_envio_para_base_de_usuarios.py @@ -1,3 +1,5 @@ +from unittest.mock import Mock + import pytest from Libpythonpro.spam.main import EnviadorDeSpam @@ -9,16 +11,6 @@ def test_envio_de_spam(sessao): enviador_de_spam= EnviadorDeSpam(sessao, Enviador()) -class EnviadorMock(Enviador): - def __init__(self): - super().__init__() - self.qtd_email_enviados = 0 - self.parametros_de_envio = None - - def enviar(self, remetente, destinatário, assunto, corpo): - self.parametros_de_envio = (remetente, destinatário, assunto, corpo) - self.qtd_email_enviados += 1 - @pytest.mark.parametrize( 'usuarios', [ @@ -34,27 +26,27 @@ def enviar(self, remetente, destinatário, assunto, corpo): def test_qtd_de_spam(sessao, usuarios): for usuario in usuarios: sessao.salvar(usuario) - enviador = EnviadorMock() + enviador = Mock() enviador_de_spam= EnviadorDeSpam(sessao, enviador) enviador_de_spam.enviar_emails( 'carhb@outlook.com', 'Curso Pythonpro', 'Confira os módulos fantásticos' ) - assert len(usuarios) == enviador.qtd_email_enviados + assert len(usuarios) == enviador.enviar.call_count def test_parametros_de_spam(sessao): usuario = Usuario(nome='Carlos', email='carhb@outlook.com') sessao.salvar(usuario) - enviador = EnviadorMock() + enviador = Mock() enviador_de_spam= EnviadorDeSpam(sessao, enviador) enviador_de_spam.enviar_emails( 'givanifcf@hotmail.com', 'Curso Pythonpro', 'Confira os módulos fantásticos' ) - assert enviador.parametros_de_envio ==( + enviador.enviar.assert_called_once_with( 'givanifcf@hotmail.com', 'carhb@outlook.com', 'Curso Pythonpro', From 8c4afe9fe72c4a11eaf4434f8b420c5eb7d73ad4 Mon Sep 17 00:00:00 2001 From: Carloshbfreire Date: Sat, 1 Oct 2022 14:48:10 -0300 Subject: [PATCH 15/17] =?UTF-8?q?Terminado=20o=20Exercicio=20de=20M=C3=B3d?= =?UTF-8?q?ulo=20como=20objeto?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Libpythonpro/github_api.py | 2 -- .../test_spam/test_envio_para_base_de_usuarios.py | 1 - Libpythonpro/tests/test_spam/test_github_api.py | 14 ++++++++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 Libpythonpro/tests/test_spam/test_github_api.py diff --git a/Libpythonpro/github_api.py b/Libpythonpro/github_api.py index abc64ed4d..f9926480a 100644 --- a/Libpythonpro/github_api.py +++ b/Libpythonpro/github_api.py @@ -12,5 +12,3 @@ def buscar_avatar(usuario): return resp.json()['avatar_url'] -if __name__ == '__main__': - print(buscar_avatar('Carloshbfreire')) diff --git a/Libpythonpro/tests/test_spam/test_envio_para_base_de_usuarios.py b/Libpythonpro/tests/test_spam/test_envio_para_base_de_usuarios.py index 6eb8c09a9..9d232dbbf 100644 --- a/Libpythonpro/tests/test_spam/test_envio_para_base_de_usuarios.py +++ b/Libpythonpro/tests/test_spam/test_envio_para_base_de_usuarios.py @@ -6,7 +6,6 @@ from Libpythonpro.spam.modelos import Usuario from Libpythonpro.spam.test_spam.enviador_de_email import Enviador - def test_envio_de_spam(sessao): enviador_de_spam= EnviadorDeSpam(sessao, Enviador()) diff --git a/Libpythonpro/tests/test_spam/test_github_api.py b/Libpythonpro/tests/test_spam/test_github_api.py new file mode 100644 index 000000000..86f9e689a --- /dev/null +++ b/Libpythonpro/tests/test_spam/test_github_api.py @@ -0,0 +1,14 @@ +from unittest.mock import Mock + +from Libpythonpro import github_api + + +def test_buscar_avatar(): + resp_mock = Mock() + resp_mock.json.return_value = { + 'login': 'Carloshbfreire', 'id': 107650943, + 'avatar_url': 'https://avatars.githubusercontent.com/u/107650943?v=4', + } + github_api.requests.get = Mock(return_value=resp_mock) + url = github_api.buscar_avatar('Carloshbfreire') + assert 'https://avatars.githubusercontent.com/u/107650943?v=4' == url From 8c367bf1c08da119907ad17c3eca20fdb51b4cd7 Mon Sep 17 00:00:00 2001 From: Carloshbfreire Date: Sun, 2 Oct 2022 16:35:42 -0300 Subject: [PATCH 16/17] Terminado o Exercicio de Isolamento de Imports --- .../tests/test_spam/test_github_api.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/Libpythonpro/tests/test_spam/test_github_api.py b/Libpythonpro/tests/test_spam/test_github_api.py index 86f9e689a..22bd06c3d 100644 --- a/Libpythonpro/tests/test_spam/test_github_api.py +++ b/Libpythonpro/tests/test_spam/test_github_api.py @@ -1,14 +1,26 @@ from unittest.mock import Mock -from Libpythonpro import github_api +import pytest +from Libpythonpro import github_api -def test_buscar_avatar(): +@pytest.fixture +def avatar_url(): resp_mock = Mock() + url = 'https://avatars.githubusercontent.com/u/107650943?v=4' resp_mock.json.return_value = { 'login': 'Carloshbfreire', 'id': 107650943, - 'avatar_url': 'https://avatars.githubusercontent.com/u/107650943?v=4', + 'avatar_url': url, } + get_original = github_api.requests.get github_api.requests.get = Mock(return_value=resp_mock) + yield url + github_api.requests.get = get_original + +def test_buscar_avatar(avatar_url): + url = github_api.buscar_avatar('Carloshbfreire') + assert avatar_url == url + +def test_buscar_avatar_integraçao(): url = github_api.buscar_avatar('Carloshbfreire') assert 'https://avatars.githubusercontent.com/u/107650943?v=4' == url From cfa394b15bc3de7c64ded9c611ccf04b31b4c83c Mon Sep 17 00:00:00 2001 From: Carloshbfreire Date: Mon, 3 Oct 2022 15:32:04 -0300 Subject: [PATCH 17/17] Terminado o Exercicio de Biblioteca pytest-mock. --- Libpythonpro/tests/test_spam/test_github_api.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Libpythonpro/tests/test_spam/test_github_api.py b/Libpythonpro/tests/test_spam/test_github_api.py index 22bd06c3d..79839811c 100644 --- a/Libpythonpro/tests/test_spam/test_github_api.py +++ b/Libpythonpro/tests/test_spam/test_github_api.py @@ -5,17 +5,16 @@ from Libpythonpro import github_api @pytest.fixture -def avatar_url(): +def avatar_url(mocker): resp_mock = Mock() url = 'https://avatars.githubusercontent.com/u/107650943?v=4' resp_mock.json.return_value = { 'login': 'Carloshbfreire', 'id': 107650943, 'avatar_url': url, } - get_original = github_api.requests.get - github_api.requests.get = Mock(return_value=resp_mock) - yield url - github_api.requests.get = get_original + get_mock = mocker.patch('Libpythonpro.github_api.requests.get') + get_mock.return_value = resp_mock + return url def test_buscar_avatar(avatar_url): url = github_api.buscar_avatar('Carloshbfreire')