예제 #1
0
    def test_when_customer_does_not_exists_and_all_details_correct_creates_customer(
            self, database, payment_processors):
        assert Customer.find_by_email(self.email) is None

        customer = CustomerCreate.call(self.token, self.processor_name,
                                       self.details)

        assert customer is not None
        assert Customer.find_by_email(self.email) == customer
예제 #2
0
    def test_when_customer_does_not_exists_and_with_extra_details_creates_customer(
            self, database, payment_processors):
        assert Customer.find_by_email(self.email) is None

        customer = CustomerCreate.call(
            self.token, self.processor_name, {
                **self.details, 'extra-attr': 'something'
            })

        assert customer is not None
        assert Customer.find_by_email(self.email) == customer
예제 #3
0
    def test_finds_by_email_returns_the_expected_customer(self, database):
        customer = Customer.create(
            first_name = self.first_name,
            last_name = self.last_name,
            company = self.company,
            email = self.email,
            phone = self.phone,
            fax = self.fax,
            website = self.website
        )

        assert Customer.query.count() == 1
        assert Customer.find_by_email('*****@*****.**') is None
        assert Customer.find_by_email(self.email) == customer
예제 #4
0
    def test_creates_customers_when_all_details_are_valid(
            self, testapp, database, payment_processors):
        client = testapp.test_client()
        response = client.post('/customers', json=self.params)
        customer = Customer.find_by_email(self.params['email'])

        assert response.status_code == HTTPStatus.CREATED
        assert response.json == customer.as_dict()
예제 #5
0
    def test_when_customer_details_are_valid_and_optional_present_creates_customer(
            self, database, optional_details, payment_processors):
        customer_counter = Customer.query.count()

        customer = CustomerCreate.call(self.token, self.processor_name, {
            **self.details,
            **optional_details
        })

        assert Customer.query.count() == customer_counter + 1
        assert customer is not None
        assert Customer.find_by_email(self.email) == customer
예제 #6
0
    def create_customer(self):
        customer = Customer.find_by_token(self.customer_token)

        if customer is None:
            customer = Customer.find_by_email(self.details['email'])

        if customer is None:
            processor_information = self._register_customer_with_processor(
                self.processor_name, self.details)

            customer = Customer.create(**self.details)

            PaymentProcessorCustomerInformationCreate.call(
                self.processor_name, customer, processor_information)

        return customer