winofy-backend/apps/reviews/tests/test_reviews.py
Ali Asadi 52adc732fa Initial Winofy backend: marketplace core (no payment integration)
Django 6 + DRF resource server against the Gooyal accounts OAuth2 service,
matching the Winsoo ecosystem's conventions. Covers locations, stores,
catalog, cart, checkout/orders (with the multi-store-cart split and the
status stepper), reviews, and notifications, plus a demo-data seed command.

Payment integration (wallet debits, online gateway, seller payouts) is
intentionally left out here — see feature/payment.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-10 14:03:15 +03:30

56 lines
2.5 KiB
Python

from apps.orders.models import Order, OrderGroup
from apps.reviews.models import Review
from apps.orders.tests.base import OrdersTestCase
class ReviewTests(OrdersTestCase):
def setUp(self):
self.mock_external_clients()
self.client.force_authenticate(user=self.customer)
self.add_to_cart(self.product1, quantity=1)
response = self.client.post('/api/v1/checkout/', {
'address_uuid': str(self.address.uuid),
'payment_method': OrderGroup.PaymentMethod.CASH_ON_DELIVERY,
})
self.order = Order.objects.get(uuid=response.data['orders'][0]['uuid'])
def _deliver_order(self):
self.client.force_authenticate(user=self.seller1)
for action in ('confirm', 'mark-ready', 'mark-shipped', 'mark-delivered'):
self.client.post(f'/api/v1/seller/orders/{self.order.uuid}/{action}/')
self.client.force_authenticate(user=self.customer)
def test_cannot_review_before_delivery(self):
response = self.client.post('/api/v1/reviews/', {
'order_uuid': str(self.order.uuid), 'rating': 5, 'comment': 'خوب بود',
})
self.assertEqual(response.status_code, 400)
def test_can_review_after_delivery_and_store_rating_updates(self):
self._deliver_order()
response = self.client.post('/api/v1/reviews/', {
'order_uuid': str(self.order.uuid), 'rating': 4, 'comment': 'راضی بودم',
})
self.assertEqual(response.status_code, 201, response.data)
self.store1.refresh_from_db()
self.assertEqual(self.store1.rating_avg, 4)
self.assertEqual(self.store1.rating_count, 1)
def test_cannot_review_the_same_order_twice(self):
self._deliver_order()
self.client.post('/api/v1/reviews/', {'order_uuid': str(self.order.uuid), 'rating': 4})
response = self.client.post('/api/v1/reviews/', {'order_uuid': str(self.order.uuid), 'rating': 5})
self.assertEqual(response.status_code, 400)
def test_seller_can_reply_to_a_review(self):
self._deliver_order()
self.client.post('/api/v1/reviews/', {'order_uuid': str(self.order.uuid), 'rating': 4})
review = Review.objects.get(order=self.order)
self.client.force_authenticate(user=self.seller1)
response = self.client.post(f'/api/v1/seller/reviews/{review.uuid}/reply/', {'seller_reply': 'ممنون از شما'})
self.assertEqual(response.status_code, 200, response.data)
review.refresh_from_db()
self.assertEqual(review.seller_reply, 'ممنون از شما')