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 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 test_update(self): """Test if rating and count are updated when review is updated or deleted""" 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) db_review.update( review_id=review_2["id"], drafted=review_2["is_draft"], text=u"Testing rating update", rating=None, ) # Check if avg_rating is updated after change in rating 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_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_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_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 get_avg_rating(entity_id, entity_type): """Retrieve average rating""" try: return db_avg_rating.get(entity_id, entity_type) except db_exceptions.NoDataFoundException: return None
def get_avg_rating(entity_id, entity_type): """Retrieve average rating""" try: return db_avg_rating.get(entity_id, entity_type) except db_exceptions.NoDataFoundException: return None