# Path: kobra/factories.py
# class DiscountFactory(factory.DjangoModelFactory):
#     ticket_type = factory.SubFactory(TicketTypeFactory)
#     union = factory.Iterator(Union.objects.all())
#     amount = factory.fuzzy.FuzzyInteger(5, 30)
# 
#     class Meta:
#         model = Discount
# 
# class DiscountRegistrationFactory(factory.DjangoModelFactory):
#     discount = factory.SubFactory(DiscountFactory)
#     student = factory.SubFactory(StudentFactory)
# 
#     class Meta:
#         model = DiscountRegistration
# 
# class StudentFactory(factory.DjangoModelFactory):
#     name = factory.Faker('name')
#     liu_id = factory.LazyAttributeSequence(
#         lambda self, seq: '{:.5}{:03d}'.format(
#             self.name.lower(), seq))
#     mifare_id = factory.fuzzy.FuzzyInteger(0, 0xffffffffffffff)
# 
#     union = factory.SubFactory(UnionFactory)
#     section = factory.SubFactory(SectionFactory)
# 
#     email = factory.Faker('email')
# 
#     id = factory.LazyFunction(uuid.uuid4)
#     liu_lin = factory.LazyFunction(uuid.uuid4)
# 
#     class Meta:
#         model = Student
# 
# class UnionFactory(factory.DjangoModelFactory):
#     name = factory.Faker('company')
# 
#     class Meta:
#         model = Union
# 
# class UserFactory(factory.DjangoModelFactory):
#     name = factory.Faker('name')
# 
#     email = factory.Faker('email')
# 
#     class Meta:
#         model = settings.AUTH_USER_MODEL


from rest_framework import status
from rest_framework.reverse import reverse
from rest_framework.test import APITestCase
from ....factories import (DiscountFactory, DiscountRegistrationFactory,
                           StudentFactory, UnionFactory, UserFactory)

        response = self.client.post(url, data=request_data)
        self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)

    def test_create_authenticated_unowned_discount(self):
        url = reverse('v1:discountregistration-list')
        user = UserFactory()

        union = UnionFactory()
        discount = DiscountFactory(union=union)
        student = StudentFactory(union=union)

        request_data = {
            'discount': reverse(
                'v1:discount-detail',
                kwargs={'pk': discount.pk}),
            'student': reverse(
                'v1:student-detail',
                kwargs={'pk': student.pk})
        }

        self.client.force_authenticate(user)
        response = self.client.post(url, data=request_data)
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

    def test_create_authenticated_owned_discount(self):
        url = reverse('v1:discountregistration-list')
        user = UserFactory()

        union = UnionFactory()

# Path: kobra/factories.py
# class DiscountFactory(factory.DjangoModelFactory):
#     ticket_type = factory.SubFactory(TicketTypeFactory)
#     union = factory.Iterator(Union.objects.all())
#     amount = factory.fuzzy.FuzzyInteger(5, 30)
# 
#     class Meta:
#         model = Discount
# 
# class DiscountRegistrationFactory(factory.DjangoModelFactory):
#     discount = factory.SubFactory(DiscountFactory)
#     student = factory.SubFactory(StudentFactory)
# 
#     class Meta:
#         model = DiscountRegistration
# 
# class StudentFactory(factory.DjangoModelFactory):
#     name = factory.Faker('name')
#     liu_id = factory.LazyAttributeSequence(
#         lambda self, seq: '{:.5}{:03d}'.format(
#             self.name.lower(), seq))
#     mifare_id = factory.fuzzy.FuzzyInteger(0, 0xffffffffffffff)
# 
#     union = factory.SubFactory(UnionFactory)
#     section = factory.SubFactory(SectionFactory)
# 
#     email = factory.Faker('email')
# 
#     id = factory.LazyFunction(uuid.uuid4)
#     liu_lin = factory.LazyFunction(uuid.uuid4)
# 
#     class Meta:
#         model = Student
# 
# class UnionFactory(factory.DjangoModelFactory):
#     name = factory.Faker('company')
# 
#     class Meta:
#         model = Union
# 
# class UserFactory(factory.DjangoModelFactory):
#     name = factory.Faker('name')
# 
#     email = factory.Faker('email')
# 
#     class Meta:
#         model = settings.AUTH_USER_MODEL


# Path: kobra/api/v1/tests/test_discount_registrations.py
from rest_framework import status
from rest_framework.reverse import reverse
from rest_framework.test import APITestCase
from ....factories import (DiscountFactory, DiscountRegistrationFactory,
                           StudentFactory, UnionFactory, UserFactory)


        response = self.client.post(url, data=request_data)
        self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)

    def test_create_authenticated_unowned_discount(self):
        url = reverse('v1:discountregistration-list')
        user = UserFactory()

        union = UnionFactory()
        discount = DiscountFactory(union=union)
        student = StudentFactory(union=union)

        request_data = {
            'discount': reverse(
                'v1:discount-detail',
                kwargs={'pk': discount.pk}),
            'student': reverse(
                'v1:student-detail',
                kwargs={'pk': student.pk})
        }

        self.client.force_authenticate(user)
        response = self.client.post(url, data=request_data)
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

    def test_create_authenticated_owned_discount(self):
        url = reverse('v1:discountregistration-list')
        user = UserFactory()

        union = UnionFactory()

        discount = DiscountFactory(union=union)