def test_movies_basic(): client, repo = client_with_db_data() response = client.get('/movies?page=0') #print(response.data) session = repo.session_factory() expected_result = session.query(Movie).all() for i in range(MOVIES_ON_PAGE): # TODO assert bytes(expected_result[i].title, 'utf8') in response.data
def test_register(): client, _ = client_with_db_data() response = client.post('/register', data={'username': '******', 'password': '******'}) assert response.headers['Location'] == url('/login') response = client.post('/register', data={'username': '******', 'password': '******'}) # 200 = no redirect assert response.status_code == 200 assert bytes(ErrorMessages.duplicate_username, 'utf') in response.data
def test_logout(): client, _ = client_with_db_data() response = client.post('/register', data={'username': '******', 'password': '******'}) assert response.headers['Location'] == url('/login') with client: response = client.post('/login', data={'username': '******', 'password': '******'}) assert response.headers['Location'] == url('/movies') assert 'user' in session response = client.get('/logout') assert response.headers['Location'] == url('/login') assert 'user' not in session
def test_register_invalid(): client, _ = client_with_db_data() response = client.post('/register', data={'username': '******', 'password': '******'}) assert response.status_code == 200 assert bytes(ErrorMessages.invalid_password, 'utf') in response.data response = client.post('/register', data={'username': '', 'password': '******'}) assert response.status_code == 200 assert bytes(ErrorMessages.non_empty_username, 'utf') in response.data response = client.post('/register', data={'username': '******', 'password': '******'}) assert response.status_code == 200 assert bytes(ErrorMessages.invalid_username, 'utf') in response.data
def test_login_invalid(): client, _ = client_with_db_data() with client: response = client.post('/register', data={'username': '******', 'password': '******'}) assert response.headers['Location'] == url('/login') assert 'user' not in session response = client.post('/login', data={'username': '******', 'password': '******'}) assert response.status_code == 200 assert 'user' not in session assert bytes(ErrorMessages.invalid_login, 'utf') in response.data response = client.post('/login', data={'username': '******', 'password': '******'}) #print( response.headers) assert response.status_code == 200 assert 'user' not in session
def test_movie_add_review(): client, repo = client_with_db_data() client.post('/register', data={ 'username': '******', 'password': '******' }) client.post('/register', data={'username': '******', 'password': '******'}) client.post('/login', data={'username': '******', 'password': '******'}) client.post('/movies/24/review', data={ 'review_text': 'Its Jedi Propaganda!', 'rating': '3' }) response = client.get('/movies/24') assert bytes('Its Jedi Propaganda!', 'utf8') in response.data
def test_movies_filter_genre(): client, repo = client_with_db_data() response = client.get('/movies?page=0&genre=Adventure&genre=Action') #print(response.data) assert bytes('Suicide Squad', 'utf8') in response.data assert bytes('Guardians of the Galaxy', 'utf8') in response.data