Ejemplo n.º 1
0
    def test_two_ratings(self):
        user_id1 = generate_client_id()
        user_id2 = generate_client_id()

        db.session.add(CommentRating(1, user_id1, self.comment, self.lecture))
        db.session.add(CommentRating(-1, user_id2, self.comment, self.lecture))
        db.session.flush()

        self._set_client_id_cookie(user_id1)
        rv = self.client.get('/api/0/lectures/1/comments')
        response = json.loads(rv.data.decode('utf-8'))
        assert response['comments'][0]['rating'] == 1

        self._set_client_id_cookie(user_id2)
        rv = self.client.get('/api/0/lectures/1/comments')
        response = json.loads(rv.data.decode('utf-8'))
        assert response['comments'][0]['rating'] == -1
Ejemplo n.º 2
0
    def test_default_rating(self):
        user_id = generate_client_id()

        db.session.add(CommentRating(1, user_id, self.comment, self.lecture))
        db.session.flush()

        self._set_generated_client_id_cookie()
        rv = self.client.get('/api/0/lectures/1/comments')
        response = json.loads(rv.data.decode('utf-8'))
        assert response['comments'][0]['rating'] == 0
Ejemplo n.º 3
0
    def test_one_user_two_ratings(self):
        user_id = generate_client_id()

        comment2 = Comment('Great!', datetime.utcnow(), self.lecture)
        db.session.add(comment2)

        db.session.add(CommentRating(1, user_id, self.comment, self.lecture))
        db.session.flush()

        db.session.add(CommentRating(-1, user_id, comment2, self.lecture))
        db.session.flush()

        self._set_client_id_cookie(user_id)
        rv = self.client.get('/api/0/lectures/1/comments')
        response = json.loads(rv.data.decode('utf-8'))
        assert len(response['comments']) == 2
        assert response['comments'][0]['rating'] == 1
        assert response['comments'][1]['rating'] == -1