예제 #1
0
    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))
예제 #2
0
    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))
예제 #3
0
    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)
예제 #4
0
    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)
예제 #5
0
    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)
예제 #6
0
    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")
예제 #7
0
    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)
예제 #8
0
    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)
예제 #9
0
    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)