def test_add_review(self): user1 = User('Martin', 'pw12345') movie = Movie("Moana", 2016, 1) user1.add_review(Review(movie, "Ahhh", 2)) print() print(user1.reviews) print(movie.external_rating)
def test_init(self): user1 = User('Martin', 'pw12345') user2 = User('Ian', 'pw67890') user3 = User('Daniel', 'pw87465') print() print(user1) print(user2) print(user3)
def test_hash(self): user1 = User('Martin', 'pw12345') user2 = User('Ian', 'pw67890') user3 = User('Daniel', 'pw87465') test_set = set() test_set.add(user1) test_set.add(user2) test_set.add(user3) print() print(test_set)
def test_can_add_review(): mem_repo = MemoryRepository() up_movie = Movie("Up", 2009, 1) klaus_movie = Movie("Klaus", 2019, 2) dolittle_movie = Movie("Dolittle", 2019, 3) mem_repo.add_movie(up_movie) mem_repo.add_movie(klaus_movie) mem_repo.add_movie(dolittle_movie) # ["Dolittle", "Klaus", "Up"] movie_id = 3 review_text = "Very good!" username = "******" rating = 5 mem_repo.add_user(User(username, "CS235")) # call the service layer to add the comment movie_services.add_review(movie_id, review_text, rating, username, mem_repo) # retrieve the reviews for the movie from the repository reviews_as_dict = movie_services.get_reviews_for_movie(movie_id, mem_repo) # check that the reviews inclue a review with the new review text. assert next((dictionary['review_text'] for dictionary in reviews_as_dict if dictionary['review_text'] == review_text), None) is not None
def test_repository_does_not_retrieve_a_non_existent_user(): mem_repo = MemoryRepository() user = User("Bob", "42069") mem_repo.add_user(user) got_user = mem_repo.get_user("Terry") assert got_user is None
def register(): form = RegistrationForm() error = None # Successful POST, username and password valid. if form.validate_on_submit(): password = generate_password_hash(form.password.data) user = User(form.username.data, password) unique_username = repo.repo_instance.add_user(user) if unique_username: session.clear() session['username'] = user.username return redirect(url_for('index_bp.index')) else: error = 'Your username is already taken - please supply another' # For a GET or a failed POST request, return the Registration Web page. return render_template( 'credentials.html', title='Register', form=form, username_error_message=error, password_error_message=None, handler_url=url_for('authentication_bp.register'), )
def test_repository_can_get_user(): mem_repo = MemoryRepository() user = User("Terry", "42069") mem_repo.add_user(user) got_user = mem_repo.get_user("Terry") assert got_user == user
def load_users(data_path, repo): filename = os.path.join(data_path, "users.csv") with open(filename, mode='r', encoding='utf-8-sig') as csvfile: movie_file_reader = csv.DictReader(csvfile) for row in movie_file_reader: if not any(row.values()): break user = User(row["username"], generate_password_hash(row["password"])) for media_id in row["movies"].split(";"): media = repo.get_media(int(media_id)) user.watch_movie(media) repo.add_user(user)
def add_user(username: str, password: str, repo: AbstractRepository): # check that the gievn username is available user = repo.get_user(username) if user is not None: raise NameNotUniqueException # encrpyt the 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_watch_movie(self): user1 = User('Martin', 'pw12345') user1.watch_movie(Movie("Moana", 2016, 1)) print() print(user1.watched_movies) movies = [Movie("Moana", 2016, 1), Movie("Guardians of the Galaxy", 2014, 2)] movies[0].runtime_minutes = 107 movies[1].runtime_minutes = 121 user = User("Martin", "pw12345") print(user.watched_movies) print(user.time_spent_watching_movies_minutes) for movie in movies: user.watch_movie(movie) print(user.watched_movies) print(user.time_spent_watching_movies_minutes)
def user(): return User('dbowie', '1234567890')
def test_repository_can_add_user(): mem_repo = MemoryRepository() user = User("Jimmy", "42069") mem_repo.add_user(user) assert mem_repo.get_user("Jimmy") is user
def test_repo_retrieve_fake_user_review(in_memory_repo): user = User('Dave', '123456789') reviews = in_memory_repo.get_reviews_by_user(user) assert len(reviews) == 0
def test_repo_retrieve_different_user(in_memory_repo): user = in_memory_repo.get_user("guest") assert user == User("guest", "password")
def test_repo_retrieve_user(in_memory_repo): user = in_memory_repo.get_user("admin") assert user == User("admin", "admin")
def test_repo_add_user(in_memory_repo): user = User('Dave', '123456789') in_memory_repo.add_user(user) assert in_memory_repo.get_user('Dave') is user