def get_customer_by_email(self, email_address):
        """
        Gets customer by email address returns none if not found
        :param email_address: Email address in scope
        :return: Customer or None
        """
        customer_store = CustomerStore()

        customer = customer_store.get(email_address)

        return customer
    def create_or_get_customer(self, customer):
        """
        Get customer if it exists in database, otherwise create.
        :param customer: Customer object we're looking for
        :returns customer: Customer
        """
        customer_store = CustomerStore()

        database_customer = customer_store.get(customer.email_address)

        if database_customer:
            return database_customer

        # Cust doesn't exist so save them
        try:
            customer_store.save(customer)
            return Customer(customer)
        except CustomerStoreError:
            app.logger.debug('Error creating customer {0}'.format(customer.email_address))
            raise CustomerServiceError("Error creating customer")
class TestCustomerStore(unittest.TestCase):

    test_cust = None
    customer_store = None

    @patch.object(CustomerStore, 'config', DYNAMODB_CONFIG)
    def setUp(self):
        self.test_cust = Customer({'emailAddress': '*****@*****.**', 'firstName': 'Testy', 'surname': 'McTest'})
        self.customer_store = CustomerStore()
        self.customer_store.save(self.test_cust)  # This demonstrates save functionality

    def tearDown(self):
        self.customer_store.delete(self.test_cust.email_address)

    def test_get_returns_test_customer(self):
        # Act
        cust = self.customer_store.get(self.test_cust.email_address)

        # Assert
        self.assertEqual(cust, self.test_cust)

    def test_get_returns_none_if_customer_not_found(self):
        # Act
        cust = self.customer_store.get('*****@*****.**')

        # Assert
        self.assertEqual(cust, None, 'Unmatched customer should return None, not raise an exception')
 def setUp(self):
     self.test_cust = Customer({'emailAddress': '*****@*****.**', 'firstName': 'Testy', 'surname': 'McTest'})
     self.customer_store = CustomerStore()
     self.customer_store.save(self.test_cust)  # This demonstrates save functionality