Esempio n. 1
0
    def read_user_csv_file(self):
        with open(self.__file_name, mode='r', encoding='utf-8-sig') as csvfile:
            user_file_reader = csv.DictReader(csvfile)

            for row in user_file_reader:
                user_class = User(row['username'], row['password'])
                user_class.id = int(row['id'])
Esempio n. 2
0
def add_user(username: str, password: str, repo: AbstractRepository):
    user = repo.get_user(username.lower())
    if user is not None:
        raise NameNotUniqueException

    hashed_password = generate_password_hash(password)

    user = User(username, hashed_password)
    repo.add_user(user)
Esempio n. 3
0
def test_user_comments():
    user = User("Hazel", "1234")
    movie = Movie("Her", 2013)
    comment = Comment(movie, "What are some similar movies to this?")
    user.add_comment(comment)
    assert comment in user.comments
    user.add_comment(comment)
    assert len(user.comments) == 1
Esempio n. 4
0
def test_user_watchlist():
    user = User("Hazel", "1234")
    watchlist = WatchList()
    user.add_watchlist(watchlist)
    assert user.watchlist == watchlist
    watchlist2 = WatchList()
    user.add_watchlist(watchlist2)
    assert user.watchlist == watchlist
Esempio n. 5
0
def test_add_user(populated_repo):
    # add new user
    user = User('Hazel', '12345')
    log_serv.add_user('Hazel', '12345', populated_repo)
    assert log_serv.get_user('Hazel', populated_repo) == user
    # user doesnt exist
    with pytest.raises(log_serv.UnknownUserException):
        log_serv.get_user('Error', populated_repo)
    # username taken
    with pytest.raises(log_serv.NameNotUniqueException):
        log_serv.add_user('Hazel', '12345', populated_repo)
    # invalid password
    with pytest.raises(log_serv.ValidationException):
        log_serv.validate_user('Hazel', "123456", populated_repo)
    #valid password
    try:
        log_serv.validate_user("Hazel", "12345", populated_repo)
    except ValidationException:
        assert False
Esempio n. 6
0
def test_get_user(populated_repo):
    user = User('hazel', 'password')
    populated_repo.add_user(user)
    assert populated_repo.get_user('hazel') is user
Esempio n. 7
0
 def __init__(self):
     self.__movies = list()
     self.__movie_index = dict()
     self.__users = [User('richard', 'test1234')]