# Path: doj/tests/db/models.py
# class TestModel(models.Model):
# 
#     field_1 = models.BigIntegerField(default=9223372036854775807)
#     field_2 = models.BinaryField(default="010101010101010101010101")  # Causes problems with SQLite
#     field_3 = models.BooleanField(default=True)
#     field_4 = models.CharField(max_length=256, default="abc")
#     field_5 = models.DateField(auto_now_add=True)
#     field_6 = models.DateTimeField(auto_now_add=True)
#     field_7 = models.DecimalField(max_digits=5, decimal_places=2, default=123.45)
#     field_8 = models.EmailField(default='test@email.at')
#     field_9 = models.FloatField(default=12.34)
#     field_10 = models.IntegerField(default=1234)
#     field_11 = models.GenericIPAddressField(default='192.0.2.30')
#     field_12 = models.NullBooleanField(default=None)
#     field_13 = models.PositiveIntegerField(default=1234)
#     field_14 = models.PositiveSmallIntegerField(default=1234)
#     field_15 = models.SmallIntegerField(default=1234)
#     field_16 = models.TextField(default="abc")
#     field_18 = models.TimeField(auto_now_add=True)
#     field_19 = models.ForeignKey('TestModelRelation', related_name='test_models', null=True, blank=True)
# 
# class TestModelRelation(models.Model):
# 
#     field_1 = models.BigIntegerField(default=1234)


from datetime import datetime
from django.test import TestCase
from django.db import transaction
from django.db.models import Count, Min, Max, Avg, Sum
from django.db.models.query import EmptyQuerySet
from doj.tests.db.models import TestModel, TestModelRelation

    def test_inserting_relations(self):
        test_relation = TestModelRelation()
        test_relation.save()

        for _ in range(0, DBTestCase.NUMBER_OF_RELATIONS):
            test_model = TestModel()
            test_model.save()
            test_relation.test_models.add(test_model)

        self.assertEqual(test_relation.test_models.all()[0].field_4, 'abc')
        self.assertEqual(test_relation.test_models.all().count(), DBTestCase.NUMBER_OF_RELATIONS)

    def test_related_lookup(self):
        test_model = None

        test_relation = TestModelRelation()
        test_relation.save()

        for _ in range(0, DBTestCase.NUMBER_OF_RELATIONS):
            test_model = TestModel()
            test_model.save()
            test_relation.test_models.add(test_model)

        test_model = TestModel.objects.select_related('field_19').get(id=test_model.id)

        self.assertEqual(test_model.field_19.field_1, 1234)

    def test_limit_related_lookup(self):
        for _ in range(0, DBTestCase.NUMBER_OF_RECORDS):

# Path: doj/tests/db/models.py
# class TestModel(models.Model):
# 
#     field_1 = models.BigIntegerField(default=9223372036854775807)
#     field_2 = models.BinaryField(default="010101010101010101010101")  # Causes problems with SQLite
#     field_3 = models.BooleanField(default=True)
#     field_4 = models.CharField(max_length=256, default="abc")
#     field_5 = models.DateField(auto_now_add=True)
#     field_6 = models.DateTimeField(auto_now_add=True)
#     field_7 = models.DecimalField(max_digits=5, decimal_places=2, default=123.45)
#     field_8 = models.EmailField(default='test@email.at')
#     field_9 = models.FloatField(default=12.34)
#     field_10 = models.IntegerField(default=1234)
#     field_11 = models.GenericIPAddressField(default='192.0.2.30')
#     field_12 = models.NullBooleanField(default=None)
#     field_13 = models.PositiveIntegerField(default=1234)
#     field_14 = models.PositiveSmallIntegerField(default=1234)
#     field_15 = models.SmallIntegerField(default=1234)
#     field_16 = models.TextField(default="abc")
#     field_18 = models.TimeField(auto_now_add=True)
#     field_19 = models.ForeignKey('TestModelRelation', related_name='test_models', null=True, blank=True)
# 
# class TestModelRelation(models.Model):
# 
#     field_1 = models.BigIntegerField(default=1234)


# Path: doj/tests/db/tests.py
from datetime import datetime
from django.test import TestCase
from django.db import transaction
from django.db.models import Count, Min, Max, Avg, Sum
from django.db.models.query import EmptyQuerySet
from doj.tests.db.models import TestModel, TestModelRelation


    def test_inserting_relations(self):
        test_relation = TestModelRelation()
        test_relation.save()

        for _ in range(0, DBTestCase.NUMBER_OF_RELATIONS):
            test_model = TestModel()
            test_model.save()
            test_relation.test_models.add(test_model)

        self.assertEqual(test_relation.test_models.all()[0].field_4, 'abc')
        self.assertEqual(test_relation.test_models.all().count(), DBTestCase.NUMBER_OF_RELATIONS)

    def test_related_lookup(self):
        test_model = None

        test_relation = TestModelRelation()
        test_relation.save()

        for _ in range(0, DBTestCase.NUMBER_OF_RELATIONS):
            test_model = TestModel()
            test_model.save()
            test_relation.test_models.add(test_model)

        test_model = TestModel.objects.select_related('field_19').get(id=test_model.id)

        self.assertEqual(test_model.field_19.field_1, 1234)

    def test_limit_related_lookup(self):
        for _ in range(0, DBTestCase.NUMBER_OF_RECORDS):

            test_model = TestModel()