Skip to content

Commit

Permalink
Change review score to review rating
Browse files Browse the repository at this point in the history
  • Loading branch information
huangsam committed Jul 11, 2020
1 parent 5d782b1 commit 1b2e8ec
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
18 changes: 18 additions & 0 deletions places/migrations/0007_auto_20200711_0104.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.0.8 on 2020-07-11 01:04

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('places', '0006_auto_20200711_0045'),
]

operations = [
migrations.RenameField(
model_name='review',
old_name='score',
new_name='rating',
),
]
6 changes: 3 additions & 3 deletions places/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __str__(self):
return f"Restaurant {self.name} located at {self.address}"


class Score(models.IntegerChoices):
class Rating(models.IntegerChoices):
TERRIBLE = 1
MEDIOCRE = 2
AVERAGE = 3
Expand All @@ -37,7 +37,7 @@ class Score(models.IntegerChoices):
class Review(models.Model):
title = models.CharField(max_length=255)
body = models.TextField()
score = models.IntegerField(choices=Score.choices)
rating = models.IntegerField(choices=Rating.choices)
place = models.ForeignKey("Restaurant", models.CASCADE, related_name="reviews")
author = models.ForeignKey(get_user_model(), models.CASCADE, related_name="reviews")

Expand All @@ -49,4 +49,4 @@ def __repr__(self):
return f"<Review id={self.id} score={self.score}>"

def __str__(self):
return f"User {self.author.username} reviewed {self.place.name} with a score of {self.score}"
return f"User {self.author.username} reviewed {self.place.name} with a rating of {self.rating}"
12 changes: 6 additions & 6 deletions places/tests/models/test_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def setUpTestData(cls):
Review.objects.create(
title="Amazing",
body="This place is excellent",
score=5,
rating=5,
place=restaurant,
author=cls.user,
)
Expand All @@ -37,19 +37,19 @@ def test_review_all(self):
def test_review_get(self):
review = Review.objects.get(title="Amazing")
self.assertEquals(review.place.name, "Plutos")
self.assertEquals(review.score, 5)
self.assertEquals(review.rating, 5)
self.assertEquals(review.author, self.user)

def test_review_filter(self):
reviews = Review.objects.filter(score=5)
reviews = Review.objects.filter(rating=5)
self.assertEquals(len(reviews), 1)

def test_review_exception(self):
self.assertRaises(Review.DoesNotExist, Review.objects.get, score=0)
self.assertRaises(Review.DoesNotExist, Review.objects.get, score=6)
self.assertRaises(Review.DoesNotExist, Review.objects.get, rating=0)
self.assertRaises(Review.DoesNotExist, Review.objects.get, rating=6)

def test_review_empty(self):
reviews = Review.objects.filter(score=0)
reviews = Review.objects.filter(rating=0)
self.assertEquals(len(reviews), 0)

def test_restaurant_reviews(self):
Expand Down

0 comments on commit 1b2e8ec

Please sign in to comment.