Пример #1
0
 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
Пример #2
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'
     )
Пример #3
0
 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'
     )
Пример #4
0
 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
Пример #5
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
Пример #6
0
 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
Пример #7
0
 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
Пример #8
0
 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
Пример #9
0
 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
Пример #10
0
 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
Пример #11
0
 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
Пример #12
0
 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'
     )
Пример #13
0
 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
Пример #14
0
 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
Пример #15
0
 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
Пример #16
0
 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
Пример #17
0
    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'
Пример #18
0
    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'
Пример #19
0
    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'
Пример #20
0
    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']
Пример #21
0
 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"
     )
Пример #22
0
 def login(self, client):
     login_user(client, UserFactory())
Пример #23
0
 def response(self, client, user, like):
     login_user(client, user)
     return client.get(
         url_for('like.index', user_id=user.id)
     )