# Path: api_v3/models/review.py
# class Review(models.Model):
#     """Ticket review model."""
# 
#     MAX_DAYS_TO_RESPOND = 7
# 
#     RATINGS = (
#         (-1, 'No'),
#         (0, 'Neutral'),
#         (1, 'Yes')
#     )
# 
#     ticket = models.ForeignKey(
#         Ticket, blank=False, related_name='reviews', db_index=True,
#         on_delete=models.DO_NOTHING)
# 
#     rating = models.IntegerField(
#         default=RATINGS[1][0], choices=RATINGS, db_index=True)
#     link = models.CharField(max_length=255, blank=False, null=True)
#     body = BleachField(blank=False)
#     created_at = models.DateTimeField(auto_now_add=True)
# 
#     @classmethod
#     def ticket_to_token(cls, ticket):
#         """Generates an expiring JWT token with the ticket ID."""
#         return jwt.encode(
#             {
#                 'sub': ticket.id,
#                 'exp': (
#                     datetime.utcnow() +
#                     timedelta(days=cls.MAX_DAYS_TO_RESPOND)
#                 )
#             },
#             settings.SECRET_KEY,
#             algorithm='HS256'
#         )
# 
#     @classmethod
#     def ticket_from_token(cls, token):
#         """Extracts the ticket ID from a valid JWT token."""
#         if token is None or token == '':
#             return None
# 
#         try:
#             payload = jwt.decode(
#                 token, settings.SECRET_KEY, algorithms=['HS256'])
# 
#             return Ticket.objects.get(id=payload.get('sub'))
#         except jwt.ExpiredSignatureError:
#             return None
# 
# Path: api_v3/factories/profile.py
# class ProfileFactory(DjangoModelFactory):
# 
#     class Meta:
#         model = Profile
# 
#     email = Faker('email')
#     first_name = Faker('first_name')
#     last_name = Faker('last_name')
#     bio = Faker('job')
#     last_login = Faker('past_date', start_date='-30d')
# 
# Path: api_v3/factories/responder.py
# class ResponderFactory(DjangoModelFactory):
# 
#     class Meta:
#         model = Responder
# 
#     ticket = SubFactory(TicketFactory)
#     user = SubFactory(ProfileFactory)
# 
# Path: api_v3/factories/review.py
# class ReviewFactory(DjangoModelFactory):
# 
#     class Meta:
#         model = Review
# 
#     ticket = SubFactory(TicketFactory)
#     body = Faker('bs')
# 
# Path: api_v3/tests/views/support.py
# class ApiTestCase(TestCase):
#     JSON_API_CONTENT_TYPE = 'application/vnd.api+json'
#     def as_jsonapi_payload(self, serializer_class, obj, update={}):


import json
from api_v3.models import Review
from api_v3.factories import ProfileFactory, ResponderFactory, ReviewFactory
from .support import ApiTestCase, APIClient, reverse
            ProfileFactory.create(),
            ProfileFactory.create(is_superuser=True)
        ]

        review = ReviewFactory.create(
            ticket__requester=self.users[0],
            rating=Review.RATINGS[2][0]
        )

        self.reviews = [
            review,
            ReviewFactory.create(
                ticket__requester=self.users[0],
                ticket=review.ticket,
                rating=Review.RATINGS[2][0]
            ),
            ReviewFactory.create(
                ticket__requester=self.users[0],
                rating=Review.RATINGS[2][0]
            )
        ]

    def test_list_anonymous(self):
        response = self.client.get(reverse('review_stats-list'))

        self.assertEqual(response.status_code, 401)

    def test_list_user(self):
        self.client.force_authenticate(self.users[0])


# Path: api_v3/models/review.py
# class Review(models.Model):
#     """Ticket review model."""
# 
#     MAX_DAYS_TO_RESPOND = 7
# 
#     RATINGS = (
#         (-1, 'No'),
#         (0, 'Neutral'),
#         (1, 'Yes')
#     )
# 
#     ticket = models.ForeignKey(
#         Ticket, blank=False, related_name='reviews', db_index=True,
#         on_delete=models.DO_NOTHING)
# 
#     rating = models.IntegerField(
#         default=RATINGS[1][0], choices=RATINGS, db_index=True)
#     link = models.CharField(max_length=255, blank=False, null=True)
#     body = BleachField(blank=False)
#     created_at = models.DateTimeField(auto_now_add=True)
# 
#     @classmethod
#     def ticket_to_token(cls, ticket):
#         """Generates an expiring JWT token with the ticket ID."""
#         return jwt.encode(
#             {
#                 'sub': ticket.id,
#                 'exp': (
#                     datetime.utcnow() +
#                     timedelta(days=cls.MAX_DAYS_TO_RESPOND)
#                 )
#             },
#             settings.SECRET_KEY,
#             algorithm='HS256'
#         )
# 
#     @classmethod
#     def ticket_from_token(cls, token):
#         """Extracts the ticket ID from a valid JWT token."""
#         if token is None or token == '':
#             return None
# 
#         try:
#             payload = jwt.decode(
#                 token, settings.SECRET_KEY, algorithms=['HS256'])
# 
#             return Ticket.objects.get(id=payload.get('sub'))
#         except jwt.ExpiredSignatureError:
#             return None
# 
# Path: api_v3/factories/profile.py
# class ProfileFactory(DjangoModelFactory):
# 
#     class Meta:
#         model = Profile
# 
#     email = Faker('email')
#     first_name = Faker('first_name')
#     last_name = Faker('last_name')
#     bio = Faker('job')
#     last_login = Faker('past_date', start_date='-30d')
# 
# Path: api_v3/factories/responder.py
# class ResponderFactory(DjangoModelFactory):
# 
#     class Meta:
#         model = Responder
# 
#     ticket = SubFactory(TicketFactory)
#     user = SubFactory(ProfileFactory)
# 
# Path: api_v3/factories/review.py
# class ReviewFactory(DjangoModelFactory):
# 
#     class Meta:
#         model = Review
# 
#     ticket = SubFactory(TicketFactory)
#     body = Faker('bs')
# 
# Path: api_v3/tests/views/support.py
# class ApiTestCase(TestCase):
#     JSON_API_CONTENT_TYPE = 'application/vnd.api+json'
#     def as_jsonapi_payload(self, serializer_class, obj, update={}):


# Path: api_v3/tests/views/test_review_stats.py
import json
from api_v3.models import Review
from api_v3.factories import ProfileFactory, ResponderFactory, ReviewFactory
from .support import ApiTestCase, APIClient, reverse

            ProfileFactory.create(),
            ProfileFactory.create(is_superuser=True)
        ]

        review = ReviewFactory.create(
            ticket__requester=self.users[0],
            rating=Review.RATINGS[2][0]
        )

        self.reviews = [
            review,
            ReviewFactory.create(
                ticket__requester=self.users[0],
                ticket=review.ticket,
                rating=Review.RATINGS[2][0]
            ),
            ReviewFactory.create(
                ticket__requester=self.users[0],
                rating=Review.RATINGS[2][0]
            )
        ]

    def test_list_anonymous(self):
        response = self.client.get(reverse('review_stats-list'))

        self.assertEqual(response.status_code, 401)

    def test_list_user(self):
        self.client.force_authenticate(self.users[0])


        response = self.client.get(reverse('review_stats-list'))