-
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.
Pytest framework issue after conftest.py file refactor.
- Loading branch information
Showing
11 changed files
with
136 additions
and
1 deletion.
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 |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = '0.2' | ||
__version__ = '0.3' |
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,31 @@ | ||
from time import sleep | ||
|
||
|
||
class Session: | ||
count = 0 | ||
users = [] | ||
|
||
def save(self, user): | ||
Session.count += 1 | ||
user.id = Session.count | ||
self.users.append(user) | ||
|
||
def list(self): | ||
return self.users | ||
|
||
def roll_back(self): | ||
self.users.clear() | ||
|
||
def close(self): | ||
pass | ||
|
||
|
||
class Connection: | ||
def __init__(self): | ||
sleep(1) | ||
|
||
def generate_session(self): | ||
return Session() | ||
|
||
def close(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 Sender(object): | ||
def send(self, shipper, recipient, title, body): | ||
if '@' not in shipper: | ||
raise InvalidEmail(f'Invalid shipper address: {shipper}') | ||
return shipper | ||
|
||
|
||
class InvalidEmail(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,7 @@ | ||
class SpamSender: | ||
def __init__(self, session, sender): | ||
self.session = session | ||
self.sender = sender | ||
|
||
def send_emails(self, shipper, title, body): | ||
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,4 @@ | ||
class User: | ||
def __init__(self, name): | ||
self.name = name | ||
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,20 @@ | ||
import pytest | ||
|
||
from libpythonpro_doug.spam.db import Connection | ||
|
||
|
||
@pytest.fixture(scope='session') | ||
def connection(): | ||
# Setup | ||
connection_obj = Connection() | ||
yield connection_obj | ||
# Tear Down | ||
connection_obj.close() | ||
|
||
|
||
@pytest.fixture | ||
def session(connection): | ||
session_obj = connection.generate_session() | ||
yield session_obj | ||
session_obj.roll_back() | ||
session_obj.close() |
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,39 @@ | ||
import pytest | ||
|
||
from libpythonpro_doug.spam.email_sender import Sender, InvalidEmail | ||
|
||
|
||
def test_create_email_sender(): | ||
email_sender = Sender() | ||
assert email_sender is not None | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'shipper', | ||
['douglas.fraga@gmail.com', 'douglas@threetek.com.br'] | ||
) | ||
def test_email_sender(shipper): | ||
email_sender = Sender() | ||
|
||
result = email_sender.send( | ||
shipper, | ||
'dfr_dede@yahoo.com.br', | ||
'Python Pro training course', | ||
'email body' | ||
) | ||
assert shipper in result | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'shipper', | ||
['', 'douglas'] | ||
) | ||
def test_invalid_email_sender(shipper): | ||
email_sender = Sender() | ||
with pytest.raises(InvalidEmail): | ||
email_sender.send( | ||
shipper, | ||
'dfr_dede@yahoo.com.br', | ||
'Python Pro training course', | ||
'email body' | ||
) |
11 changes: 11 additions & 0 deletions
11
libpythonpro_doug/tests/test_spam/test_send_to_user_base.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,11 @@ | ||
from libpythonpro_doug.spam.email_sender import Sender | ||
from libpythonpro_doug.spam.main import SpamSender | ||
|
||
|
||
def test_send_spam(session): | ||
spam_sender = SpamSender(session, Sender()) | ||
spam_sender.send_emails( | ||
'douglas.fraga@gmail.com', | ||
'Python Pro Training Course', | ||
'Email body' | ||
) |
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,14 @@ | ||
from libpythonpro_doug.spam.models import User | ||
|
||
|
||
def test_save_user(session): | ||
user = User(name='Doug') | ||
session.save(user) | ||
assert isinstance(user.id, int) | ||
|
||
|
||
def test_list_user(session): | ||
users = [User(name='Doug'), User(name='Carol')] | ||
for user in users: | ||
session.save(user) | ||
assert users == session.list() |