def test_deletes_like(self, client, comment, user, like, delete_data): assert len(user.likes) == 1 login_user(client, user) client.delete( url_for("like.delete", user_id=user.id), data=json.dumps(delete_data), content_type="application/json" ) assert len(user.likes) == 0
def response(self, client, user, create_data): login_user(client, user) return client.post( url_for('like.create', user_id=user.id), data=json.dumps(create_data), content_type='application/json' )
def response(self, client, user, comment): LikeFactory(user=user, comment=comment) login_user(client, user) return client.post( url_for('like.create', user_id=user.id), data=json.dumps({'comment_id': comment.id}), content_type='application/json' )
def test_decreases_comment_like_count(self, client, comment, user, like, delete_data): db.session.commit() assert comment.like_count == 1 login_user(client, user) client.delete( url_for("like.delete", user_id=user.id), data=json.dumps(delete_data), content_type="application/json" ) assert comment.like_count == 0
def test_returns_404_for_non_existent_comment(self, client, user): login_user(client, user) response = client.post( url_for('like.create', user_id=user.id), data=json.dumps({'comment_id': 999}), content_type='application/json' ) assert response.status_code == 404
def test_returns_404_if_hearing_does_not_exist(self, client, user): login_user(client, user) response = client.get( url_for('like.index', user_id=user.id), data=json.dumps({'hearing_id': 999}), content_type='application/json' ) assert response.status_code == 404
def test_returns_unpublished_hearing_to_official(self, client): user = UserFactory(is_official=True) login_user(client, user) hearing = HearingFactory(published=False) response = client.get( url_for('hearing.show', hearing_id=hearing.id, slug=hearing.slug) ) assert response.status_code == 200
def test_returns_400_for_non_existent_like(self, client, user, comment): login_user(client, user) response = client.delete( url_for("like.delete", user_id=user.id), data=json.dumps({"comment_id": comment.id}), content_type="application/json", ) assert response.status_code == 400
def test_returns_empty_list_if_there_are_no_likes(self, client): another_user = UserFactory() login_user(client, another_user) response = client.get( url_for('like.index', user_id=another_user.id) ) content = response.data.decode('utf8') assert '[]' in content
def test_returns_hidden_comments_to_officials(self, client, hearing): user = UserFactory(is_official=True) login_user(client, user) comment = CommentFactory(hearing=hearing, is_hidden=True) response = client.get( url_for('comment.index', hearing_id=hearing.id) ) content = response.data.decode('utf8') assert comment.title in content
def test_returns_400_if_hearing_is_closed(self, client, user): hearing = HearingFactory(closes_at=date.today() - timedelta(2)) comment = CommentFactory(hearing=hearing) login_user(client, user) response = client.post( url_for('like.create', user_id=user.id), data=json.dumps({'comment_id': comment.id}), content_type='application/json' ) assert response.status_code == 400
def response(self, client, user, hearing, comment, comment_data): login_user(client, user) return client.put( url_for( 'comment.update', hearing_id=hearing.id, comment_id=comment.id ), data=json.dumps(comment_data), content_type='application/json' )
def test_returns_400_if_hearing_is_closed(self, client, user): login_user(client, user) hearing = HearingFactory(closes_at=date.today() - timedelta(2)) comment = CommentFactory(hearing=hearing) LikeFactory(user=user, comment=comment) response = client.delete( url_for("like.delete", user_id=user.id), data=json.dumps({"comment_id": comment.id}), content_type="application/json", ) assert response.status_code == 400
def test_returns_404_for_non_existing_comment( self, client, official, hearing, comment ): login_user(client, official) response = client.put( url_for( 'comment.update', hearing_id=hearing.id, comment_id=999 ) ) assert response.status_code == 404
def test_returns_401_for_non_officials( self, client, user, hearing, comment ): login_user(client, user) response = client.put( url_for( 'comment.update', hearing_id=hearing.id, comment_id=comment.id ) ) assert response.status_code == 401
def test_returns_400_if_data_is_not_json( self, client, official, hearing, comment ): login_user(client, official) response = client.put( url_for( 'comment.update', hearing_id=hearing.id, comment_id=comment.id ) ) assert response.status_code == 400
def test_login_with_missing_fields(self, client): """ POST /login Should: return 400 """ res = login_user(client, email=VALID_USER['email']) res_json = res.get_json() assert res.status_code == 400 assert res_json['reason'] == 'Email or password is missing' res = login_user(client, password=VALID_USER['password']) res_json = res.get_json() assert res.status_code == 400 assert res_json['reason'] == 'Email or password is missing'
def test_login_invalid_user(self, client): """ POST /login Should: return 401 """ res = login_user(client, 'invalidEmail', VALID_USER['password']) res_json = res.get_json() assert res.status_code == 401 assert res_json['reason'] == 'Wrong credentials'
def test_login_wrong_password(self, client): """ POST /login Should: return 401 """ res = register_user(client, VALID_USER['email'], VALID_USER['username'], VALID_USER['password']) res = login_user(client, VALID_USER['email'], 'superHackyPassword') res_json = res.get_json() assert res.status_code == 401 assert res_json['reason'] == 'Wrong credentials'
def test_login_success(self, client): """ POST /login Should: return 200 """ res = register_user(client, VALID_USER['email'], VALID_USER['username'], VALID_USER['password']) res = login_user(client, VALID_USER['email'], VALID_USER['password']) res_json = res.get_json() assert res.status_code == 200 assert res_json['token'] == 'token_{}'.format(VALID_USER['email']) assert res_json['user']['id'] == NEXT_ID assert res_json['user']['email'] == VALID_USER['email'] assert res_json['user']['username'] == VALID_USER['username']
def response(self, client, user, comment, delete_data, like): login_user(client, user) return client.delete( url_for("like.delete", user_id=user.id), data=json.dumps(delete_data), content_type="application/json" )
def login(self, client): login_user(client, UserFactory())
def response(self, client, user, like): login_user(client, user) return client.get( url_for('like.index', user_id=user.id) )