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 test_insert_customer(self) -> not None: # GIVEN arguments = "000000001,Ivanov Vasyl,developer,FGH,[email protected],79278763423".split( ",") customer = Customer(*arguments) # WHEN self.xml_storage.insert_customer(customer) # THEN customer = self.xml_storage.find_customer("customer_id", "000000001") self.assertIsNotNone(customer)
def test_delete_customer(self) -> None: # GIVEN arguments = "000000004,Green Alexandr,manager,FGH,[email protected],79056987458".split( ",") customer = Customer(*arguments) self.xml_storage.insert_customer(customer) # WHEN self.xml_storage.delete_customer(customer) # THEN customer = self.xml_storage.find_customer("customer_id", "000000004") self.assertIsNone(customer)
def test_get_everything(self) -> True: # GIVEN arguments = "000000004,Green Alexandr,manager,FGH,[email protected],79056987458".split( ",") customer = Customer(*arguments) self.xml_storage.insert_customer(customer) arguments_sorted = ["position", "full_name"] # WHEN customers = self.xml_storage.list_of_customer(arguments_sorted) # THEN self.assertGreaterEqual(len(customers), 1)
def test_update_customer(self) -> True: # GIVEN) arguments = "000000003,Romanov Dmitriy,manager,FGH,[email protected],79273987569".split( ",") customer = Customer(*arguments) self.xml_storage.insert_customer(customer) # WHEN updatable_arguments = dict() updatable_arguments["position"] = "general manager" self.xml_storage.update_customer(customer, updatable_arguments) customer = self.xml_storage.find_customer("customer_id", "000000003") # THEN self.assertEqual(customer.position, "general manager")
def test_find_customer(self) -> not None: # GIVEN arguments = "000000002,Ivanov Peter,manager,FGH,[email protected],79279826478".split( ",") customer = Customer(*arguments) self.xml_storage.insert_customer(customer) # WHEN argument_name = "customer_id" argument_value = "000000002" customer = self.xml_storage.find_customer(argument_name, argument_value) # THEN self.assertIsNotNone(customer)
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)