Exemple #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
Exemple #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
Exemple #3
0
def test_user_construction():
    user = User('dbowie', '1234567890')

    assert user.username == 'dbowie'
    assert user.password == '1234567890'
    assert len(user.comments) == 0
    assert repr(user) == '<User dbowie 1234567890>'
Exemple #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_repository_can_add_a_user(session):
    repo = SqlAlchemyRepository(session)

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

    assert repo.get_user('Dave') is user
Exemple #6
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
Exemple #7
0
def add_user(username: str, password: str, repo: AbstractRepository):
    user = repo.get_user(username)
    if user is not None:
        raise NameNotUniqueException

    password_hash = generate_password_hash(password)

    user = User(username, password_hash)
    repo.add_user(user)
Exemple #8
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)
Exemple #9
0
def add_user(username: str, password: str,
             uow: unit_of_work.AbstractUnitOfWork):
    with uow:
        # Check that the given username is available.
        user = uow.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)
        uow.repo.add_user(user)
        uow.commit()
Exemple #10
0
def test_make_comment_establishes_relationships():
    comment_text = 'COVID-19 in the USA!'
    user = User('bspringsteen', '0987654321')
    article = Article(
        date.fromisoformat('2020-03-15'),
        'Coronavirus travel restrictions: Self-isolation deadline pushed back to give airlines breathing room',
        'The self-isolation deadline has been pushed back',
        'https://www.nzherald.co.nz/business/news/article.cfm?c_id=3&objectid=12316800',
        'https://th.bing.com/th/id/OIP.0lCxLKfDnOyswQCF9rcv7AHaCz?w=344&h=132&c=7&o=5&pid=1.7'
    )

    comment = make_comment(comment_text, user, article)

    # Check that the User object knows about the Comment.
    assert comment in user.comments

    # Check that the Comment knows about the User.
    assert comment.user is user

    # Check that Article knows about the Comment.
    assert comment in article.comments

    # Check that the Comment knows about the Article.
    assert comment.article is article
Exemple #11
0
def test_repository_can_retrieve_a_user(session_factory):
    repo = SqlAlchemyRepository(session_factory)

    user = repo.get_user('fmercury')
    assert user == User('fmercury', '8734gfe2058v')
Exemple #12
0
def user():
    return User('dbowie', '1234567890')
Exemple #13
0
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
Exemple #14
0
def test_repository_can_retrieve_a_user(in_memory_repo):
    user = in_memory_repo.get_user('fmercury')
    assert user == User('fmercury', '8734gfe2058v')
Exemple #15
0
def make_user():
    user = User("Andrew", "111")
    return user
Exemple #16
0
def test_review(self):
    movie1 = Movie("super cool movie", 2020)
    text = "wow this is a super cool movie"
    user1 = User("cooldude", "ABcd1234")
    review1 = Review(movie1, text, user1, 8)
    assert review1.review_text == "wow this is a super cool movie"
Exemple #17
0
def test_user_construction(self):
    user1 = User("cooldude", "ABcd1234")
    assert user1.user_name == 'cooldude'
    assert user1.password == 'ABcd1234'