def test_revise_order_build_confirmation(self): from objects import Shift, Delivery, Order, Tip from processes.revise import Revise_Order from utility.utility import now # id order = Order(Delivery(Shift(now().date()))) test = Revise_Order(order, test=True) test.user_selection = '1' test.build_confirmation() # tip order = Order(Delivery(Shift(now().date()))) test = Revise_Order(order, test=True) test.user_selection = '2' test.build_confirmation() # distance order = Order(Delivery(Shift(now().date()))) test = Revise_Order(order, test=True) test.user_selection = '3' test.build_confirmation() # end time order = Order(Delivery(Shift(now().date()))) test = Revise_Order(order, test=True) test.user_selection = '4' test.build_confirmation() # save order = Order(Delivery(Shift(now().date()))) test = Revise_Order(order, test=True) test.user_selection = 's' test.build_confirmation()
def test_remove_id_from_file(self): import datetime from objects import Shift from os import mkdir, remove, rmdir, path shift = Shift(datetime.datetime.strptime('2020-06-29', '%Y-%m-%d')) # write file mkdir('data') with open(shift.file_list()['completed_ids'], 'w') as file: file.write('2020-06-20,2020-06-24,2020-06-27,2020-06-29,2020-06-30') # read file with open(shift.file_list()['completed_ids'], 'r') as file: test = file.read() # test that id is in file self.assertIn('2020-06-29', test) # run method shift.remove_id_from_file() # read file with open(shift.file_list()['completed_ids'], 'r') as file: test = file.read() # test that id is not in file self.assertNotIn('2020-06-29', test) # remove test file remove(shift.file_list()['completed_ids']) rmdir('data')
def test_revise_delivery_build_confirmation(self): from processes.revise import Revise_Delivery from objects import Shift, Delivery, Order from utility.utility import now delivery = Delivery(Shift(now().date())) test = Revise_Delivery(delivery, test=True)
def test_load_carry_out_tips(self): from objects import Shift from os import path, remove from processes.load import load_carry_out_tips from utility.utility import now shift = Shift(now().date()) file_list = self.shift.file_list() # create file with open(file_list['tips'], 'w') as carry_out_tips_file: carry_out_tips_file.write( '3.11,0.0,0.0\n'\ '0.0,2.71,0.0') # check file exists and baseline self.assertTrue(path.exists(file_list['tips'])) self.assertTrue(len(shift.carry_out_tips) == 0) # run function shift = load_carry_out_tips(shift) # check data was loaded correctly self.assertTrue(len(shift.carry_out_tips) > 0) self.assertEqual(shift.carry_out_tips[0].total_amount(), self.shift.carry_out_tips[0].total_amount()) self.assertEqual(shift.carry_out_tips[1].total_amount(), self.shift.carry_out_tips[1].total_amount()) self.assertEqual(shift.carry_out_tips[0].csv(), self.shift.carry_out_tips[0].csv()) self.assertEqual(shift.carry_out_tips[1].csv(), self.shift.carry_out_tips[1].csv()) # delete files remove(file_list['tips'])
def test_remove_id_from_file_empty_file(self): import datetime from objects import Shift from os import mkdir, rmdir, path shift = Shift(datetime.datetime.strptime('2020-06-29', '%Y-%m-%d')) # write file mkdir('data') with open(shift.file_list()['completed_ids'], 'w') as file: file.write('2020-06-29') # read file with open(shift.file_list()['completed_ids'], 'r') as file: test = file.read() # test that id is in file self.assertIn('2020-06-29', test) # run method shift.remove_id_from_file() # check that file was deleted self.assertFalse(path.exists(shift.file_list()['completed_ids'])) # remove directory rmdir('data')
def overwrite_shift(self): from objects import Shift from os import mkdir from shutil import rmtree from utility.file import write from utility.utility import now self.shift = Shift(now().date()) # delete directory that contains all files rmtree(self.shift.file_list()['directory']) # recreate the directory to store new files mkdir(self.shift.file_list()['directory']) # set and save start time self.shift.set_start_time() write(self.shift.start_time, self.shift.file_list()['start_time']) # remove id from completed ids file self.shift.remove_id_from_file() return self
def test_view_order_main(self): from datetime import datetime from objects import Shift, Delivery, Order, Tip from processes.view import view_order from utility.utility import now, To_Datetime # no data entered order = Order(Delivery(Shift(now().date())), 123) test = view_order(order) expected = 'Order I.D. #: 123\n'\ '\tTotal tip: $0.00\n' self.assertEqual(test, expected) # card order.tip = Tip(3.97) test = view_order(order) expected = 'Order I.D. #: 123\n'\ '\tCard tip: $3.97\n' self.assertEqual(test, expected) # cash order.tip = Tip(cash=3.97) test = view_order(order) expected = 'Order I.D. #: 123\n'\ '\tCash tip: $3.97\n' self.assertEqual(test, expected) # card and cash order.tip = Tip(3, 2) test = view_order(order) expected = 'Order I.D. #: 123\n'\ '\tTotal tip: $5.00\n'\ '\tCard tip: $3.00\n'\ '\tCash tip: $2.00\n' self.assertEqual(test, expected) # unknown order.tip = Tip(unknown=3.97) test = view_order(order) expected = 'Order I.D. #: 123\n'\ '\tUnknown tip: $3.97\n' self.assertEqual(test, expected) # distance order.miles_traveled = 3.9 test = view_order(order) expected = 'Order I.D. #: 123\n'\ '\tUnknown tip: $3.97\n'\ '\tDistance to address: 3.9 miles\n' self.assertEqual(test, expected) # end time order.end_time = datetime.strptime('15:27:42', '%H:%M:%S') test = view_order(order) expected = 'Order I.D. #: 123\n'\ '\tUnknown tip: $3.97\n'\ '\tDistance to address: 3.9 miles\n'\ '\tCompleted at: 03:27:42 PM\n' self.assertEqual(test, expected)
def resume_shift(self): from objects import Shift from os import remove from utility.file import write from utility.utility import now self.shift = Shift(now().date()) # load completed shift data self.shift.load_completed() # get shift start time start_time = self.shift.start_time # delete shift info file remove(self.shift.file_list()['info']) # save start time write(start_time, self.shift.file_list()['start_time']) # remove id from completed ids file self.shift.remove_id_from_file() # load current shift data self.shift.load_current() return self
def test_load_shift_completed(self): from objects import Shift from os import path, remove from processes.load import load_shift from utility.utility import now shift = Shift(now().date()) file_list = self.shift.file_list() # create file with open(file_list['info'], 'w') as shift_file: shift_file.write(self.shift.csv()) # check file was created and baseline self.assertTrue(path.exists(file_list['info'])) self.assertNotEqual(shift.miles_traveled, self.shift.miles_traveled) self.assertNotEqual(shift.fuel_economy, self.shift.fuel_economy) self.assertNotEqual(shift.vehicle_compensation, self.shift.vehicle_compensation) self.assertNotEqual(shift.device_compensation, self.shift.device_compensation) self.assertNotEqual(shift.extra_tips_claimed, self.shift.extra_tips_claimed) self.assertNotEqual(shift.total_hours, self.shift.total_hours) self.assertNotEqual(shift.start_time, self.shift.start_time) self.assertNotEqual(shift.end_time, self.shift.end_time) # run function shift = load_shift(shift) # check that data was loaded correctly self.assertEqual(shift.miles_traveled, self.shift.miles_traveled) self.assertEqual(shift.fuel_economy, self.shift.fuel_economy) self.assertEqual(shift.vehicle_compensation, self.shift.vehicle_compensation) self.assertEqual(shift.device_compensation, self.shift.device_compensation) self.assertEqual(shift.extra_tips_claimed, self.shift.extra_tips_claimed) self.assertEqual(shift.total_hours, self.shift.total_hours) self.assertEqual(shift.start_time, self.shift.start_time) self.assertEqual(shift.end_time, self.shift.end_time) # delete file remove(file_list['info'])
def test_revise_order_build_prompt(self): from objects import Shift, Delivery, Order, Tip from processes.revise import Revise_Order from utility.utility import now order = Order(Delivery(Shift(now().date()))) test = Revise_Order(order, test=True) test.build_prompt() expected =\ '\n- Revise Order -\n'\ '1. Add/edit I.D.\n'\ '2. Add/edit tip\n'\ '3. Add/edit miles traveled\n'\ '4. Add/edit end time\n'\ 'V. View current order values\n'\ 'S. Save changes\n'\ 'B. Go back\n' self.assertEqual(test.prompt, expected)
from menus import Shift_Tracking_Menu from objects import Shift from os import path, chdir from resources.system_names import data_directory, shifts_directory from utility.utility import now # make directories to store user data shifts_path = path.join(data_directory, shifts_directory) if not path.exists(data_directory): from os import mkdir mkdir(data_directory) if not path.exists(shifts_path): from os import mkdir mkdir(shifts_path) shift = Shift(now().date()) # check for completed shift if path.exists(shift.file_list()['info']): from menus import Completed_Shift menu = Completed_Shift(shift) shift = menu.shift # check if shift has not started elif not path.exists(shift.file_list()['directory']): shift.start() # load shift else: shift.load_current() # daily shift tracking menu Shift_Tracking_Menu(shift)
class Completed_Shift: def __init__(self, shift, test=False): from objects import Shift if not isinstance(shift, Shift): raise TypeError self.shift = shift if test is False: from utility.user_input import enter_to_continue self.user_choice() if self.user_choice.lower() == 'r': from resources.strings import Shift__resume__confirmation self.resume_shift(self.shift) enter_to_continue(Shift__resume__confirmation) elif self.user_choice.lower() == 'o': from resources.strings import Shift__overwritten__confirmation self.overwrite_shift(self.shift) enter_to_continue(Shift__overwritten__confirmation) elif self.user_choice.lower() == 'q': pass def overwrite_shift(self): from objects import Shift from os import mkdir from shutil import rmtree from utility.file import write from utility.utility import now self.shift = Shift(now().date()) # delete directory that contains all files rmtree(self.shift.file_list()['directory']) # recreate the directory to store new files mkdir(self.shift.file_list()['directory']) # set and save start time self.shift.set_start_time() write(self.shift.start_time, self.shift.file_list()['start_time']) # remove id from completed ids file self.shift.remove_id_from_file() return self def resume_shift(self): from objects import Shift from os import remove from utility.file import write from utility.utility import now self.shift = Shift(now().date()) # load completed shift data self.shift.load_completed() # get shift start time start_time = self.shift.start_time # delete shift info file remove(self.shift.file_list()['info']) # save start time write(start_time, self.shift.file_list()['start_time']) # remove id from completed ids file self.shift.remove_id_from_file() # load current shift data self.shift.load_current() return self def user_choice(self): from resources.strings import Shift__completed__menu as prompt from utility.user_input import check_match, user_input self.user_choice = user_input(self.prompt) while not check_match('^[roq]$', self.user_choice): self.user_choice = user_input(self.prompt) return self
class Test_Delivery(unittest.TestCase): def setUp(self): from objects import Delivery, Shift from utility.utility import now self.shift = Shift(now().date()) self.delivery = Delivery(self.shift) def test_add_order_type_error(self): import objects with self.assertRaises(TypeError): self.delivery.add_order(self.shift) with self.assertRaises(TypeError): self.delivery.add_order(self.delivery) with self.assertRaises(TypeError): self.shift.add_delivery(objects.Extra_Stop(self.shift)) with self.assertRaises(TypeError): self.shift.add_delivery(objects.Tip()) with self.assertRaises(TypeError): self.shift.add_delivery(123) with self.assertRaises(TypeError): self.shift.add_delivery('hello world') with self.assertRaises(TypeError): self.shift.add_delivery([1, 2, 3, 4]) def test_add_order(self): from objects import Order self.assertEqual(self.delivery.orders, []) order_1 = Order(self.delivery, 5) self.delivery.add_order(order_1) self.assertIn(5, self.delivery.order_ids) self.assertIn(order_1, self.delivery.orders) order_2 = Order(self.delivery, 748) self.delivery.add_order(order_2) self.assertIn(748, self.delivery.order_ids) self.assertIn(order_2, self.delivery.orders) def test_csv(self): from utility.utility import To_Datetime expected = 'None,None,None,None' self.assertEqual(self.delivery.csv(), expected) start_time = To_Datetime('2020-08-23 12:03:00.000').from_datetime() end_time = To_Datetime('2020-08-23 12:37:00.000').from_datetime() distance = 7.2 average_speed = 21 self.delivery.start_time = start_time self.delivery.end_time = end_time self.delivery.miles_traveled = distance self.delivery.average_speed = average_speed expected = '{},{},{},{}'.format(distance, average_speed, start_time, end_time) self.assertEqual(self.delivery.csv(), expected)
def test_revise_delivery_build_prompt(self): from datetime import datetime from processes.revise import Revise_Delivery from objects import Shift, Delivery, Order, Extra_Stop from utility.utility import now # no data added yet delivery = Delivery(Shift(now().date())) test = Revise_Delivery(delivery, test=True) test.build_prompt() expected =\ '\n- Revise Delivery -\n'\ 'Please select an option:\n'\ '1. Add start time\n'\ '2. Add miles traveled\n'\ '3. Add average speed\n'\ '4. Add end time\n'\ 'O. Add order\n'\ 'V. View current delivery\n'\ 'S. Save changes\n'\ 'B. Go back\n' self.assertEqual(test.prompt, expected) # start time added test.delivery.start_time = datetime.strptime('15:27:42', '%H:%M:%S') test.build_prompt() expected =\ '\n- Revise Delivery -\n'\ 'Please select an option:\n'\ '1. Revise start time\n'\ '2. Add miles traveled\n'\ '3. Add average speed\n'\ '4. Add end time\n'\ 'O. Add order\n'\ 'V. View current delivery\n'\ 'S. Save changes\n'\ 'B. Go back\n' self.assertEqual(test.prompt, expected) # miles traveled added test.delivery.miles_traveled = 4.7 test.build_prompt() expected =\ '\n- Revise Delivery -\n'\ 'Please select an option:\n'\ '1. Revise start time\n'\ '2. Revise miles traveled\n'\ '3. Add average speed\n'\ '4. Add end time\n'\ 'O. Add order\n'\ 'V. View current delivery\n'\ 'S. Save changes\n'\ 'B. Go back\n' self.assertEqual(test.prompt, expected) # average speed added test.delivery.average_speed = 17 test.build_prompt() expected =\ '\n- Revise Delivery -\n'\ 'Please select an option:\n'\ '1. Revise start time\n'\ '2. Revise miles traveled\n'\ '3. Revise average speed\n'\ '4. Add end time\n'\ 'O. Add order\n'\ 'V. View current delivery\n'\ 'S. Save changes\n'\ 'B. Go back\n' self.assertEqual(test.prompt, expected) # end time added test.delivery.end_time = datetime.strptime('15:37:42', '%H:%M:%S') test.build_prompt() expected =\ '\n- Revise Delivery -\n'\ 'Please select an option:\n'\ '1. Revise start time\n'\ '2. Revise miles traveled\n'\ '3. Revise average speed\n'\ '4. Revise end time\n'\ 'O. Add order\n'\ 'V. View current delivery\n'\ 'S. Save changes\n'\ 'B. Go back\n' self.assertEqual(test.prompt, expected) # one order added test.delivery.order_id = [0] test.delivery.orders = [Order(delivery)] test.build_prompt() expected =\ '\n- Revise Delivery -\n'\ 'Please select an option:\n'\ '1. Revise start time\n'\ '2. Revise miles traveled\n'\ '3. Revise average speed\n'\ '4. Revise end time\n'\ 'O. Revise order/Add order\n'\ 'V. View current delivery\n'\ 'S. Save changes\n'\ 'B. Go back\n' self.assertEqual(test.prompt, expected) # two orders added test.delivery.order_id = [0, 1] test.delivery.orders = [Order(delivery), Order(delivery, 1)] test.build_prompt() expected =\ '\n- Revise Delivery -\n'\ 'Please select an option:\n'\ '1. Revise start time\n'\ '2. Revise miles traveled\n'\ '3. Revise average speed\n'\ '4. Revise end time\n'\ 'O. Select an order/Add order\n'\ 'V. View current delivery\n'\ 'S. Save changes\n'\ 'B. Go back\n' self.assertEqual(test.prompt, expected) # extra stop added test.delivery.extra_stop_id = [0] test.delivery.extra_stops = [Extra_Stop(delivery)] test.build_prompt() expected =\ '\n- Revise Delivery -\n'\ 'Please select an option:\n'\ '1. Revise start time\n'\ '2. Revise miles traveled\n'\ '3. Revise average speed\n'\ '4. Revise end time\n'\ 'O. Select an order/Add order\n'\ 'E. Revise extra stop\n'\ 'V. View current delivery\n'\ 'S. Save changes\n'\ 'B. Go back\n' self.assertEqual(test.prompt, expected) # two extra stops added test.delivery.extra_stop_id = [0, 1] test.delivery.extra_stops =\ [Extra_Stop(delivery), Extra_Stop(delivery, 1)] test.build_prompt() expected =\ '\n- Revise Delivery -\n'\ 'Please select an option:\n'\ '1. Revise start time\n'\ '2. Revise miles traveled\n'\ '3. Revise average speed\n'\ '4. Revise end time\n'\ 'O. Select an order/Add order\n'\ 'E. Select an extra stop\n'\ 'V. View current delivery\n'\ 'S. Save changes\n'\ 'B. Go back\n' self.assertEqual(test.prompt, expected)
from objects import Shift import os from utility.file import Read from utility.utility import now, To_Datetime id_list = Read(Shift(now().date()).file_list()['completed_ids']).comma() uncompleted_id_list = [] os.chdir(os.path.join('data', 'shifts')) for directory in os.listdir(): if directory not in id_list: uncompleted_id_list.append(directory) print(f'Total uncompleted shifts: {len(uncompleted_id_list)}') print('List of uncompleted dates:') for directory in uncompleted_id_list: print(directory)
def test_load_shift_current(self): from objects import Shift from os import path, remove from processes.load import load_shift from utility.utility import now shift = Shift(now().date()) file_list = self.shift.file_list() # create files with open(file_list['start_time'], 'w') as start_time_file: start_time_file.write(str(self.shift.start_time)) with open(file_list['end_time'], 'w') as end_time_file: end_time_file.write(str(self.shift.end_time)) with open(file_list['miles_traveled'], 'w') as miles_traveled_file: miles_traveled_file.write(str(self.shift.miles_traveled)) with open(file_list['fuel_economy'], 'w') as fuel_economy_file: fuel_economy_file.write(str(self.shift.fuel_economy)) with open(file_list['vehicle_compensation'], 'w') as vehicle_compensation_file: vehicle_compensation_file.write( str(self.shift.vehicle_compensation)) with open(file_list['device_compensation'], 'w') as device_compensation_file: device_compensation_file.write(str(self.shift.device_compensation)) with open(file_list['total_hours'], 'w') as total_hours_file: total_hours_file.write(str(self.shift.total_hours)) with open(file_list['extra_tips_claimed'], 'w') as extra_tips_claimed_file: extra_tips_claimed_file.write(str(self.shift.extra_tips_claimed)) # check files were created and baseline self.assertTrue(path.exists(file_list['start_time'])) self.assertTrue(path.exists(file_list['end_time'])) self.assertTrue(path.exists(file_list['miles_traveled'])) self.assertTrue(path.exists(file_list['fuel_economy'])) self.assertTrue(path.exists(file_list['vehicle_compensation'])) self.assertTrue(path.exists(file_list['device_compensation'])) self.assertTrue(path.exists(file_list['total_hours'])) self.assertTrue(path.exists(file_list['extra_tips_claimed'])) self.assertNotEqual(shift.start_time, self.shift.start_time) self.assertNotEqual(shift.end_time, self.shift.end_time) self.assertNotEqual(shift.miles_traveled, self.shift.miles_traveled) self.assertNotEqual(shift.fuel_economy, self.shift.fuel_economy) self.assertNotEqual(shift.vehicle_compensation, self.shift.vehicle_compensation) self.assertNotEqual(shift.device_compensation, self.shift.device_compensation) self.assertNotEqual(shift.total_hours, self.shift.total_hours) self.assertNotEqual(shift.extra_tips_claimed, self.shift.extra_tips_claimed) # run function shift = load_shift(shift, current=True) # check that data was loaded correctly self.assertEqual(shift.start_time, self.shift.start_time) self.assertEqual(shift.end_time, self.shift.end_time) self.assertEqual(shift.miles_traveled, self.shift.miles_traveled) self.assertEqual(shift.fuel_economy, self.shift.fuel_economy) self.assertEqual(shift.vehicle_compensation, self.shift.vehicle_compensation) self.assertEqual(shift.device_compensation, self.shift.device_compensation) self.assertEqual(shift.total_hours, self.shift.total_hours) self.assertEqual(shift.extra_tips_claimed, self.shift.extra_tips_claimed) # delete files remove(file_list['start_time']) remove(file_list['end_time']) remove(file_list['miles_traveled']) remove(file_list['fuel_economy']) remove(file_list['vehicle_compensation']) remove(file_list['device_compensation']) remove(file_list['total_hours']) remove(file_list['extra_tips_claimed'])
def setUp(self): from objects import Delivery, Shift from utility.utility import now self.shift = Shift(now().date()) self.delivery = Delivery(self.shift)