Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save brydavis/251d454bcb14cdc64622dd4ee09b9a34 to your computer and use it in GitHub Desktop.
Save brydavis/251d454bcb14cdc64622dd4ee09b9a34 to your computer and use it in GitHub Desktop.
Tests for Assignment 4
"""
Autograde Lesson 3 assignment
Run pytest
Run cobverage and linitng using standard batch file
Student should submit an empty database
"""
import pytest
import logging
import basic_operations as l
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
fh = logging.FileHandler('norton.log')
fh.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s\t%(message)s')
fh.setFormatter(formatter)
logger.addHandler(fh)
@pytest.fixture
def _add_customers():
return (row for row in [
("1","Tybalt","Heinsh","8 Lien Trail","876935123","[email protected]","active","2420"),
("2","Gwennie","Tennock","4608 Steensland Lane","134552899","[email protected]","active","2343"),
("3","Euell","Fidgeon","8 Lerdahl Park","009363240","[email protected]","inactive","1077"),
("4","Cairistiona","Ginnell","3 Harbort Drive","880717312","[email protected]","active","1484"),
("5","Mariel","Wolfarth","47 Loomis Hill","069169873","[email protected]","inactive","113"),
("6","Mallorie","Sammut","3614 Fisk Avenue","828591715","[email protected]","active","3255"),
("7","Seamus","Pittford","2136 Rigney Park","807689452","[email protected]","active","3468"),
("8","Piotr","Gauson","4145 Kensington Park","133398937","[email protected]","inactive","3625"),
("9","Teodora","Loxton","40829 Bartillon Crossing","194346240","[email protected]","inactive","444"),
("10","Nanine","Eadmeades","8691 Calypso Circle","367839372","[email protected]","inactive","2459"),
("11","Marieann","Calcutt","5678 Rutledge Point","245977057","[email protected]","inactive","2962"),
("12","Wandis","Dewdney","095 Packers Park","135126295","[email protected]","active","4742"),
("13","Tommy","Wannes","59889 Myrtle Avenue","969027317","[email protected]","inactive","4067"),
("14","Letti","Barkworth","7 Sundown Place","243310785","[email protected]","inactive","1697"),
("15","Danit","Fayerman","9107 Oakridge Point","596550663","[email protected]","active","2382"),
("16","Susanna","Grigaut","87 Cascade Avenue","839048392","[email protected]","inactive","3982"),
("17","Donal","Thraves","2048 Porter Place","303563873","[email protected]","inactive","3597"),
("18","Erina","Whightman","0 Columbus Park","380312722","[email protected]","active","2007"),
("19","Rogers","Dumbare","2 Shopko Hill","510504125","[email protected]","active","371"),
("20","Kayla","Coyte","4134 Atwood Pass","468104655","[email protected]","active","4400"),
])
@pytest.fixture
def _search_customers(): # needs to del with database
return [
[
("15","Danit","Fayerman","9107 Oakridge Point","596550663","[email protected]","active","2382"),
("16","Susanna","Grigaut","87 Cascade Avenue","839048392","[email protected]","inactive","3982"),
("17","Donal","Thraves","2048 Porter Place","303563873","[email protected]","inactive","3597"),
("18","Erina","Whightman","0 Columbus Park","380312722","[email protected]","active","2007"),
("19","Rogers","Dumbare","2 Shopko Hill","510504125","[email protected]","active","371"),
],
("16", "000")
]
@pytest.fixture
def _delete_customers(): # needs to del with database
return iter([
("3","Euell","Fidgeon","8 Lerdahl Park","009363240","[email protected]","inactive","1077"),
("4","Cairistiona","Ginnell","3 Harbort Drive","880717312","[email protected]","active","1484"),
("5","Mariel","Wolfarth","47 Loomis Hill","069169873","[email protected]","inactive","113"),
])
@pytest.fixture
def _update_customer_credit(): # needs to del with database
return (row for row in [
("8","Piotr","Gauson","4145 Kensington Park","133398937","[email protected]","inactive","3625"),
("9","Teodora","Loxton","40829 Bartillon Crossing","194346240","[email protected]","inactive","444"),
("10","Nanine","Eadmeades","8691 Calypso Circle","367839372","[email protected]","inactive","2459"),
])
@pytest.fixture
def _list_active_customers():
return (
row for row in [
("1","Tybalt","Heinsh","8 Lien Trail","876935123","[email protected]","active","2420"),
("2","Gwennie","Tennock","4608 Steensland Lane","134552899","[email protected]","active","2343"),
("4","Cairistiona","Ginnell","3 Harbort Drive","880717312","[email protected]","active","1484"),
("6","Mallorie","Sammut","3614 Fisk Avenue","828591715","[email protected]","active","3255"),
("7","Seamus","Pittford","2136 Rigney Park","807689452","[email protected]","active","3468"),
("12","Wandis","Dewdney","095 Packers Park","135126295","[email protected]","active","4742"),
("15","Danit","Fayerman","9107 Oakridge Point","596550663","[email protected]","active","2382"),
]
)
def test_list_active_customers(_list_active_customers):
""" actives """
for customer in _list_active_customers:
l.add_customer(
customer[0],
customer[1],
customer[2],
customer[3],
customer[4],
customer[5],
customer[6],
customer[7],
)
actives = l.list_active_customers()
assert actives == 7
def test_add_customer(_add_customers):
""" additions """
# logger.info(type(_add_customers))
for customer in _add_customers:
l.add_customer(
customer[0],
customer[1],
customer[2],
customer[3],
customer[4],
customer[5],
customer[6],
customer[7],
)
added = l.search_customer(customer[0])
assert added["name"] == customer[1]
assert added["lastname"] == customer[2]
assert added["email"] == customer[5]
assert added["phone_number"] == customer[4]
for customer in _add_customers:
l.delete_customer(customer[0])
def test_search_customer(_search_customers):
""" search """
logger.info(type(_search_customers))
for customer in _search_customers[0]:
l.add_customer(
customer[0],
customer[1],
customer[2],
customer[3],
customer[4],
customer[5],
customer[6],
customer[7]
)
result = l.search_customer(_search_customers[1][1])
assert result == {}
result = l.search_customer(_search_customers[1][0])
assert result["name"] == _search_customers[0][1][1]
assert result["lastname"] == _search_customers[0][1][2]
assert result["email"] == _search_customers[0][1][5]
assert result["phone_number"] == _search_customers[0][1][4]
for customer in _search_customers[0]:
l.delete_customer(customer[0])
def test_delete_customer(_delete_customers):
""" delete """
# logger.info(type(_delete_customers))
for customer in _delete_customers:
l.add_customer(customer[0],
customer[1],
customer[2],
customer[3],
customer[4],
customer[5],
customer[6],
customer[7]
)
response = l.delete_customer(customer[0])
assert response is True
deleted = l.search_customer(customer[0])
assert deleted == {}
def test_update_customer_credit(_update_customer_credit):
""" update """
for customer in _update_customer_credit:
l.add_customer(
customer[0],
customer[1],
customer[2],
customer[3],
customer[4],
customer[5],
customer[6],
customer[7]
)
l.update_customer_credit("8", 0)
l.update_customer_credit("9", 1000)
l.update_customer_credit("10", -42)
with pytest.raises(ValueError) as excinfo:
l.update_customer_credit("00100", 1000) # error
assert 'NoCustomer' in str(excinfo.value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment