# Path: promises_instances/models.py
# class DDAHCategory(Category):
#     instance = models.ForeignKey(DDAHInstance, related_name='categories', null=True, blank=True)
#     order = models.PositiveIntegerField(default=0, blank=False, null=False)
# 
#     class Meta:
#         ordering = ('order', )
# 
# class DDAHInstance(Instance):
#     pass
# 
# class DDAHPromise(Promise):
#     instance = models.ForeignKey(DDAHInstance, related_name='promises', null=True, blank=True)
# 
#     def save(self, *args, **kwargs):
#         if self.category is not None:
#             self.instance = self.category.instance
#         return super(DDAHPromise, self).save()


from django.test import TestCase
from promises_instances.models import DDAHCategory, DDAHInstance, DDAHPromise
from instances.models import Instance
from popolo.models import Person
from promises.models import Promise


class DDAHInstancesTestCase(TestCase):
    def setUp(self):
        self.person = Person.objects.create(name=u"A person")

    def test_create_instance(self):
        '''Create an instance'''
        ddah_instance = DDAHInstance.objects.create(label='label', title='the title')
        self.assertTrue(ddah_instance)
        self.assertIsInstance(ddah_instance, Instance)

    def test_an_instance_can_have_categories(self):
        ddah_instance = DDAHInstance.objects.create(label='label', title='the title')

# Path: promises_instances/models.py
# class DDAHCategory(Category):
#     instance = models.ForeignKey(DDAHInstance, related_name='categories', null=True, blank=True)
#     order = models.PositiveIntegerField(default=0, blank=False, null=False)
# 
#     class Meta:
#         ordering = ('order', )
# 
# class DDAHInstance(Instance):
#     pass
# 
# class DDAHPromise(Promise):
#     instance = models.ForeignKey(DDAHInstance, related_name='promises', null=True, blank=True)
# 
#     def save(self, *args, **kwargs):
#         if self.category is not None:
#             self.instance = self.category.instance
#         return super(DDAHPromise, self).save()


# Path: promises_instances/tests/ddah_instances_tests.py
from django.test import TestCase
from promises_instances.models import DDAHCategory, DDAHInstance, DDAHPromise
from instances.models import Instance
from popolo.models import Person
from promises.models import Promise



class DDAHInstancesTestCase(TestCase):
    def setUp(self):
        self.person = Person.objects.create(name=u"A person")

    def test_create_instance(self):
        '''Create an instance'''
        ddah_instance = DDAHInstance.objects.create(label='label', title='the title')
        self.assertTrue(ddah_instance)
        self.assertIsInstance(ddah_instance, Instance)

    def test_an_instance_can_have_categories(self):
        ddah_instance = DDAHInstance.objects.create(label='label', title='the title')

        category = DDAHCategory.objects.create(name="Education", instance=ddah_instance)