# Path: api_v3/factories/attachment.py
# class AttachmentFactory(DjangoModelFactory):
# 
#     class Meta:
#         model = Attachment
# 
#     ticket = SubFactory(TicketFactory)
#     user = SubFactory(ProfileFactory)
#     upload = FileField(filename='țеșт.txt')
# 
# 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/ticket.py
# class TicketFactory(DjangoModelFactory):
# 
#     class Meta:
#         model = Ticket
# 
#     requester = SubFactory(ProfileFactory)
# 
#     status = Faker(
#         'random_element', elements=[s[0] for s in Ticket.STATUSES])
#     kind = Faker(
#         'random_element', elements=[k[0] for k in Ticket.KINDS])
#     request_type = Faker(
#         'random_element', elements=[t[0] for t in Ticket.TYPES])
#     priority = Faker(
#         'random_element', elements=[t[0] for t in Ticket.PRIORITIES])
#     sensitive = Faker('random_element', elements=[True, False])
#     whysensitive = Faker('catch_phrase')
#     deadline_at = Faker('future_datetime', end_date='+30d')
#     countries = Faker(
#         'random_sample', elements=[t[0] for t in COUNTRIES], length=3)
# 
#     background = Faker('bs')
# 
#     first_name = Faker('first_name')
#     last_name = Faker('last_name')
#     born_at = Faker('past_datetime', start_date='-30y')
#     connections = Faker('company')
#     sources = Faker('name')
#     business_activities = Faker('catch_phrase')
# 
#     company_name = Faker('company')
#     country = Faker('random_element', elements=[c[0] for c in COUNTRIES])
# 
# 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={}):


from django.core.files.uploadedfile import SimpleUploadedFile
from api_v3.factories import (
    AttachmentFactory,
    ProfileFactory,
    ResponderFactory,
    TicketFactory
)
from .support import TestCase, APIClient, reverse

    def test_retrieve_anonymous(self):
        response = self.client.get(
            reverse('download-detail', args=[self.attachment.id]))

        self.assertEqual(response.status_code, 401)

    def test_retrieve_auth_not_ticket_user(self):
        self.client.force_authenticate(self.users[2])

        response = self.client.get(
            reverse('download-detail', args=[self.attachment.id]))

        self.assertEqual(response.status_code, 404)

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

        response = self.client.get(
            reverse('download-detail', args=[self.attachment.id]))

        self.assertEqual(response.status_code, 200)
        self.assertNotIn(response.get('Content-Disposition'), 'inline')

    def test_retrieve_auth_ticket_responder(self):
        self.client.force_authenticate(self.users[1])

        response = self.client.get(
            reverse('download-detail', args=[self.attachment.id]))


# Path: api_v3/factories/attachment.py
# class AttachmentFactory(DjangoModelFactory):
# 
#     class Meta:
#         model = Attachment
# 
#     ticket = SubFactory(TicketFactory)
#     user = SubFactory(ProfileFactory)
#     upload = FileField(filename='țеșт.txt')
# 
# 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/ticket.py
# class TicketFactory(DjangoModelFactory):
# 
#     class Meta:
#         model = Ticket
# 
#     requester = SubFactory(ProfileFactory)
# 
#     status = Faker(
#         'random_element', elements=[s[0] for s in Ticket.STATUSES])
#     kind = Faker(
#         'random_element', elements=[k[0] for k in Ticket.KINDS])
#     request_type = Faker(
#         'random_element', elements=[t[0] for t in Ticket.TYPES])
#     priority = Faker(
#         'random_element', elements=[t[0] for t in Ticket.PRIORITIES])
#     sensitive = Faker('random_element', elements=[True, False])
#     whysensitive = Faker('catch_phrase')
#     deadline_at = Faker('future_datetime', end_date='+30d')
#     countries = Faker(
#         'random_sample', elements=[t[0] for t in COUNTRIES], length=3)
# 
#     background = Faker('bs')
# 
#     first_name = Faker('first_name')
#     last_name = Faker('last_name')
#     born_at = Faker('past_datetime', start_date='-30y')
#     connections = Faker('company')
#     sources = Faker('name')
#     business_activities = Faker('catch_phrase')
# 
#     company_name = Faker('company')
#     country = Faker('random_element', elements=[c[0] for c in COUNTRIES])
# 
# 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_download.py
from django.core.files.uploadedfile import SimpleUploadedFile
from api_v3.factories import (
    AttachmentFactory,
    ProfileFactory,
    ResponderFactory,
    TicketFactory
)
from .support import TestCase, APIClient, reverse


    def test_retrieve_anonymous(self):
        response = self.client.get(
            reverse('download-detail', args=[self.attachment.id]))

        self.assertEqual(response.status_code, 401)

    def test_retrieve_auth_not_ticket_user(self):
        self.client.force_authenticate(self.users[2])

        response = self.client.get(
            reverse('download-detail', args=[self.attachment.id]))

        self.assertEqual(response.status_code, 404)

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

        response = self.client.get(
            reverse('download-detail', args=[self.attachment.id]))

        self.assertEqual(response.status_code, 200)
        self.assertNotIn(response.get('Content-Disposition'), 'inline')

    def test_retrieve_auth_ticket_responder(self):
        self.client.force_authenticate(self.users[1])

        response = self.client.get(
            reverse('download-detail', args=[self.attachment.id]))


        self.assertEqual(response.status_code, 200)