import pytest import sqlite3 from controllers.database.user import UserController from models.users.customer import Customer customer = Customer( "testuser", "Password1", "firstname", "lastname", "test@test", "123456789" ) # Tests a new user can be created def test_create_user(): db = UserController() db.create(customer) # Tests the database maintains integrity when we try and add a user with the same details def test_duplicate_user(): db = UserController() with pytest.raises(sqlite3.IntegrityError): db.create(customer) # Test we the same user details get returned from the database def test_read_user(): db = UserController() # Test the same user is returned user = db.read("testuser") assert isinstance(user, Customer) # Update the ID on the item as database assigns new id customer.id = user.id assert user.__dict__ == customer.__dict__