# 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
class DBTestCase(TestCase):
    NUMBER_OF_RECORDS = 10
    NUMBER_OF_RELATIONS = 2

    def setUp(self):
        TestModel.objects.all().delete()
        TestModelRelation.objects.all().delete()

    def test_inserting_records(self):
        for _ in range(0, DBTestCase.NUMBER_OF_RECORDS):
            TestModel().save()

        self.assertEqual(TestModel.objects.all()[0].field_4, 'abc')
        self.assertEqual(TestModel.objects.all().count(), DBTestCase.NUMBER_OF_RECORDS)

    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


# 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

class DBTestCase(TestCase):
    NUMBER_OF_RECORDS = 10
    NUMBER_OF_RELATIONS = 2

    def setUp(self):
        TestModel.objects.all().delete()
        TestModelRelation.objects.all().delete()

    def test_inserting_records(self):
        for _ in range(0, DBTestCase.NUMBER_OF_RECORDS):
            TestModel().save()

        self.assertEqual(TestModel.objects.all()[0].field_4, 'abc')
        self.assertEqual(TestModel.objects.all().count(), DBTestCase.NUMBER_OF_RECORDS)

    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()