def execute(self) -> Customer: try: Customer.get_by_email(self.email) raise AlreadyExists except NotFound: pass customer = Customer( first_name=self.first_name, last_name=self.last_name, phone_number=self.phone_number, email=self.email, address=self.address, city=self.city ).create_customer( ) return customer
def test_create_customer(): """ GIVEN CreateCustomerCommand with a valid properties author, title and content WHEN the execute method is called THEN a new Customer must exist in the database with the same attributes """ cmd = CreateCustomerCommand(first_name="Emmanuel", last_name="Caster", phone_number="08182104309", email="*****@*****.**", address="Row 3 House 6 Staff Qtrs", city="Lagos") customer = cmd.execute() db_customer = Customer.get_by_email(customer.email) assert db_customer["first_name"] == customer.first_name assert db_customer["last_name"] == customer.last_name assert db_customer["phone_number"] == customer.phone_number assert db_customer["email"] == customer.email assert db_customer["address"] == customer.address assert db_customer["city"] == customer.city