def test_user_equality(self): """ Test if two users are equal if the reference is the same. """ user1 = model.User("1", "john", "secret") user2 = model.User("1", "john", "secret") assert user1 == user2
def test_user_has_role_instance(self): """ Test if user has a role instance """ user = model.User("1", "john", "secret") user.role = model.Role("admin") assert isinstance(user.role, model.Role)
def test_user_version_increment_wehn_update(self): """ Test if version increments when update attributes """ user = model.User("1", "john", "secret") user.username = "******" assert 1 == user.version
def test_user_attributes(self): """ Test user attributes """ user = model.User("1", "john", "secret") assert hasattr(user, "reference") assert hasattr(user, "username") assert hasattr(user, "password") assert hasattr(user, "role")
def test_orm_can_load_lines(sqlite_session_factory): """ Test if orm maps correctly the entity. """ session = sqlite_session_factory() session.execute( "INSERT INTO users (reference, version, username, password) VALUES " "('1', '1', 'steve', 'secret')") expected = [model.User("1", "steve", "secret")] assert expected == session.query(model.User).all()
def test_orm_mapper_can_save_a_user(sqlite_session_factory): """ Test if orm mappers can save an user in database. """ session = sqlite_session_factory() user = model.User(reference="1", username="******", password="******") session.add(user) session.commit() rows = list(session.execute("SELECT username, password from users")) assert [("john", "secret")] == rows
def test_uow_can_add_an_user(sqlite_session_factory): """ Test if unit of work can add a new user. """ session = sqlite_session_factory() uow = SqlUnitOfWork(session) user = model.User(reference="1", username="******", password="******") with uow: uow.repo.add(user) uow.commit() row = list( session.execute("SELECT reference, username, password FROM users")) expected = [("1", "john", "secret")] assert expected == row
def test_uow_role_saved_along_with_user(sqlite_session_factory): """ Test if the role is saved along with the user. """ session = sqlite_session_factory() uow = SqlUnitOfWork(session) user = model.User("1", "steve", "secret") user.role = model.Role("admin") with uow: uow.repo.add(user) uow.commit() rows = list(session.execute("SELECT name FROM roles")) expected = [('admin', )] assert expected == rows
def test_user_entity_instance(self): """ Test if user is instance of Entity """ user = model.User("123", "john", "secret") assert isinstance(user, model.Entity)
def test_user_representation(self): """ Test user representation. """ user = model.User(reference="1", username="******", password="******") assert "<User(username=john)>" == repr(user)