def test_update_customer(self, MockStorageStrategy: Mock) -> None: # GIVEN expected_customer = Customer(self.customer_id, self.full_name, self.position, self.name_of_the_organization, self.email, self.phone ) new_phone = "79278763447" customer_storage_mock = MockStorageStrategy() customer_storage_mock.find_customer.return_value = expected_customer customer_service = CustomerService(customer_storage_mock) # WHEN customer_service.update_customer(self.customer_id, self.full_name, self.position, self.name_of_the_organization, self.email, new_phone ) # THEN self.assertTrue(customer_storage_mock.update_customer.assert_called_once) updated_phone = customer_storage_mock.update_customer.call_args.args[5] self.assertEqual(updated_phone, new_phone) customer_to_update = customer_storage_mock.update_customer.call_args.args[0] self.assertTrue(eq(expected_customer, customer_to_update))
def test_create_customer(self, MockStorageStrategy: Mock) -> None: # GIVEN expected_customer = Customer(self.customer_id, self.full_name, self.position, self.name_of_the_organization, self.email, self.phone ) customer_storage_mock = MockStorageStrategy() customer_storage_mock.find_customer.return_value = None customer_service = CustomerService(customer_storage_mock) # WHEN customer_service.create_customer(self.customer_id, self.full_name, self.position, self.name_of_the_organization, self.email, self.phone ) # THEN self.assertTrue(customer_storage_mock.insert_customer.assert_called_once) customer_to_insert = customer_storage_mock.insert_customer.call_args.args[0] self.assertTrue(eq(expected_customer, customer_to_insert))
def main(): arg_parser = argparse.ArgumentParser( description= 'The program is designed to store, view and edit customer data') arg_parser.add_argument('--path', type=str, default=environ.get('path'), help='XML file path') arg_parser.add_argument('--db', type=str, default=environ.get('db'), help='database name') arg_parser.add_argument('--user', type=str, default=environ.get('user'), help='user name') arg_parser.add_argument('--password', type=str, default=environ.get('password'), help='password user') arg_parser.add_argument('--host', type=str, default=environ.get('host'), help='host') arg_parser.add_argument('--port', type=str, default=environ.get('port'), help='port') args = arg_parser.parse_args() storage = StorageFactory.get_storage(args) customer_service = CustomerService(storage) while True: input_command = input("Please enter the command:").split(maxsplit=1) if len(input_command) == 0: continue try: command = EXPECTED_COMMANDS[input_command[0]]() command.execute(customer_service) except KeyError: print("INVALID COMMAND!\n") EXPECTED_COMMANDS["help"]().execute(customer_service) except ValidateException as e: print(e) except CommandException as e: print(e) except CustomerException as e: print("ERROR:", e) except Exception as e: print(e)
def test_create_customer_raise_exception(self, MockStorageStrategy: Mock) -> None: # GIVEN customer_storage_mock = MockStorageStrategy(side_effect=CustomerException) customer_service = CustomerService(customer_storage_mock) # WHEN try: customer_service.create_customer(self.customer_id, self.full_name, self.position, self.name_of_the_organization, self.email, self.phone ) except CustomerException: # THEN self.assertRaises(CustomerException)
def test_display_customer_details(self, MockStorageStrategy: Mock) -> None: # GIVEN expected_customer = Customer(self.customer_id, self.full_name, self.position, self.name_of_the_organization, self.email, self.phone ) customer_storage_mock = MockStorageStrategy() customer_storage_mock.find_customer.return_value = expected_customer customer_service = CustomerService(customer_storage_mock) # WHEN customer_service.find_customer("customer_id", self.customer_id) # THEN self.assertTrue(customer_storage_mock.find_customer.assert_called_once)
def test_display_customer_data_ordered(self, MockStorageStrategy: Mock) -> None: # GIVEN expected_customer = Customer(self.customer_id, self.full_name, self.position, self.name_of_the_organization, self.email, self.phone ) customer_storage_mock = MockStorageStrategy() customer_storage_mock.list_of_customer.return_value = [expected_customer] customer_service = CustomerService(customer_storage_mock) # WHEN list_options = ["full_name"] customer_service.get_list_of_customers(list_options) # THEN self.assertTrue(customer_storage_mock.list_of_customer.assert_called_once) params = customer_storage_mock.list_of_customer.call_args.args[0] self.assertEqual(params, list_options)