def test_summary(self): """Test dictionary set with {Donor: Total, number of donations, and average donation amount}""" group_instance = d.Group('test.db') summary = group_instance.summary() # 'Zach is in database self.assertDictEqual(summary, {'Shane': [21, 3, 7.0], 'Joe': [5, 1, 5.0], 'Zach': [10, 1, 10.0], 'Pete':[15, 2, 7.5], 'Fitz':[1,1,1.0], 'Luke':[5, 1, 5.0]})
import os import donors_sql as d import create_mr_tables as new_database import logging # from peewee import * mail = d.Group('mailroom.db') individual = d.Individual('mailroom.db') logging.basicConfig(level=logging.WARNING) logger = logging.getLogger(__name__) def create_database(): file_name = input('\nWhat would you like to name your new database?\n' 'e - to exit\n') if file_name == 'e': return else: if os.path.exists(file_name): logging.info('This database already exists.') return # cwd = os.getcwd() file_name = file_name + '.db' logger.info(f'Creating new database {file_name}.') new_database.database.init(file_name) database = new_database.database database.connect() logger.info('Creating Modules in database') database.create_tables([new_database.Donor, new_database.Donations])
def test_Group_search2(self): """Returns 'name' when name does exist""" database.connect(reuse_if_open=True) group_instance = d.Group('test.db') search_result = group_instance.search('Zach') # 'Zach is in database self.assertEqual(search_result, 'Zach')
def test_Group_search1(self): """Returns None when name does not exist""" #database.connect(reuse_if_open=True) group_instance = d.Group('test.db') search_result = group_instance.search('Bob') # Bob is not in database self.assertEqual(search_result, None)
def test_sort_list(self): """sorts the dictionary by largest to smallest donation""" group_instance = d.Group('test.db') summary = group_instance.summary() sorted = group_instance.sort_list(summary) self.assertEqual(sorted, ['Shane', 'Pete', 'Zach', 'Joe', 'Luke', 'Fitz'])