コード例 #1
0
 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
コード例 #2
0
 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)
コード例 #3
0
 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
コード例 #4
0
 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")
コード例 #5
0
ファイル: test_orm.py プロジェクト: ppmadalin/sql-alchemy-orm
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()
コード例 #6
0
ファイル: test_orm.py プロジェクト: ppmadalin/sql-alchemy-orm
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
コード例 #7
0
ファイル: test_uow.py プロジェクト: ppmadalin/sql-alchemy-orm
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
コード例 #8
0
ファイル: test_uow.py プロジェクト: ppmadalin/sql-alchemy-orm
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
コード例 #9
0
 def test_user_entity_instance(self):
     """
     Test if user is instance of Entity
     """
     user = model.User("123", "john", "secret")
     assert isinstance(user, model.Entity)
コード例 #10
0
 def test_user_representation(self):
     """
     Test user representation.
     """
     user = model.User(reference="1", username="******", password="******")
     assert "<User(username=john)>" == repr(user)