def setUpModule(): DDFLibrary.instance = EXCLUSIVE_DDF_LIBRARY G(ModelForDDFSetup, integer=9999, shelve=True) # using EXCLUSIVE_DDF_LIBRARY # isolating setup module test DDFLibrary.instance = DDFLibrary( ) # hacking singleton: start a new DDFLibrary
def setUp(self): DDFLibrary.instance = DDFLibrary( ) # singleton object is cleared by another tests teach(ModelForDDFSetup, integer=9999) # using EXCLUSIVE_DDF_LIBRARY
def tearDown(self): DDFLibrary.instance = DDFLibrary()
def setUp(self): DDFLibrary.instance = DDFLibrary() teach(ModelForDDFSetup, integer=1000, ddf_lesson='test1') teach(ModelForDDFSetup, integer=1001) teach(ModelForDDFSetup, integer=1002, ddf_lesson='test2')
# -*- coding: utf-8 -*- from unittest import TestCase from django_dynamic_fixture import G, DDFLibrary from django_dynamic_fixture.models_test import ModelForDDFSetup from django_dynamic_fixture.tests.ddf_setup import DDF_LIBRARY_FOR_TESTS EXCLUSIVE_DDF_LIBRARY = DDFLibrary() def setUpModule(): DDFLibrary.instance = EXCLUSIVE_DDF_LIBRARY G(ModelForDDFSetup, integer=9999, shelve=True) # using EXCLUSIVE_DDF_LIBRARY # isolating setup module test DDFLibrary.instance = DDFLibrary( ) # hacking singleton: start a new DDFLibrary class ModuleDDFSetUpTest(TestCase): def setUp(self): DDFLibrary.instance = EXCLUSIVE_DDF_LIBRARY # singleton object is cleared by another tests def tearDown(self): DDFLibrary.instance = DDFLibrary() def test_setup_module_load_before_any_test_of_this_module(self): instance = G(ModelForDDFSetup, use_library=True) self.assertEquals(9999, instance.integer)
from django_dynamic_fixture import N, DDFLibrary from django_dynamic_fixture.models_test import ModelForDDFSetup DDF_LIBRARY_FOR_TESTS = DDFLibrary() DDFLibrary.instance = DDF_LIBRARY_FOR_TESTS N(ModelForDDFSetup, integer=1000, shelve='test1') N(ModelForDDFSetup, integer=1001, shelve=True) N(ModelForDDFSetup, integer=1002, shelve='test2') # isolating ddf setup test DDFLibrary.instance = DDFLibrary() # hacking singleton: start a new DDFLibrary
return modeladmin.reverse(urlname, modeladmin.model.objects.first().pk) return modeladmin.reverse(urlname) def register_custom_generators(): GENERATORS = { MoneyField: lambda field: Money( (random.random() * 2 - 1) * 999_999_999, random.choice(CURRENCY_CHOICES)[0], ), CurrencyField: lambda field: random.choice(CURRENCY_CHOICES)[0], models.DurationField: lambda field: datetime.timedelta( seconds=(random.random() * 2 - 1) * 999_999_999 ), } ddflib = DDFLibrary.get_instance() for modeladmin in admin.site._registry.values(): if ( not modeladmin.model._meta.managed or modeladmin.model in ddflib.configs and DDFLibrary.DEFAULT_KEY in ddflib.configs[modeladmin.model] ): continue lessons = {} # yes, the 3-level loop is a bit ugly... # but necessary because we want to use isinstance and not a dict-lookup for field in modeladmin.model._meta.get_fields(): for fieldtype, generator in GENERATORS.items(): if isinstance(field, fieldtype): lessons[field.name] = generator break