import factory

from nodeconductor.iaas import models
from nodeconductor.cloud.tests import factories as cloud_factories
from nodeconductor.structure.tests import factories as structure_factories


class TemplateFactory(factory.DjangoModelFactory):
    class Meta(object):
        model = models.Template

    name = factory.Sequence(lambda n: 'template%s' % n)


class InstanceFactory(factory.DjangoModelFactory):
    class Meta(object):
        model = models.Instance

    hostname = factory.Sequence(lambda n: 'host%s' % n)
    template = factory.SubFactory(TemplateFactory)
    flavor = factory.SubFactory(cloud_factories.FlavorFactory)
    project = factory.SubFactory(structure_factories.ProjectFactory, cloud=factory.SelfAttribute('..flavor.cloud'))

@@ -190,16 +190,33 @@
 tories%0A%0A
+import datetime%0A%0A
 %0Aclass T
@@ -720,16 +720,49 @@
 Factory,
+%0A                                
  cloud=f
@@ -801,8 +801,320 @@
 loud'))%0A
+%0A%0Aclass PurchaseFactory(factory.DjangoModelFactory):%0A    class Meta(object):%0A        model = models.Purchase%0A%0A    date = factory.LazyAttribute(lambda o: datetime.datetime.now())%0A    user = factory.SubFactory(structure_factories.UserFactory)%0A    project = factory.SubFactory(structure_factories.ProjectFactory)%0A%0A%0A

Add purchase history factory