|
@@ -0,0 +1,116 @@
|
|
1
|
+from django.test.testcases import TestCase
|
|
2
|
+from django.urls import reverse
|
|
3
|
+
|
|
4
|
+from oscar.apps.catalogue.reviews.models import ProductReview, Vote
|
|
5
|
+from oscar.test.factories import UserFactory, create_product
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+class TestAddVoteView(TestCase):
|
|
9
|
+ def setUp(self):
|
|
10
|
+ self.client.force_login(UserFactory())
|
|
11
|
+
|
|
12
|
+ def test_voting_on_product_review_returns_404_on_non_public_product(self):
|
|
13
|
+ product = create_product(is_public=False)
|
|
14
|
+ review = ProductReview.objects.create(product=product, **{
|
|
15
|
+ "title": "Awesome!",
|
|
16
|
+ "score": 5,
|
|
17
|
+ "body": "Wonderful product",
|
|
18
|
+ })
|
|
19
|
+ path = reverse("catalogue:reviews-vote",
|
|
20
|
+ kwargs={"product_slug": product.slug, "product_pk": product.pk, "pk": review.pk})
|
|
21
|
+
|
|
22
|
+ response = self.client.post(path, data={"delta": Vote.UP})
|
|
23
|
+
|
|
24
|
+ self.assertEqual(response.status_code, 404)
|
|
25
|
+
|
|
26
|
+ def test_voting_on_product_review_redirect_on_public_product(self):
|
|
27
|
+ product = create_product(is_public=True)
|
|
28
|
+ review = ProductReview.objects.create(product=product, **{
|
|
29
|
+ "title": "Awesome!",
|
|
30
|
+ "score": 5,
|
|
31
|
+ "body": "Wonderful product",
|
|
32
|
+ })
|
|
33
|
+ path = reverse("catalogue:reviews-vote",
|
|
34
|
+ kwargs={"product_slug": product.slug, "product_pk": product.pk, "pk": review.pk})
|
|
35
|
+
|
|
36
|
+ response = self.client.post(path, data={"delta": Vote.UP})
|
|
37
|
+
|
|
38
|
+ self.assertRedirects(response, product.get_absolute_url())
|
|
39
|
+
|
|
40
|
+ def test_creating_product_review_returns_404_on_non_public_product(self):
|
|
41
|
+ product = create_product(is_public=False)
|
|
42
|
+ path = reverse("catalogue:reviews-add", kwargs={"product_slug": product.slug, "product_pk": product.pk})
|
|
43
|
+
|
|
44
|
+ response = self.client.post(path, data={
|
|
45
|
+ "title": "Awesome!",
|
|
46
|
+ "score": 5,
|
|
47
|
+ "body": "Wonderful product",
|
|
48
|
+ })
|
|
49
|
+
|
|
50
|
+ self.assertEqual(response.status_code, 404)
|
|
51
|
+
|
|
52
|
+ def test_creating_product_review_redirect_on_public_product(self):
|
|
53
|
+ product = create_product(is_public=True)
|
|
54
|
+ path = reverse("catalogue:reviews-add", kwargs={"product_slug": product.slug, "product_pk": product.pk})
|
|
55
|
+
|
|
56
|
+ response = self.client.post(path, data={
|
|
57
|
+ "title": "Awesome!",
|
|
58
|
+ "score": 5,
|
|
59
|
+ "body": "Wonderful product",
|
|
60
|
+ })
|
|
61
|
+
|
|
62
|
+ self.assertRedirects(response, product.get_absolute_url())
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+class TestProductReviewList(TestCase):
|
|
66
|
+ def setUp(self):
|
|
67
|
+ self.client.force_login(UserFactory())
|
|
68
|
+
|
|
69
|
+ def test_listing_product_reviews_returns_404_on_non_public_product(self):
|
|
70
|
+ product = create_product(is_public=False)
|
|
71
|
+ path = reverse("catalogue:reviews-list", kwargs={"product_slug": product.slug, "product_pk": product.pk})
|
|
72
|
+
|
|
73
|
+ response = self.client.get(path)
|
|
74
|
+
|
|
75
|
+ self.assertEqual(response.status_code, 404)
|
|
76
|
+
|
|
77
|
+ def test_listing_product_reviews_returns_200_on_public_product(self):
|
|
78
|
+ product = create_product(is_public=True)
|
|
79
|
+ path = reverse("catalogue:reviews-list", kwargs={"product_slug": product.slug, "product_pk": product.pk})
|
|
80
|
+
|
|
81
|
+ response = self.client.get(path)
|
|
82
|
+
|
|
83
|
+ self.assertEqual(response.status_code, 200)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+class TestProductReviewDetail(TestCase):
|
|
87
|
+ def setUp(self):
|
|
88
|
+ self.client.force_login(UserFactory())
|
|
89
|
+
|
|
90
|
+ def test_retrieving_product_review_returns_404_on_non_public_product(self):
|
|
91
|
+ product = create_product(is_public=False)
|
|
92
|
+ review = ProductReview.objects.create(product=product, **{
|
|
93
|
+ "title": "Awesome!",
|
|
94
|
+ "score": 5,
|
|
95
|
+ "body": "Wonderful product",
|
|
96
|
+ })
|
|
97
|
+ path = reverse("catalogue:reviews-detail",
|
|
98
|
+ kwargs={"product_slug": product.slug, "product_pk": product.pk, "pk": review.pk})
|
|
99
|
+
|
|
100
|
+ response = self.client.get(path)
|
|
101
|
+
|
|
102
|
+ self.assertEqual(response.status_code, 404)
|
|
103
|
+
|
|
104
|
+ def test_retrieving_product_review_returns_200_on_public_product(self):
|
|
105
|
+ product = create_product(is_public=True)
|
|
106
|
+ review = ProductReview.objects.create(product=product, **{
|
|
107
|
+ "title": "Awesome!",
|
|
108
|
+ "score": 5,
|
|
109
|
+ "body": "Wonderful product",
|
|
110
|
+ })
|
|
111
|
+ path = reverse("catalogue:reviews-detail",
|
|
112
|
+ kwargs={"product_slug": product.slug, "product_pk": product.pk, "pk": review.pk})
|
|
113
|
+
|
|
114
|
+ response = self.client.get(path)
|
|
115
|
+
|
|
116
|
+ self.assertEqual(response.status_code, 200)
|