-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Configurado Integraçao com Travis-CI
- Loading branch information
1 parent
d2680db
commit 572de69
Showing
18 changed files
with
233 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
language: python | ||
python: | ||
- 3.9 | ||
install: | ||
- pip instal -r requirements-dev.txt | ||
script: | ||
- flake8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,7 @@ | ||
import requests as requests | ||
import requests | ||
|
||
|
||
def buscar_avatar(usuario): | ||
url = f'http://api.github.com/users/{usuario}' | ||
resp = requests.get(url) | ||
return resp.json()['avatar_url'] | ||
|
||
if __name__ == '__main__' : | ||
print(buscar_avatar('cicerossoares')) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from time import sleep | ||
|
||
|
||
class Conexao: | ||
def __init__(self): | ||
sleep(2) | ||
|
||
@staticmethod | ||
def gerar_sessao(): | ||
return Sessao() | ||
|
||
def fechar(self): | ||
pass | ||
|
||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class Enviador: | ||
def enviar(self, remetente, destinatario, assunto, corpo): | ||
if '@' not in remetente: | ||
raise EmailInvalido(f'Email remetente invalido: {remetente}') | ||
return remetente | ||
|
||
|
||
class EmailInvalido(Exception): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class Usuario: | ||
def __init__(self, nome, email): | ||
self.email = email | ||
self.nome = nome | ||
self.id = None |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
def test_int(): | ||
assert 1==1 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import pytest | ||
|
||
from libpythonsrs.spam.db import Conexao | ||
|
||
|
||
@pytest.fixture(scope='session') | ||
def conexao(): | ||
#setup | ||
conexao_obj = Conexao() | ||
yield conexao_obj | ||
#teardown | ||
conexao_obj.fechar() | ||
|
||
|
||
@pytest.fixture | ||
def sessao(conexao): | ||
sessao_obj = conexao.gerar_sessao() | ||
yield sessao_obj | ||
sessao_obj.roll_back() | ||
sessao_obj.fechar() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import pytest | ||
|
||
from libpythonsrs import api_github | ||
from unittest.mock import Mock | ||
|
||
|
||
@pytest.fixture | ||
def avatar_url(mocker): | ||
resp_mock = Mock() | ||
url = 'https://avatars.githubusercontent.com/u/98067396?v=4' | ||
resp_mock.json.return_value = { | ||
"login": "Cicerossoares", "id": 98067396, "node_id": "U_kgDOBdhjxA", | ||
"avatar_url":url, | ||
} | ||
get_mock = mocker.patch('libpythonsrs.api_github.requests.get') | ||
get_mock.return_value = resp_mock | ||
return url | ||
|
||
|
||
def test_buscar_avatar(avatar_url): | ||
url = api_github.buscar_avatar('cicerossoares') | ||
assert url == url | ||
|
||
|
||
def test_buscar_avatar_integracao(): | ||
url = api_github.buscar_avatar('cicerossoares') | ||
assert 'https://avatars.githubusercontent.com/u/98067396?v=4' == url |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import pytest | ||
|
||
from libpythonsrs.spam.enviador_email import Enviador, EmailInvalido | ||
|
||
|
||
def test_criar_enviador_email(): | ||
enviador = Enviador() | ||
assert enviador is not None | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'remetente', | ||
['ozctkz@gmail.com', 'cjgatao02@gmail.com'] | ||
) | ||
def test_remetente(remetente): | ||
enviador = Enviador() | ||
resultado = enviador.enviar( | ||
remetente, | ||
'cjgatao@gmail.com', | ||
'teste do enviador', | ||
'Voce conseguiu Cicero' | ||
) | ||
assert remetente in resultado | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'remetente', | ||
['','cjgatao02'] | ||
) | ||
def test_remetente_invalido(remetente): | ||
enviador = Enviador() | ||
with pytest.raises(EmailInvalido): | ||
enviador.enviar( | ||
remetente, | ||
'cjgatao@gmail.com', | ||
'teste do enviador', | ||
'Voce conseguiu Cicero' | ||
) |
62 changes: 62 additions & 0 deletions
62
libpythonsrs/tests/test_spam/test_envio_para_base_usuarios.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
from unittest.mock import Mock | ||
|
||
import pytest as pytest | ||
|
||
from libpythonsrs.spam.enviador_email import Enviador | ||
from libpythonsrs.spam.main import EnviadorDeSpam | ||
from libpythonsrs.spam.modelos import Usuario | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'usuarios', | ||
[ | ||
[ | ||
Usuario(nome='Cicero', email='ozctkz@gmail.com'), | ||
Usuario(nome='Junior', email='ozctkz@gmail.com') | ||
], | ||
[ | ||
Usuario(nome='Cicero', email='ozctkz@gmail.com') | ||
] | ||
] | ||
) | ||
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( | ||
'ozctkz@gmail.com', | ||
'Testando', | ||
'testando' | ||
) | ||
assert len(usuarios) == enviador.enviar.call_count | ||
|
||
|
||
class EnviadorMock(Enviador): | ||
|
||
def __init__(self): | ||
super().__init__() | ||
self.qtd_email_enviados = 0 | ||
self.parametros_de_envio = None | ||
|
||
def enviar(self, remetente, destinatario, assunto, corpo): | ||
self.parametros_de_envio = (remetente, destinatario, assunto, corpo) | ||
self.qtd_email_enviados += 1 | ||
|
||
|
||
def test_parametros_de_spam(sessao): | ||
usuario = Usuario(nome='Cicero', email='ozctkz@gmail.com') | ||
sessao.salvar(usuario) | ||
enviador = Mock() | ||
enviador_de_spam = EnviadorDeSpam(sessao, enviador) | ||
enviador_de_spam.enviar_emails( | ||
'cjgatao@gmail.com', | ||
'Testando', | ||
'testando' | ||
) | ||
enviador.enviar.assert_called_once_with( | ||
'cjgatao@gmail.com', | ||
'ozctkz@gmail.com', | ||
'Testando', | ||
'testando' | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from libpythonsrs.spam.modelos import Usuario | ||
|
||
|
||
def test_salvar_usuario(conexao, sessao): | ||
usuario = Usuario(nome='Cicero', email='ozctkz@gmail.com') | ||
sessao.salvar(usuario) | ||
assert isinstance(usuario.id, int) | ||
|
||
|
||
def test_listar_usuarios(sessao): | ||
usuarios = [Usuario(nome='Cicero', email='ozctkz@gmail.com'), | ||
Usuario(nome='Junior', email='ozctkz@gmail.com') | ||
] | ||
for usuario in usuarios: | ||
sessao.salvar(usuario) | ||
assert usuarios == sessao.listar() |
Binary file not shown.
Binary file not shown.