def getRatingAverage(): try: ratingSum = 0 ratings = Group.getRatings(session['group'], conn) if len(ratings) == 0: return json.dumps({'averageRating': 5}) for rating in ratings: ratingSum += rating['rating'] return json.dumps({'averageRating': ratingSum / len(ratings)}) except: return json.dumps({'averageRating': -1})
def test_insertGroupRating(): Group.insertGroupRating(email1, group1, rating1, conn) assert Group.getRatings(group1, conn) == [{'rating': 4}] Group.insertGroupRating(email2, group2, rating2, conn) assert Group.getRatings(group2, conn) == [{'rating': 5}] assert Group.getRatings(group3, conn) == ()