Exemplo n.º 1
0
def load_users_and_review(repo: MemoryRepository):
    review = Review(
        movie=repo.get_movie(1),
        txt='Best Movie Ever!',
        rating=10
    )
    user = User(username='******', password=generate_password_hash('smar387PWord'))
    user.add_review(review)
    repo.add_review(review)
    repo.add_user(user)
Exemplo n.º 2
0
def load_users(data_path: str, repo: MemoryRepository):
    users = dict()

    for line in read_csv_file(os.path.join(data_path, 'users.csv')):
        user = User(
            username=line[1],
            password=generate_password_hash(line[2])
        )
        repo.add_user(user)
        users[line[0]] = user
    return users
Exemplo n.º 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)
    repo.add_user(user)
def load_users(data_path: str, repo: MemoryRepository):
    users = dict()
    ignore_row = 0
    for data_row in read_csv_file(os.path.join(data_path, 'users.csv')):
        if ignore_row == 0:
            ignore_row += 1
            continue
        user = User(username=data_row[1],
                    password=generate_password_hash(data_row[2]))
        repo.add_user(user)
        users[data_row[0]] = user
    return users
Exemplo n.º 5
0
def test_init(review):
    user = User('Steve', 'pass123')
    movie = Movie("Moana", 2016)
    review_text = "This movie was very enjoyable."
    rating = 8
    timestamp = datetime.today()
    review = Review(user, movie, review_text, timestamp, rating)

    ## test cr3
    assert repr(review.movie) == "<Movie Moana, 2016>"
    assert "Review: {}".format(
        review.review_text) == "Review: This movie was very enjoyable."
    assert "Rating: {}".format(review.rating) == "Rating: 8"

    ##test movie
    actor = Actor("Will Smith")
    review.movie = actor  ##illegal
    assert repr(review.movie) == "<Movie Moana, 2016>"
    movie = Movie("Will Smith smith Will Smith?", 1900)
    review.movie = movie  ##legal
    assert repr(review.movie) == "<Movie Will Smith smith Will Smith?, 1900>"

    ##test review text
    review.review_text = 1900  ##illegal
    assert review.review_text == "This movie was very enjoyable."
    review.review_text = "Will Smith will smith Will Smith"  ##legal
    assert review.review_text == "Will Smith will smith Will Smith"

    ##test rating
    review.rating = 10.1
    assert review.rating == 8
    review.rating = 9
    assert review.rating == 9

    ##test __eq__
    movie = Movie("Will Smith smith Will Smith?", 1900)
    review_text = "Will Smith will smith Will Smith"
    rating = 9
    review1 = Review(user, movie, review_text, timestamp, rating)
    assert review == review1
Exemplo n.º 6
0
def user():
    return User('dbowie', '1234567890')
Exemplo n.º 7
0
def review():
    timestamp = datetime.today()
    return Review(User("", ""), Movie("", 0), "", timestamp, 0)
Exemplo n.º 8
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
Exemplo n.º 9
0
def test_repository_can_retrieve_a_user(in_memory_repo):
    user = in_memory_repo.get_user('fmercury')
    assert user == User('fmercury', '8734gfe2058v')