def test_add_and_get_users(session_factory):
    repository = SqlAlchemyRepository(session_factory)
    assert repository.get_users() == []
    repository.add_user(User("Brian Marshall", "123"))
    repository.add_user(User("Mark Tremonti", "456"))
    repository.add_user(User("Mark Tremonti", "456"))
    assert repository.get_user("Brian Marshall") == User(
        "Brian Marshall", "123")
    assert repository.get_user("Scott Phillips") is None
    assert repository.get_users() == [
        User("Brian Marshall", "123"),
        User("Mark Tremonti", "456")
    ]
def test_can_retrieve_an_movie_and_add_a_comment_to_it(session_factory):
    repo = SqlAlchemyRepository(session_factory)

    # Fetch Movie and User.
    movie = repo.get_movie(5)
    author = repo.get_user('thorke')

    # Create a new Comment, connecting it to the Movie and User.
    comment = make_comment('First death in Australia', author, movie)

    movie_fetched = repo.get_movie(5)
    author_fetched = repo.get_user('thorke')

    assert comment in movie_fetched.comments
    assert comment in author_fetched.comments
def test_repository_can_add_a_comment(session_factory):
    repo = SqlAlchemyRepository(session_factory)

    user = repo.get_user('thorke')
    movie = repo.get_movie(2)
    comment = make_comment("Trump's onto it!", user, movie)

    repo.add_comment(comment)

    assert comment in repo.get_comments()
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
def test_repository_does_not_retrieve_a_non_existent_user(session_factory):
    repo = SqlAlchemyRepository(session_factory)

    user = repo.get_user('Sam')
    assert user is None
def test_repository_can_retrieve_a_user(session_factory):
    repo = SqlAlchemyRepository(session_factory)

    user = repo.get_user('fmercury')
    assert user == User('fmercury', '8734gfe2058v')