コード例 #1
0
    def test_get_and_count(self):
        """Test the get function that gets revisions for the test review ordered by the timestamp
        and the count function that returns the total number of revisions of a review"""

        review_id = self.review.id
        count = revision.get_count(review_id)
        first_revision = revision.get(review_id)[0]
        self.assertEqual(count, 1)
        self.assertEqual(first_revision['text'], "Testing!")
        self.assertEqual(type(first_revision['timestamp']), datetime)
        self.assertEqual(type(first_revision['id']), int)

        self.review.update(text="Testing Again!")
        second_revision = revision.get(review_id)[0]
        count = revision.get_count(review_id)
        self.assertEqual(count, 2)
        self.assertEqual(second_revision['text'], "Testing Again!")
        self.assertEqual(type(second_revision['timestamp']), datetime)
        self.assertEqual(type(second_revision['id']), int)

        self.review.update(text="Testing Once Again!")
        # Testing offset and limit
        first_two_revisions = revision.get(review_id, limit=2, offset=1)
        count = revision.get_count(review_id)
        self.assertEqual(count, 3)
        self.assertEqual(first_two_revisions[1]['text'], "Testing!")
        self.assertEqual(first_two_revisions[0]['text'], "Testing Again!")
コード例 #2
0
    def test_get_all_votes(self):
        """Test to get the number of votes on revisions of a review"""

        review_id = self.review["id"]
        revision.get_count(review_id)
        first_revision = revision.get(review_id)[0]
        vote.submit(self.user_1.id, first_revision['id'], True)
        vote.submit(self.user_2.id, first_revision['id'], False)
        votes = revision.get_all_votes(review_id)
        votes_first_revision = votes[first_revision['id']]
        self.assertDictEqual(votes_first_revision, {
            "positive": 1,
            "negative": 1
        })
コード例 #3
0
    def test_get_all_votes(self):
        """Test to get the number of votes on revisions of a review"""

        review_id = self.review["id"]
        revision.get_count(review_id)
        first_revision = revision.get(review_id)[0]
        vote.submit(self.user_1.id, first_revision['id'], True)
        vote.submit(self.user_2.id, first_revision['id'], False)
        votes = revision.get_all_votes(review_id)
        votes_first_revision = votes[first_revision['id']]
        self.assertDictEqual(votes_first_revision, {
            "positive": 1,
            "negative": 1
        })
コード例 #4
0
ファイル: review.py プロジェクト: mwiencek/critiquebrainz
def revisions_more(id):
    review = Review.query.get_or_404(str(id))

    # Not showing review if it isn't published yet and not viewed by author.
    if review.is_draft and not (current_user.is_authenticated
                                and current_user == review.user):
        raise NotFound("Can't find a review with the specified ID.")
    if review.is_hidden and not current_user.is_admin():
        raise NotFound(gettext("Review has been hidden."))

    page = int(request.args.get('page', default=0))
    offset = page * RESULTS_LIMIT
    try:
        count = db_revision.get_count(id)
        revisions = db_revision.get(id, limit=RESULTS_LIMIT, offset=offset)
    except db_exceptions.NoDataFoundException:
        raise NotFound(
            gettext("The revision(s) you are looking for does not exist."))
    votes = db_revision.get_votes(id)
    results = list(
        zip(reversed(range(count - offset - RESULTS_LIMIT, count - offset)),
            revisions))

    template = render_template('review/revision_results.html',
                               review=review,
                               results=results,
                               votes=votes,
                               count=count)
    return jsonify(results=template, more=(count - offset - RESULTS_LIMIT) > 0)
コード例 #5
0
ファイル: review.py プロジェクト: shagun6/critiquebrainz
def entity(id, rev=None):
    review = get_review_or_404(id)
    # Not showing review if it isn't published yet and not viewed by author.
    if review["is_draft"] and not (current_user.is_authenticated
                                   and current_user == review["user"]):
        raise NotFound(gettext("Can't find a review with the specified ID."))
    if review["is_hidden"]:
        if not current_user.is_admin():
            raise Forbidden(
                gettext("Review has been hidden. "
                        "You need to be an administrator to view it."))
        else:
            flash.warn(gettext("Review has been hidden."))

    spotify_mappings = None
    soundcloud_url = None
    if review["entity_type"] == 'release_group':
        spotify_mappings = mbspotify.mappings(str(review["entity_id"]))
        soundcloud_url = soundcloud.get_url(str(review["entity_id"]))
    count = db_revision.get_count(id)
    if not rev:
        rev = count
    if rev < count:
        flash.info(
            gettext(
                'You are viewing an old revision, the review has been updated since then.'
            ))
    elif rev > count:
        raise NotFound(
            gettext("The revision you are looking for does not exist."))

    revision = db_revision.get(id, offset=count - rev)[0]
    if not review[
            "is_draft"] and current_user.is_authenticated:  # if user is logged in, get their vote for this review
        try:
            vote = db_vote.get(user_id=current_user.id,
                               revision_id=revision['id'])
        except db_exceptions.NoDataFoundException:
            vote = None
    else:  # otherwise set vote to None, its value will not be used
        vote = None
    if revision["text"] is None:
        review["text_html"] = None
    else:
        review["text_html"] = markdown(revision['text'], safe_mode="escape")

    user_all_reviews, review_count = db_review.list_reviews(  # pylint: disable=unused-variable
        user_id=review["user_id"],
        sort="random",
        exclude=[review["id"]],
    )
    other_reviews = user_all_reviews[:3]
    avg_rating = get_avg_rating(review["entity_id"], review["entity_type"])
    return render_template('review/entity/%s.html' % review["entity_type"],
                           review=review,
                           spotify_mappings=spotify_mappings,
                           soundcloud_url=soundcloud_url,
                           vote=vote,
                           other_reviews=other_reviews,
                           avg_rating=avg_rating)
コード例 #6
0
    def test_get_and_count(self):
        """Test the get function that gets revisions for the test review ordered by the timestamp
        and the count function that returns the total number of revisions of a review"""

        review_id = self.review["id"]
        count = revision.get_count(review_id)
        first_revision = revision.get(review_id)[0]
        self.assertEqual(count, 1)
        self.assertEqual(first_revision['text'], "Testing!")
        self.assertEqual(first_revision['rating'], 5)
        self.assertEqual(type(first_revision['timestamp']), datetime)
        self.assertEqual(type(first_revision['id']), int)

        db_review.update(
            review_id=self.review["id"],
            drafted=self.review["is_draft"],
            text="Testing Again!",
            rating=4,
        )
        second_revision = revision.get(review_id)[0]
        count = revision.get_count(review_id)
        self.assertEqual(count, 2)
        self.assertEqual(second_revision['text'], "Testing Again!")
        self.assertEqual(second_revision['rating'], 4)
        self.assertEqual(type(second_revision['timestamp']), datetime)
        self.assertEqual(type(second_revision['id']), int)

        db_review.update(
            review_id=self.review["id"],
            drafted=self.review["is_draft"],
            text="Testing Once Again!",
            rating=3,
        )
        # Testing offset and limit
        first_two_revisions = revision.get(review_id, limit=2, offset=1)
        count = revision.get_count(review_id)
        self.assertEqual(count, 3)
        self.assertEqual(first_two_revisions[1]['text'], "Testing!")
        self.assertEqual(first_two_revisions[0]['text'], "Testing Again!")
        self.assertEqual(first_two_revisions[1]['rating'], 5)
        self.assertEqual(first_two_revisions[0]['rating'], 4)
コード例 #7
0
ファイル: review.py プロジェクト: pulkit6559/critiquebrainz
def revisions(id):
    review = get_review_or_404(id)
    # Not showing review if it isn't published yet and not viewed by author.
    if review["is_draft"] and not (current_user.is_authenticated and
                                   current_user == review["user"]):
        raise NotFound("Can't find a review with the specified ID.")
    if review["is_hidden"] and not current_user.is_admin():
        raise NotFound(gettext("Review has been hidden."))
    try:
        count = db_revision.get_count(id)
        revisions = db_revision.get(id, limit=RESULTS_LIMIT)
    except db_exceptions.NoDataFoundException:
        raise NotFound(gettext("The revision(s) you are looking for does not exist."))
    votes = db_revision.get_all_votes(id)
    results = list(zip(reversed(range(count - RESULTS_LIMIT, count)), revisions))
    return render_template('review/revisions.html', review=review, results=results,
                           count=count, limit=RESULTS_LIMIT, votes=votes)
コード例 #8
0
ファイル: review.py プロジェクト: pulkit6559/critiquebrainz
def compare(id):
    review = get_review_or_404(id)
    if review["is_draft"] and not (current_user.is_authenticated and
                                   current_user == review["user"]):
        raise NotFound(gettext("Can't find a review with the specified ID."))
    if review["is_hidden"] and not current_user.is_admin():
        raise NotFound(gettext("Review has been hidden."))
    count = db_revision.get_count(id)
    old, new = int(request.args.get('old') or count - 1), int(request.args.get('new') or count)
    if old > count or new > count:
        raise NotFound(gettext("The revision(s) you are looking for does not exist."))
    if old > new:
        return redirect(url_for('.compare', id=id, old=new, new=old))
    left = db_revision.get(id, offset=count - old)[0]
    right = db_revision.get(id, offset=count - new)[0]
    left['number'], right['number'] = old, new
    left['text'], right['text'] = side_by_side_diff(left['text'], right['text'])
    return render_template('review/compare.html', review=review, left=left, right=right)
コード例 #9
0
ファイル: views.py プロジェクト: shivam-kapila/critiquebrainz
def review_revision_entity_handler(review_id, rev):
    """Get a particular revisions of review with a specified UUID.

    **Request Example:**

    .. code-block:: bash

        $ curl https://critiquebrainz.org/ws/1/review/b7575c23-13d5-4adc-ac09-2f55a647d3de/revisions/1 \\
               -X GET

    **Response Example:**

    .. code-block:: json

        {
          "revision": {
            "id": 1,
            "review_id": "b7575c23-13d5-4adc-ac09-2f55a647d3de",
            "text": "TEXT CONTENT OF REVIEW",
            "rating": 5,
            "timestamp": "Tue, 10 Aug 2010 00:00:00 GMT",
            "votes_negative": 0,
            "votes_positive": 0
          }
        }

    :statuscode 200: no error
    :statuscode 404: review not found

    :resheader Content-Type: *application/json*
    """
    review = get_review_or_404(review_id)
    if review["is_hidden"]:
        raise NotFound("Review has been hidden.")

    count = db_revision.get_count(review["id"])
    if rev > count:
        raise NotFound("Can't find the revision you are looking for.")

    revision = db_revision.get(review_id, offset=count - rev)[0]
    revision.update(id=rev)
    return jsonify(revision=revision)
コード例 #10
0
ファイル: views.py プロジェクト: metabrainz/critiquebrainz
def review_revision_entity_handler(review_id, rev):
    """Get a particular revisions of review with a specified UUID.

    **Request Example:**

    .. code-block:: bash

        $ curl https://critiquebrainz.org/ws/1/review/b7575c23-13d5-4adc-ac09-2f55a647d3de/revisions/1 \\
               -X GET

    **Response Example:**

    .. code-block:: json

        {
          "revision": {
            "id": 1,
            "review_id": "b7575c23-13d5-4adc-ac09-2f55a647d3de",
            "text": "TEXT CONTENT OF REVIEW",
            "rating": 5,
            "timestamp": "Tue, 10 Aug 2010 00:00:00 GMT",
            "votes_negative": 0,
            "votes_positive": 0
          }
        }

    :statuscode 200: no error
    :statuscode 404: review not found

    :resheader Content-Type: *application/json*
    """
    review = get_review_or_404(review_id)
    if review["is_hidden"]:
        raise NotFound("Review has been hidden.")

    count = db_revision.get_count(review["id"])
    if rev > count:
        raise NotFound("Can't find the revision you are looking for.")

    revision = db_revision.get(review_id, offset=count - rev)[0]
    revision.update(id=rev)
    return jsonify(revision=revision)