def test_view_tip(self): from objects import Tip from processes.view import view_tip # card and cash tip = Tip(3.0, 2.0) test = view_tip(tip) expected = '\nTotal tip: $5.00\nCard tip: $3.00\nCash tip: $2.00\n' self.assertEqual(test, expected) # card tip = Tip(3.0) test = view_tip(tip) expected = '\nCard tip: $3.00\n' self.assertEqual(test, expected) # cash tip = Tip(cash=3.0) test = view_tip(tip) expected = '\nCash tip: $3.00\n' self.assertEqual(test, expected) # unknown tip = Tip(unknown=3.0) test = view_tip(tip) expected = '\nUnknown tip: $3.00\n' self.assertEqual(test, expected) # no tip tip = Tip() test = view_tip(tip) expected = '\nTotal tip: $0.00\n' self.assertEqual(test, expected)
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 test_consolidate_order(self): from objects import Tip from os import mkdir, remove, rmdir, path from processes.consolidate import consolidate_order from utility.utility import To_Datetime delivery = self.shift.deliveries[0] parent_directory = delivery.file_list()['directory'] order = delivery.orders[0] file_list = order.file_list() # create directories mkdir(parent_directory) mkdir(file_list['directory']) # create indavidual files with open(file_list['id'], 'w') as id_file: id_file.write(str(order.id)) with open(file_list['tip'], 'w') as tip_file: tip_file.write(str(order.tip.csv())) with open(file_list['miles_traveled'], 'w') as miles_traveled_file: miles_traveled_file.write(str(order.miles_traveled)) with open(file_list['end_time'], 'w') as end_time_file: end_time_file.write(str(order.end_time)) # check that files were created and others dont exist self.assertTrue(path.exists(file_list['id'])) self.assertTrue(path.exists(file_list['tip'])) self.assertTrue(path.exists(file_list['miles_traveled'])) self.assertTrue(path.exists(file_list['end_time'])) self.assertFalse(path.exists(file_list['info'])) self.assertFalse(path.exists(file_list['completed_ids'])) # run the function consolidate_order(order) # check that the files were deleted and created self.assertFalse(path.exists(file_list['id'])) self.assertFalse(path.exists(file_list['tip'])) self.assertFalse(path.exists(file_list['miles_traveled'])) self.assertFalse(path.exists(file_list['end_time'])) self.assertTrue(path.exists(file_list['info'])) self.assertTrue(path.exists(file_list['completed_ids'])) # check that correct data was written to files with open(file_list['info'], 'r') as info_file: data = info_file.readline().split(',') self.assertEqual( Tip(float(data[0]), float(data[1]), float(data[2])).csv(), order.tip.csv()) self.assertEqual(float(data[3]), order.miles_traveled) self.assertEqual( To_Datetime(data[4]).from_datetime(), order.end_time) with open(file_list['completed_ids'], 'r') as completed_ids_file: self.assertEqual(int(completed_ids_file.readline()), order.id) # delete files and directories remove(file_list['info']) remove(file_list['completed_ids']) rmdir(parent_directory)
def load_tip(file_path): if not isinstance(file_path, str): raise TypeError from objects import Tip from utility.file import Read data = Read(file_path).decimal() return Tip(data[0], data[1], data[2])
def get_tip(card=False, cash=False, both=False, unknown=False): import random from objects import Tip chance = random.randint(0, 3) # card tip if card is True or chance == 0: return Tip(random.uniform(.01, 20.0)) # cash tip if cash is True or chance == 1: return Tip(cash=random.uniform(.01, 20.0)) # card & cash tip if both is True or chance == 2: card_tip = random.uniform(.01, 20.0) cash_tip = random.uniform(.01, 20.0) return Tip(card_tip, cash_tip) # unknown if unknown is True or chance == 3: return Tip(unknown=random.uniform(.01, 20.0))
def load_carry_out_tips(shift): from objects import Tip from os import path from utility.file import Read if path.exists(shift.file_list()['tips']): file_data = Read(shift.file_list()['tips']).newline() for tip in file_data: tip_data = tip.split(',') shift.carry_out_tips.append( Tip(tip_data[0], tip_data[1], tip_data[2])) return shift
def load_order(order): from objects import Order if not isinstance(order, Order): # todo: need to fix error message for taking delivery from resources.error_messages import load__order__wrong_parameter raise TypeError(load__order__wrong_parameter) from os import path from utility.file import Read from utility.utility import To_Datetime file_list = order.file_list() # in progress if order.in_progress: # id if path.exists(file_list['id']): order.id = Read(file_list['id']).integer() # tip if path.exists(file_list['tip']): order.tip = load_tip(file_list['tip']) # distance if path.exists(file_list['distance']): order.distance = Read(file_list['distance']).decimal() # end time if path.exists(file_list['end_time']): order.end_time = Read(file_list['end_time']).datetime() # completed else: from objects import Tip # order data order_data = Read(order.file_list()['info']).comma() # tip order.tip = Tip(order_data[0], order_data[1], order_data[2]) # distance if order_data[3] != '': order.distance = float(order_data[3]) # end time if order_data[4] != '': order.end_time = To_Datetime(order_data[4]).from_datetime() return order
def test_revise_tip_build_confirmation(self): from objects import Tip from processes.revise import Revise_Tip tip = Tip() test = Revise_Tip(tip, test=True) # card # zero expected = 'Add a card tip' test.user_selection = '1' test.build_confirmation() self.assertEqual(test.confirmation, expected) # not zero expected = 'Edit card tip' tip = Tip(card=5) test = Revise_Tip(tip, test=True) test.user_selection = '1' test.build_confirmation() self.assertEqual(test.confirmation, expected) # cash # zero expected = 'Add a cash tip' tip = Tip() test = Revise_Tip(tip, test=True) test.user_selection = '2' test.build_confirmation() self.assertEqual(test.confirmation, expected) # not zero expected = 'Edit cash tip' tip = Tip(cash=5) test = Revise_Tip(tip, test=True) test.user_selection = '2' test.build_confirmation() self.assertEqual(test.confirmation, expected) # card and cash expected = 'Edit/add both card and cash tips' tip = Tip() test = Revise_Tip(tip, test=True) test.user_selection = '3' test.build_confirmation() self.assertEqual(test.confirmation, expected) # unknown # zero expected = 'Add a tip of unknown type' tip = Tip() test = Revise_Tip(tip, test=True) test.user_selection = 'u' test.build_confirmation() self.assertEqual(test.confirmation, expected) # not zero expected = 'Edit tip of unknown type' tip = Tip(unknown=5) test = Revise_Tip(tip, test=True) test.user_selection = 'u' test.build_confirmation() self.assertEqual(test.confirmation, expected) # save expected = 'Save changes' test.user_selection = 's' test.build_confirmation() self.assertEqual(test.confirmation, expected)
def result(self): # delivery if self.user_selection.lower() == 'd': from objects import Delivery import os from processes.track import start_delivery delivery = start_delivery(Delivery(self.shift)) delivery_menu = Delivery_Tracking_Menu(delivery) if delivery_menu.complete is True: self.shift.add_delivery(delivery_menu.delivery) # extra stop elif self.user_selection.lower() == 'e': from objects import Extra_Stop import os from processes.consolidate import consolidate_extra_stop from processes.load import load_extra_stop from processes.track import track_extra_stop extra_stop = Extra_Stop(self.shift).load_current() extra_stop = track_extra_stop(extra_stop) consolidate_extra_stop(extra_stop) self.shift.add_extra_stop(extra_stop) # carry out tip elif self.user_selection.lower() == 'c': from objects import Tip from utility.file import save tip = Tip().input_both() save(tip.csv(), self.shift.file_list()['tips'], '\n') self.shift.carry_out_tips.append(tip) # split elif self.user_selection.lower() == 's': from objects import Split from os import path from processes.consolidate import consolidate_split if not path.exists(Split(self.shift).file_list()['start_time']): self.shift.split = Split(self.shift).start() self.loop_condition = False else: self.shift.split.end() consolidate_split(self.shift.split) # end shift elif self.user_selection.lower() == 'x': from processes.consolidate import consolidate_shift from processes.track import end_shift self.shift = end_shift(self.shift) consolidate_shift(self.shift) self.loop_condition = False # view elif self.user_selection.lower() == 'v': View_Shift_Menu(self.shift) # revise elif self.user_selection.lower() == 'r': from processes.revise import Revise_Shift revise_shift = Revise_Shift(self.shift) self.shift = revise_shift.shift # quit elif self.user_selection.lower() == 'q': self.loop_condition = False return self