Ejemplo n.º 1
0
def test_loading_of_users(empty_session):
    users = list()
    users.append(("Andrew", "1234"))
    users.append(("Cindy", "1111"))
    insert_users(empty_session, users)

    expected = [User("Andrew", "1234"), User("Cindy", "999")]
    assert empty_session.query(User).all() == expected
Ejemplo n.º 2
0
def test_repository_can_add_a_user(session_factory):
    repo = SqlAlchemyRepository(session_factory)

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

    repo.add_user(User('Martin', '123456789'))

    user2 = repo.get_user('Dave')

    assert user2 == user and user2 is user
Ejemplo n.º 3
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(user_name=data_row[1], password=generate_password_hash(data_row[2]))
        repo.add_user(user)
        users[data_row[0]] = user
    return users
Ejemplo n.º 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()
def test_hash_():
    user1 = User("None", "qwer")
    user2 = User("HI", "qwer")
    user3 = User("Jack", "qwer")
    user4 = User("  jack      ", "qwer")

    seta = {user1, user2, user3, user4}
    assert seta == {
        User("None", "qwer"),
        User("HI", "qwer"),
        User("Jack", "qwer"),
        User("  jack      ", "qwer")
    }
Ejemplo n.º 6
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)
    repo.add_user(user)
def test_add_review():
    user = User("Jack Huang", "123124")
    movie1 = Movie("Your Name", 2000)
    movie2 = Movie("Spirited Away", 1995)
    movie3 = Movie("Avengers 4", 1899)

    review1 = Review(user, movie1, "Good 1", 1)
    review2 = Review(user, movie2, "Good 2", 2)
    review3 = Review(user, movie3, "Good 3", 3)

    assert user.reviews == []
    user.add_review(review1)
    user.add_review(review2)
    user.add_review(review3)
    assert user.reviews == [
        Review(user, movie1, "Good 1", 1),
        Review(user, movie2, "Good 2", 2),
        Review(user, movie3, "Good 3", 3)
    ]
def test_add_movies_and_length():
    user = User("Jack Huang", "123124")
    movie1 = Movie("Your Name", 2000)
    movie2 = Movie("Spirited Away", 1995)
    movie3 = Movie("Avengers 4", 1899)
    movie1.runtime_minutes = 100
    movie2.runtime_minutes = 150
    movie3.runtime_minutes = 300

    assert user.watched_movies == []
    user.watch_movie(movie1)
    user.watch_movie(movie2)
    user.watch_movie(movie3)
    assert user.watched_movies == [
        Movie("Your Name", 2000),
        Movie("Spirited Away", 1995),
        Movie("Avengers 4", None)
    ]
    assert user.time_spent_watching_movies_minutes == 550
def test_lt_none_name():
    user1 = User(None, 12345)
    user2 = User("HI", "qwer")

    lt = user1 < user2
    assert lt == True
def test_user_password_string_int():
    user = User("Jack Huang", "123124")

    assert user.user_name == "jack huang"
    assert user.password == "123124"
def test_empty_watched_movies_and_reviews():
    user = User("Jack Huang", "123124")

    assert user.watched_movies == []
    assert user.reviews == []
Ejemplo n.º 12
0
def make_user():
    user = User("Andrew", "111")
    return user
def test_repository_can_add_a_user(in_memory_repo):
    user = User('Dave', '123456789')
    in_memory_repo.add_user(user)

    assert in_memory_repo.get_user('Dave') is user
def test_repository_can_retrieve_a_user(in_memory_repo):
    user = in_memory_repo.get_user('fmercury')
    assert user == User('fmercury', '8734gfe2058v')
Ejemplo n.º 15
0
def test_repository_can_add_a_user(in_memory_repo):
    user = User('Jack', '111241')
    in_memory_repo.add_user(user)

    assert in_memory_repo.get_user('Jack') is user
Ejemplo n.º 16
0
def test_repository_can_retrieve_a_user(session_factory):
    repo = SqlAlchemyRepository(session_factory)

    user = repo.get_user('fmercury')
    assert user == User('fmercury', '8734gfe2058v')
def test_user_password_non_string():
    user = User(1234124, 123124)

    assert user.user_name is None
    assert user.password is None
def test_lt_diff_name():
    user1 = User("Hi", 12345)
    user2 = User("HI", "qwer")

    lt = user1 < user2
    assert lt == False
def test_lt_same_name():
    user1 = User(" QweR      ", "aaaaa")
    user2 = User("     qWEr ", "A")

    lt = user1 < user2
    assert lt == False
def test_eq_diff_name():
    user1 = User(" Q weR      ", 12345)
    user2 = User("     qWEr ", "qwer")

    eq = user1 == user2
    assert eq == False
def test_eq_same_name_caps_space():
    user1 = User(" QweR      ", 12345)
    user2 = User("     qWEr ", "qwer")

    eq = user1 == user2
    assert eq == True
def test_eq_same_name():
    user1 = User("qwer", 12345)
    user2 = User("qwer", "qwer")

    eq = user1 == user2
    assert eq == True
def user():
    return User('dbowie', '1234567890')
def test_user_password_normal():
    user = User("    Jack Huang     ", "gOod one")

    assert user.user_name == "jack huang"
    assert user.password == "gOod one"