def test_repository_can_retrieve_a_user(session_factory):
    repo = SqlAlchemyRepository(session_factory)

    user = repo.get_user('fmercury')
    user2 = User('fmercury', '8734gfe2058v')
    user2.username = '******'
    user2.password = '******'
    assert user == user2
def test_repository_can_add_a_user(session_factory):
    repo = SqlAlchemyRepository(session_factory)

    user = User('Dave', '123456789')
    user.username = '******'
    user.password = '******'
    repo.add_user(user)

    user2 = repo.get_user('Dave')

    assert user2 == user
예제 #3
0
def add_user(username: str, password: str, repo: AbstractRepository):
    # Check that the given username is available.
    user = repo.get_user(username)
    if user is not None:
        raise NameNotUniqueException

    # Encrypt password so that the database doesn't store passwords 'in the clear'.
    password_hash = generate_password_hash(password)

    # Create and store the new User, with password encrypted.
    user = User(username, password_hash)
    user.username = username
    user.password = password_hash
    repo.add_user(user)
예제 #4
0
def test_saving_of_users_with_common_username(empty_session):
    insert_user(empty_session, ("Andrew", "1234"))
    empty_session.commit()

    with pytest.raises(IntegrityError):
        user = User("Andrew", "111")
        empty_session.add(user)
        empty_session.commit()
예제 #5
0
def load_users(data_path: str, repo: MemoryRepository):
    users = dict()

    for data_row in read_csv_file(os.path.join(data_path, 'users.csv')):
        user = User(username=data_row[1],
                    password=generate_password_hash(data_row[2]))
        repo.add_user(user)
        users[data_row[0]] = user
    return users
예제 #6
0
def test_loading_of_users(empty_session):
    users = list()
    users.append(("Andrew", "1234"))
    users.append(("Cindy", "1111"))
    insert_users(empty_session, users)

    user1 = User("Andrew", "1234")
    user2 = User("Cindy", "999")
    user1.username = '******'
    user1.password = '******'
    user2.username = '******'
    user2.password = '******'
    assert empty_session.query(User).all() == [user1, user2]
예제 #7
0
def user():
    return User('dbowie', '1234567890')
예제 #8
0
def make_user():
    user = User('Bob', '212434')
    user.password = '******'
    user.username = '******'
    return user