def test_review_creation(self): review = db_review.create( user_id=self.user.id, entity_id="e7aad618-fa86-3983-9e77-405e21796eca", entity_type="release_group", text="Testing", rating=5, is_draft=False, license_id=self.license["id"], ) reviews, count = db_review.list_reviews() self.assertEqual(count, 1) self.assertEqual(reviews[0]["id"], review["id"]) self.assertEqual(reviews[0]["entity_id"], review["entity_id"]) self.assertEqual(reviews[0]["license_id"], review["license_id"]) self.assertEqual(reviews[0]["rating"], review["rating"]) with self.assertRaises(db_exceptions.BadDataException): db_review.create( user_id=self.user_2.id, entity_id="e7aad618-fa86-3983-9e77-405e21796eca", entity_type="release_group", is_draft=False, license_id=self.license["id"], )
def test_get_popular(self): reviews = db_review.get_popular() self.assertEqual(len(reviews), 0) db_review.create( entity_id="e7aad618-fa86-3983-9e77-405e21796eca", entity_type="release_group", user_id=self.user.id, text="Awesome", is_draft=False, license_id=self.license["id"], ) reviews = db_review.get_popular() self.assertEqual(len(reviews), 1) review = db_review.create( user_id=self.user.id, entity_id="e7aad618-fa86-3983-9e77-405e21796ece", entity_type="release_group", text="Not Awesome", is_draft=False, license_id=self.license["id"], language="en", ) db_review.set_hidden_state(review["id"], is_hidden=True) reviews = db_review.get_popular() self.assertEqual(len(reviews), 1) self.assertEqual(reviews[0]["is_hidden"], False)
def test_languages(self): db_review.create( user_id=self.user.id, entity_id="e7aad618-fa86-3983-9e77-405e21796ece", entity_type="release_group", text="Testing", is_draft=False, license_id=self.license["id"], language="en", ) db_review.create( user_id=self.user.id, entity_id="e7aad618-fa86-3983-9e77-405e21796eca", entity_type="release_group", text="Testing", is_draft=False, license_id=self.license["id"], language="de", ) reviews, count = db_review.list_reviews(language="de") self.assertEqual(len(reviews), 1) self.assertEqual(count, 1) reviews, count = db_review.list_reviews(language="ru") self.assertEqual(count, 0)
def test_update(self): """Test if rating and count are updated when review is updated, deleted or hidden""" # Check avg_rating when review is created review = db_review.create( entity_id="e7aad618-fa86-3983-9e77-405e21796eca", entity_type="release_group", text=u"Testing!", rating=5, user_id=self.user.id, is_draft=False, license_id=self.license["id"], ) review_2 = db_review.create( entity_id="e7aad618-fa86-3983-9e77-405e21796eca", entity_type="release_group", text=u"Testing!", rating=4, user_id=self.user_2.id, is_draft=False, license_id=self.license["id"], ) avg_rating = db_avg_rating.get(review["entity_id"], review["entity_type"]) self.assertEqual(avg_rating["entity_id"], review["entity_id"]) self.assertEqual(avg_rating["entity_type"], review["entity_type"]) self.assertEqual(avg_rating["rating"], 4.5) self.assertEqual(avg_rating["count"], 2) # Check if avg_rating is updated after review_2 is hidden db_review.set_hidden_state(review_2["id"], is_hidden=True) avg_rating = db_avg_rating.get(review["entity_id"], review["entity_type"]) self.assertEqual(avg_rating["rating"], 5.0) self.assertEqual(avg_rating["count"], 1) # Check if avg_rating is updated after review_2 is revealed db_review.set_hidden_state(review_2["id"], is_hidden=False) avg_rating = db_avg_rating.get(review["entity_id"], review["entity_type"]) self.assertEqual(avg_rating["rating"], 4.5) self.assertEqual(avg_rating["count"], 2) # Check if avg_rating is updated after change in rating db_review.update( review_id=review_2["id"], drafted=review_2["is_draft"], text=u"Testing rating update", rating=None, ) avg_rating = db_avg_rating.get(review["entity_id"], review["entity_type"]) self.assertEqual(avg_rating["rating"], 5.0) self.assertEqual(avg_rating["count"], 1) # Check if avg_rating is updated after a review with rating is deleted db_review.delete(review["id"]) with self.assertRaises(db_exceptions.NoDataFoundException): db_avg_rating.get(review["entity_id"], review["entity_type"])
def test_get_count(self): count = db_review.get_count() self.assertEqual(count, 0) db_review.create( user_id=self.user.id, entity_id="e7aad618-fa86-3983-9e77-405e21796eca", entity_type="release_group", rating=5, is_draft=False, license_id=self.license["id"], ) count = db_review.get_count(is_draft=False, is_hidden=False) self.assertEqual(count, 1)
def test_get_popular(self): reviews = db_review.get_popular() self.assertEqual(len(reviews), 0) db_review.create( entity_id="e7aad618-fa86-3983-9e77-405e21796eca", entity_type="release_group", user_id=self.user.id, text="Awesome", is_draft=False, license_id=self.license["id"], ) reviews = db_review.get_popular() self.assertEqual(len(reviews), 1)
def setUp(self): super(CommentTestCase, self).setUp() # each comment requires a user and a review, so create a user and # review # create user self.user = User(db_users.get_or_create(1, "Tester", new_user_data={ "display_name": "test user", })) self.user_2 = User(db_users.get_or_create(2, "Tester 2", new_user_data={ "display_name": "test user 2", })) # need to create a license before creating a review self.license = db_license.create( id=u'Test', full_name=u"Test License", ) self.review = db_review.create( user_id=self.user.id, entity_id="e7aad618-fa86-3983-9e77-405e21796eca", entity_type="release_group", text="Testing", rating=5, is_draft=False, license_id=self.license["id"], )
def setUp(self): super(UserTestCase, self).setUp() self.user1 = User( db_users.get_or_create('tester_1', new_user_data={ "display_name": "test", })) self.user2 = User( db_users.get_or_create("тестер", new_user_data={ "display_name": "test1", })) self.author = User( db_users.get_or_create("author1", new_user_data={ "display_name": "Author1", })) license = db_license.create( id='Test', full_name='Test License', ) self.review = db_review.create( entity_id="e7aad618-fa86-3983-9e77-405e21796eca", entity_type="release_group", text="Testing!", user_id=self.author.id, is_draft=False, license_id=license["id"], ) db_vote.submit(self.user1.id, self.review["last_revision"]["id"], True) self.review_created = self.review["last_revision"]["timestamp"] self.review_id = self.review["id"] self.revision_id = self.review["last_revision"]["id"] self.report = db_spam_report.create(self.revision_id, self.user1.id, "Testing Reason Report")
def setUp(self): super(ModerationLogTestCase, self).setUp() self.admin = User( db_users.get_or_create(1, "Admin", new_user_data={ "display_name": "Admin", })) self.user = User( db_users.get_or_create(2, "Tester", new_user_data={ "display_name": "Tester", })) self.reason = "Testing!" self.license = db_license.create( id=u'TEST', full_name=u"Test License", ) self.review = db_review.create( user_id=self.user.id, entity_id="e7aad618-fa86-3983-9e77-405e21796eca", entity_type="release_group", text="It is beautiful!", is_draft=False, license_id=self.license["id"], language='en', )
def setUp(self): super(CommentViewsTestCase, self).setUp() self.reviewer = User( db_users.get_or_create(1, "aef06569-098f-4218-a577-b413944d9493", new_user_data={ "display_name": u"Reviewer", })) self.commenter = User( db_users.get_or_create(2, "9371e5c7-5995-4471-a5a9-33481f897f9c", new_user_data={ "display_name": u"Commenter", })) self.license = db_license.create( id="CC BY-SA 3.0", full_name="Test License.", ) self.review = db_review.create( user_id=self.reviewer.id, entity_id="e7aad618-fa86-3983-9e77-405e21796eca", entity_type="release_group", text="Test Review.", rating=5, is_draft=False, license_id=self.license["id"], ) current_app.jinja_env.filters["entity_details"] = mock_get_entity_by_id
def test_get_popular(self): reviews = db_review.get_popular() self.assertEqual(len(reviews), 0) # popular reviews should not contain reviews saved as drafts review = db_review.create( entity_id="e7aad618-fa86-3983-9e77-405e21796eca", entity_type="release_group", user_id=self.user.id, text="A draft", is_draft=True, license_id=self.license["id"], ) reviews = db_review.get_popular() self.assertEqual(len(reviews), 0) # publishing the drafted review; now it should be in popular reviews db_review.update( review_id=review["id"], drafted=True, text=review["text"], rating=review["rating"], is_draft=False, ) reviews = db_review.get_popular() self.assertEqual(len(reviews), 1) self.assertEqual(reviews[0]["is_draft"], False) # A hidden review should not be in popular reviews db_review.set_hidden_state(review["id"], is_hidden=True) reviews = db_review.get_popular() self.assertEqual(len(reviews), 0)
def setUp(self): super(RevisionTestCase, self).setUp() self.author = User( db_users.get_or_create(1, 'Author', new_user_data={ "display_name": '0', })) self.user_1 = User( db_users.get_or_create(2, 'Tester #1', new_user_data={ "display_name": '1', })) self.user_2 = User( db_users.get_or_create(3, 'Tester #2', new_user_data={ "display_name": '2', })) self.license = db_license.create( id=u'TEST', full_name=u"Test License", ) self.review = db_review.create( user_id=self.author.id, entity_id="e7aad618-fa86-3983-9e77-405e21796eca", entity_type="release_group", text=u"Testing!", rating=5, is_draft=False, license_id=self.license["id"], )
def test_release_group_page(self): db_review.create( user_id=self.user.id, entity_id='8ef859e3-feb2-4dd1-93da-22b91280d768', entity_type='release_group', text='This is a test review', is_draft=False, license_id=self.license['id'], language='en', ) response = self.client.get( '/release-group/8ef859e3-feb2-4dd1-93da-22b91280d768') self.assert200(response) self.assertIn('Collision Course', str(response.data)) # Test if there is a review from test user self.assertIn('test user', str(response.data))
def setUp(self): super(UserTestCase, self).setUp() self.user1 = User(db_users.get_or_create(1, 'tester_1', new_user_data={ "display_name": "test", })) self.user2 = User(db_users.get_or_create(2, "тестер", new_user_data={ "display_name": "test1", })) self.author = User(db_users.get_or_create(3, "author1", new_user_data={ "display_name": "Author1", })) license = db_license.create( id='Test', full_name='Test License', ) self.review = db_review.create( entity_id="e7aad618-fa86-3983-9e77-405e21796eca", entity_type="release_group", text="Testing!", user_id=self.author.id, is_draft=False, license_id=license["id"], ) db_vote.submit(self.user1.id, self.review["last_revision"]["id"], True) self.review_created = self.review["last_revision"]["timestamp"] self.review_id = self.review["id"] self.revision_id = self.review["last_revision"]["id"] self.report = db_spam_report.create(self.revision_id, self.user1.id, "Testing Reason Report")
def setUp(self): super(SpamReportTestCase, self).setUp() author = User(db_users.get_or_create(0, '0', new_user_data={ "display_name": "Author", })) self.user1 = User(db_users.get_or_create(1, '1', new_user_data={ "display_name": "Tester #1", })) self.user2 = User(db_users.get_or_create(2, '2', new_user_data={ "display_name": "Tester #2", })) license = db_license.create( id='Test', full_name='Test License', ) self.review = db_review.create( entity_id="e7aad618-fa86-3983-9e77-405e21796eca", entity_type="release_group", text="Testing!", user_id=author.id, is_draft=False, license_id=license["id"], ) self.revision_id = self.review["last_revision"]["id"] self.report = db_spam_report.create(self.revision_id, self.user1.id, "To test is this report") self.report_time = self.report["reported_at"]
def setUp(self): super(VoteTestCase, self).setUp() author = User( db_users.get_or_create(0, '0', new_user_data={ "display_name": "Author", })) self.user_1 = User( db_users.get_or_create(1, '1', new_user_data={ "display_name": "Tester #1", })) self.user_2 = User( db_users.get_or_create(2, '2', new_user_data={ "display_name": "Tester #2", })) license = db_license.create( id='Test', full_name='Test License', ) self.review = db_review.create( entity_id="e7aad618-fa86-3983-9e77-405e21796eca", entity_type="release_group", text="Testing!", rating=5, user_id=author.id, is_draft=False, license_id=license["id"], )
def test_recording_page(self): db_review.create( user_id=self.user.id, entity_id='442ddce2-ffa1-4865-81d2-b42c40fec7c5', entity_type='recording', text='This is a test review', is_draft=False, license_id=self.license['id'], language='en', ) response = self.client.get( '/recording/8ef859e3-feb2-4dd1-93da-22b91280d768') self.assert200(response) self.assertIn('Dream Come True', str(response.data)) # Test if there is a review from test user self.assertIn('test user', str(response.data))
def test_importer(self): user = User(db_users.get_or_create(1, "Tester", new_user_data={ "display_name": "test user", })) review = db_review.create( user_id=user.id, entity_id="e7aad618-fa86-3983-9e77-405e21796eca", entity_type="release_group", text="Testing", rating=5, is_draft=False, license_id=self.license["id"], ) # Make dumps and delete entities self.runner.invoke(dump_manager.public, ['--location', self.tempdir]) archives = get_archives(self.tempdir) db_review.delete(review['id']) db_users.delete(user.id) self.assertEqual(db_users.total_count(), 0) self.assertEqual(db_review.get_count(), 0) # Import dumps - cbdump.tar.bz2 and cbdump-reviews-all.tar.bz2 and check if data imported properly self.runner.invoke(dump_manager.importer, [archives['cbdump.tar.bz2']]) self.assertEqual(db_users.total_count(), 1) self.runner.invoke(dump_manager.importer, [archives['cbdump-reviews-all.tar.bz2']]) self.assertEqual(db_review.get_count(), 1)
def rate(): form = RatingEditForm() if form.validate_on_submit(): if current_user.is_blocked: flash.error( gettext("You are not allowed to rate any entity because your " "account has been blocked by a moderator.")) return redirect( url_for('{}.entity'.format(form.entity_type.data), id=form.entity_id.data)) reviews, review_count = db_review.list_reviews( entity_id=form.entity_id.data, entity_type=form.entity_type.data, user_id=current_user.id, ) review = reviews[0] if review_count else None if not review and form.rating.data is None: raise BadRequest( "Cannot create a review with no rating and no text!") if not review and form.rating.data is not None: db_review.create( user_id=current_user.id, entity_id=form.entity_id.data, entity_type=form.entity_type.data, rating=form.rating.data, is_draft=False, ) elif review and review['text'] is None and form.rating.data is None: db_review.delete(review['id']) elif review and review['rating'] != form.rating.data: db_review.update( review_id=review['id'], drafted=review['is_draft'], text=review['text'], rating=form.rating.data, ) # TODO(code-master5): Make this message specify the entity flash.success("We have updated your rating for this entity!") else: flash.error("Error! Could not update the rating...") return redirect( url_for('{}.entity'.format(form.entity_type.data), id=form.entity_id.data))
def test_distinct_entities(self): db_review.create( user_id=self.user.id, entity_id="e7aad618-fa86-3983-9e77-405e21796eca", entity_type="release_group", text="Awesome", is_draft=False, license_id=self.license["id"], ) db_review.create( user_id=self.user_2.id, entity_id="e7aad618-fa86-3983-9e77-405e21796eca", entity_type="release_group", rating=5, is_draft=False, license_id=self.license["id"], ) entities = db_review.distinct_entities() self.assertEqual(len(entities), 1)
def create_dummy_review(self, user_id): return db_review.create( entity_id="e7aad618-fa86-3983-9e77-405e21796eca", entity_type="release_group", text=u"Test review", rating=5, user_id=user_id, is_draft=False, license_id=self.license["id"], )
def create_dummy_review(self, is_draft=False): review = db_review.create( entity_id="6b3cd75d-7453-39f3-86c4-1441f360e121", entity_type="release_group", user_id=self.user.id, text=self.review_text, is_draft=is_draft, license_id=self.license["id"], ) return review
def test_statistics(self): # test when there is no user response = self.client.get("statistics/") self.assert200(response) self.assertIn("Could not fetch results! Please try again.", str(response.data)) # creating a review db_review.create( entity_id="e7aad618-fa86-3983-9e77-405e21796eca", entity_type="release_group", text="Test review", user_id=self.user.id, is_draft=False, license_id=self.license["id"], ) # test user's name in statistics page after user added review response = self.client.get("statistics/") self.assert200(response) self.assertIn(self.user.display_name, str(response.data))
def test_review_deletion(self): review = db_review.create( user_id=self.user.id, entity_id="e7aad618-fa86-3983-9e77-405e21796eca", entity_type="release_group", text="Testing", is_draft=False, license_id=self.license["id"], ) self.assertEqual(db_review.list_reviews()[1], 1) db_review.delete(review["id"]) self.assertEqual(db_review.list_reviews()[1], 0)
def review_post_handler(user): """Publish a review. **OAuth scope:** review :reqheader Content-Type: *application/json* :json uuid entity_id: UUID of the entity that is being reviewed :json string entity_type: One of the supported reviewable entities. 'release_group' or 'event' etc. :json string text: Text part of review, min length is 25, max is 5000 **(optional)** :json integer rating: Rating part of review, min is 1, max is 5 **(optional)** :json string license_choice: license ID :json string lang: language code (ISO 639-1), default is ``en`` **(optional)** :json boolean is_draft: whether the review should be saved as a draft or not, default is ``False`` **(optional)** **NOTE:** You must provide some text or rating for the review. :resheader Content-Type: *application/json* """ def fetch_params(): is_draft = Parser.bool('json', 'is_draft', optional=True) or False if is_draft: REVIEW_TEXT_MIN_LENGTH = None entity_id = Parser.uuid('json', 'entity_id') entity_type = Parser.string('json', 'entity_type', valid_values=ENTITY_TYPES) text = Parser.string('json', 'text', min=REVIEW_TEXT_MIN_LENGTH, max=REVIEW_TEXT_MAX_LENGTH, optional=True) rating = Parser.int('json', 'rating', min=REVIEW_RATING_MIN, max=REVIEW_RATING_MAX, optional=True) license_choice = Parser.string('json', 'license_choice') language = Parser.string('json', 'language', min=2, max=3, optional=True) or 'en' if text is None and rating is None: raise InvalidRequest(desc='Review must have either text or rating') if language and language not in supported_languages: raise InvalidRequest(desc='Unsupported language') if db_review.list_reviews(user_id=user.id, entity_id=entity_id)[1]: raise InvalidRequest(desc='You have already published a review for this album') return entity_id, entity_type, text, rating, license_choice, language, is_draft if user.is_review_limit_exceeded: raise LimitExceeded('You have exceeded your limit of reviews per day.') entity_id, entity_type, text, rating, license_choice, language, is_draft = fetch_params() review = db_review.create( user_id=user.id, entity_id=entity_id, entity_type=entity_type, text=text, rating=rating, license_id=license_choice, language=language, is_draft=is_draft, ) return jsonify(message='Request processed successfully', id=review["id"])
def rate(): form = RatingEditForm() if form.validate_on_submit(): if current_user.is_blocked: flash.error(gettext("You are not allowed to rate any entity because your " "account has been blocked by a moderator.")) return redirect(url_for('{}.entity'.format(form.entity_type.data), id=form.entity_id.data)) reviews, review_count = db_review.list_reviews( entity_id=form.entity_id.data, entity_type=form.entity_type.data, user_id=current_user.id, ) review = reviews[0] if review_count else None if not review and form.rating.data is None: raise BadRequest("Cannot create a review with no rating and no text!") if not review and form.rating.data is not None: db_review.create( user_id=current_user.id, entity_id=form.entity_id.data, entity_type=form.entity_type.data, rating=form.rating.data, is_draft=False, ) elif review and review['text'] is None and form.rating.data is None: db_review.delete(review['id']) elif review and review['rating'] != form.rating.data: db_review.update( review_id=review['id'], drafted=review['is_draft'], text=review['text'], rating=form.rating.data, ) # TODO(code-master5): Make this message specify the entity flash.success("We have updated your rating for this entity!") else: flash.error("Error! Could not update the rating...") return redirect(url_for('{}.entity'.format(form.entity_type.data), id=form.entity_id.data))
def test_place_review_pages(self): review = db_review.create( entity_id="c5c9c210-b7a0-4f6e-937e-02a586c8e14c", entity_type="place", user_id=self.user.id, text="A great place.", is_draft=False, license_id=self.license["id"], ) response = self.client.get("/review/%s" % review["id"]) self.assert200(response) self.assertIn("A great place.", str(response.data))
def test_event_review_pages(self): review = db_review.create( entity_id="b4e75ef8-3454-4fdc-8af1-61038c856abc", entity_type="event", user_id=self.user.id, text="A great event, enjoyed it.", is_draft=False, license_id=self.license["id"], ) response = self.client.get("/review/%s" % review["id"]) self.assert200(response) self.assertIn("A great event, enjoyed it.", str(response.data))
def create_dummy_review(self, is_draft=False, is_hidden=False): review = db_review.create( entity_id="6b3cd75d-7453-39f3-86c4-1441f360e121", entity_type="release_group", user_id=self.user.id, text=self.review_text, rating=self.review_rating, is_draft=is_draft, license_id=self.license["id"], ) if is_hidden: db_review.set_hidden_state(review["id"], is_hidden=True) return review
def test_set_hidden_state(self): review = db_review.create( user_id=self.user.id, entity_id="e7aad618-fa86-3983-9e77-405e21796eca", entity_type="release_group", text="Awesome", is_draft=False, license_id=self.license["id"], ) db_review.set_hidden_state(review["id"], is_hidden=True) review = db_review.get_by_id(review["id"]) self.assertEqual(review["is_hidden"], True) db_review.set_hidden_state(review["id"], is_hidden=False) review = db_review.get_by_id(review["id"]) self.assertEqual(review["is_hidden"], False)
def test_delete(self): """Test delete function that deletes avg_rating given entity_id and entity_type""" review = db_review.create( entity_id="e7aad618-fa86-3983-9e77-405e21796eca", entity_type="release_group", text=u"Testing!", rating=5, user_id=self.user.id, is_draft=False, license_id=self.license["id"], ) avg_rating = db_avg_rating.get(review["entity_id"], review["entity_type"]) self.assertEqual(avg_rating["count"], 1) db_review.delete(review["id"]) with self.assertRaises(db_exceptions.NoDataFoundException): db_avg_rating.get(review["entity_id"], review["entity_type"])
def setUp(self): super(CommentViewsTestCase, self).setUp() self.user = User(db_users.get_or_create(1, "aef06569-098f-4218-a577-b413944d9493", new_user_data={ "display_name": u"Tester", })) self.license = db_license.create( id="CC BY-SA 3.0", full_name="Created so we can fill the form correctly.", ) self.review = db_review.create( user_id=self.user.id, entity_id="e7aad618-fa86-3983-9e77-405e21796eca", entity_type="release_group", text="Testing", rating=5, is_draft=False, license_id=self.license["id"], )
def test_insert_and_get(self): """Test if rating and count are inserted on creation of the first review with rating and the get function that returns a dict containing rating and count""" review = db_review.create( entity_id="e7aad618-fa86-3983-9e77-405e21796eca", entity_type="release_group", text=u"Testing!", rating=5, user_id=self.user.id, is_draft=False, license_id=self.license["id"], ) avg_rating = db_avg_rating.get(review["entity_id"], review["entity_type"]) self.assertEqual(avg_rating["entity_id"], review["entity_id"]) self.assertEqual(avg_rating["entity_type"], review["entity_type"]) self.assertEqual(avg_rating["rating"], 5.0) self.assertEqual(avg_rating["count"], 1)
def test_list_reviews(self): reviews, count = db_review.list_reviews() self.assertEqual(count, 0) self.assertEqual(len(reviews), 0) review = db_review.create( user_id=self.user.id, entity_id="e7aad618-fa86-3983-9e77-405e21796eca", entity_type="release_group", text="Awesome", rating=5, is_draft=False, license_id=self.license["id"], ) reviews, count = db_review.list_reviews() self.assertEqual(count, 1) self.assertEqual(len(reviews), 1) self.assertEqual(reviews[0]["text"], "Awesome") self.assertEqual(reviews[0]["rating"], 5) db_review.update( review_id=review["id"], drafted=review["is_draft"], text="Beautiful!", rating=4, ) reviews, count = db_review.list_reviews() self.assertEqual(count, 1) self.assertEqual(len(reviews), 1) self.assertEqual(reviews[0]["text"], "Beautiful!") self.assertEqual(reviews[0]["rating"], 4) reviews, count = db_review.list_reviews(sort="popularity") self.assertEqual(count, 1) self.assertEqual(len(reviews), 1) reviews, count = db_review.list_reviews(sort="published_on") self.assertEqual(count, 1) self.assertEqual(len(reviews), 1) reviews, count = db_review.list_reviews(sort="random") self.assertEqual(count, 1) self.assertEqual(len(reviews), 1)
def test_reviewed_entities(self): review = db_review.create( user_id=self.user.id, entity_id="e7aad618-fa86-3983-9e77-405e21796eca", entity_type="release_group", text="Awesome", is_draft=False, license_id=self.license["id"], ) reviewed_entities = db_review.reviewed_entities( entity_ids=["e7aad618-fa86-3983-9e77-405e21796eca", "deae6fc2-a675-4f35-9565-d2aaea4872c7"], entity_type="release_group", ) self.assertListEqual(reviewed_entities, ["e7aad618-fa86-3983-9e77-405e21796eca"]) db_review.delete(review["id"]) reviewed_entities = db_review.reviewed_entities( entity_ids=["e7aad618-fa86-3983-9e77-405e21796eca"], entity_type="release_group", ) self.assertListEqual(reviewed_entities, [])
def setUp(self): super(CommentViewsTestCase, self).setUp() self.reviewer = User(db_users.get_or_create(1, "aef06569-098f-4218-a577-b413944d9493", new_user_data={ "display_name": u"Reviewer", })) self.commenter = User(db_users.get_or_create(2, "9371e5c7-5995-4471-a5a9-33481f897f9c", new_user_data={ "display_name": u"Commenter", })) self.license = db_license.create( id="CC BY-SA 3.0", full_name="Test License.", ) self.review = db_review.create( user_id=self.reviewer.id, entity_id="e7aad618-fa86-3983-9e77-405e21796eca", entity_type="release_group", text="Test Review.", rating=5, is_draft=False, license_id=self.license["id"], ) current_app.jinja_env.filters["entity_details"] = mock_get_entity_by_id
def setUp(self): super(ModerationLogTestCase, self).setUp() self.admin = User(db_users.get_or_create(1, "Admin", new_user_data={ "display_name": "Admin", })) self.user = User(db_users.get_or_create(2, "Tester", new_user_data={ "display_name": "Tester", })) self.reason = "Testing!" self.license = db_license.create( id=u'TEST', full_name=u"Test License", ) self.review = db_review.create( user_id=self.user.id, entity_id="e7aad618-fa86-3983-9e77-405e21796eca", entity_type="release_group", text="It is beautiful!", is_draft=False, license_id=self.license["id"], language='en', )
def setUp(self): super(VoteTestCase, self).setUp() author = User(db_users.get_or_create(0, '0', new_user_data={ "display_name": "Author", })) self.user_1 = User(db_users.get_or_create(1, '1', new_user_data={ "display_name": "Tester #1", })) self.user_2 = User(db_users.get_or_create(2, '2', new_user_data={ "display_name": "Tester #2", })) license = db_license.create( id='Test', full_name='Test License', ) self.review = db_review.create( entity_id="e7aad618-fa86-3983-9e77-405e21796eca", entity_type="release_group", text="Testing!", rating=5, user_id=author.id, is_draft=False, license_id=license["id"], )
def setUp(self): super(RevisionTestCase, self).setUp() self.author = User(db_users.get_or_create(1, 'Author', new_user_data={ "display_name": '0', })) self.user_1 = User(db_users.get_or_create(2, 'Tester #1', new_user_data={ "display_name": '1', })) self.user_2 = User(db_users.get_or_create(3, 'Tester #2', new_user_data={ "display_name": '2', })) self.license = db_license.create( id=u'TEST', full_name=u"Test License", ) self.review = db_review.create( user_id=self.author.id, entity_id="e7aad618-fa86-3983-9e77-405e21796eca", entity_type="release_group", text=u"Testing!", rating=5, is_draft=False, license_id=self.license["id"], )
def test_update(self): review = db_review.create( user_id=self.user.id, entity_id="e7aad618-fa86-3983-9e77-405e21796eca", entity_type="release_group", text="Testing", rating=5, is_draft=True, license_id=self.license["id"], ) another_license = db_license.create( id="License-2", full_name="Another License", ) # Update review to only rating db_review.update( review_id=review["id"], drafted=review["is_draft"], rating=4, is_draft=False, license_id=another_license["id"], language="es", ) # Checking if contents are updated retrieved_review = db_review.list_reviews()[0][0] self.assertEqual(retrieved_review["text"], None) self.assertEqual(retrieved_review["rating"], 4) self.assertFalse(retrieved_review["is_draft"]) self.assertEqual(retrieved_review["license_id"], another_license["id"]) self.assertEqual(retrieved_review["language"], "es") # Update review to only text db_review.update( review_id=review["id"], drafted=review["is_draft"], text="Testing update", is_draft=False, license_id=another_license["id"], language="es", ) # Checking if contents are updated retrieved_review = db_review.list_reviews()[0][0] self.assertEqual(retrieved_review["text"], "Testing update") self.assertEqual(retrieved_review["rating"], None) # Updating should create a new revision. revisions = db_revision.get(retrieved_review["id"], limit=None) self.assertEqual(len(revisions), 3) self.assertEqual(revisions[0]["timestamp"], retrieved_review["last_revision"]["timestamp"]) self.assertEqual(revisions[0]["text"], retrieved_review["text"]) self.assertEqual(revisions[0]["rating"], retrieved_review["rating"]) # Checking things that shouldn't be allowed with self.assertRaises(db_exceptions.BadDataException): db_review.update( review_id=retrieved_review["id"], drafted=retrieved_review["is_draft"], text="Sucks!", license_id=self.license["id"], ) review = db_review.get_by_id(review["id"]) with self.assertRaises(db_exceptions.BadDataException): db_review.update( review_id=review["id"], drafted=review["is_draft"], text="Sucks!", is_draft=True, )
def test_rate(self): self.temporary_login(self.reviewer) # Test for first time rating (no review exists) payload = { 'entity_id': self.test_entity['id'], 'entity_type': 'release_group', 'rating': 4 } response = self.client.post( url_for('rate.rate'), data=payload ) self.assertRedirects(response, '/release-group/{}'.format(self.test_entity['id'])) reviews, review_count = db_review.list_reviews( entity_id=self.test_entity['id'], entity_type='release_group', user_id=self.reviewer.id ) # Test that the rate request created a review self.assertEqual(review_count, 1) review = reviews[0] self.assertEqual(review['text'], None) self.assertEqual(review['rating'], 4) response = self.client.get('/release-group/{}'.format(self.test_entity['id'])) self.assert200(response) self.assertIn('We have updated your rating for this entity!', str(response.data)) # Test after rating is cleared for review with NO text payload = { 'entity_id': self.test_entity['id'], 'entity_type': 'release_group', 'rating': None } response = self.client.post( url_for('rate.rate'), data=payload ) reviews, review_count = db_review.list_reviews( entity_id=self.test_entity['id'], entity_type='release_group', user_id=self.reviewer.id ) # Test that the clear rating request results in deletion of review (because review-text was None) self.assertEqual(review_count, 0) # Test after rating is cleared for review with some text self.review = db_review.create( user_id=self.reviewer.id, entity_id=self.test_entity['id'], entity_type="release_group", text="Test Review.", rating=4, is_draft=False, license_id=self.license["id"], ) payload = { 'entity_id': self.test_entity['id'], 'entity_type': 'release_group', 'rating': None } response = self.client.post( url_for('rate.rate'), data=payload ) reviews, review_count = db_review.list_reviews( entity_id=self.test_entity['id'], entity_type='release_group', user_id=self.reviewer.id ) # Test that the clear rating request doesn't delete review (because review-text was not None) self.assertEqual(review_count, 1) review = reviews[0] self.assertEqual(review['rating'], None)
def create_dummy_review(self): return db_review.create(**self.review)