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
class PersonRepository: | |
@db_session | |
def create(self, name, age): | |
return Person(name=name, age=age) | |
@db_session | |
def get_by_name(self, name): | |
return list(select(p for p in Person if p.name == name)) |
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
test_person_repository_gets_the_person_by_id[Andrew Who] PASSED | |
test_person_repository_gets_the_person_by_id[James Gross] PASSED | |
test_person_repository_gets_the_person_by_name[Andrew Who] PASSED | |
test_person_repository_gets_the_person_by_name[James Gross] PASSED |
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
@pytest.fixture(params=["Andrew Who", "James Gross"]) | |
def person(request): | |
return PersonRepository.create(name=request.param, age=20) |
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
@pytest.mark.integration | |
def test_person_repository_gets_the_person_by_name(person): | |
retrieved_persons = PersonRepository().get_by_name(name=person.name) | |
assert len((retrieved_persons)) == 1 | |
assert retrieved_persons[0].id == person.id | |
assert retrieved_persons[0].name == person.name | |
assert retrieved_persons[0].age == person.age |
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
@pytest.fixture | |
def person(): | |
return PersonRepository().create(name='Andrew', age=20) |
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
@pytest.mark.parametrize('leap_year', [2016, 2020, 2024, 2028, 2400]) | |
def test_is_leap_year_returns_true_for_leap_years(leap_year): | |
assert is_leap_year(leap_year) |
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
def test_is_leap_year_returns_true_for_leap_years(): | |
leap_years = [2016, 2020, 2023, 2028, 2400] | |
for leap_year in leap_years: | |
yield assert_is_leap, leap_year | |
def assert_is_leap(year): | |
assert_true(is_leap_year(year)) |
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
___________ test_get_user_stats_returns_full_user_statistics ___________ | |
def test_get_user_stats_returns_full_user_statistics(): | |
> assert get_user_stats(username='Pinky') =={ | |
"elections_hacked": 11, | |
"is_laserproof": False, | |
} | |
E AssertionError: assert {'elections_h...proof': False} == {'elections_ha...proof': False} | |
E Omitting 1 identical items, use -vv to show | |
E Differing items: |
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
_____________ test_is_leap_year_returns_true_for_leap_year _____________ | |
def test_is_leap_year_returns_true_for_leap_year(): | |
> assert is_leap_year(2021) | |
E assert False | |
E + where False = is_leap_year(2021) | |
tests/test_utils.py:5: AssertionError |
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
====================================================================== | |
FAIL: test_utils.test_is_leap_year_returns_true_for_leap_year | |
---------------------------------------------------------------------- | |
Traceback (most recent call last): | |
File "/home/heck/.virtualenvs/pytest/lib/python3.5/site-packages/nose/case.py", line 198, in runTest | |
self.test(*self.arg) | |
File "/home/heck/Workplace/pytest_presentation/tests/nose/test_utils.py", line 13, in test_is_leap_year_returns_true_for_leap_year | |
assert_true(is_leap_year(2029)) | |
AssertionError: False is not true |
NewerOlder