本文整理汇总了Python中mockups.base.Mockup类的典型用法代码示例。如果您正苦于以下问题:Python Mockup类的具体用法?Python Mockup怎么用?Python Mockup使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Mockup类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_constraints
def test_constraints(self):
filler = Mockup(BasicModel)
for obj in filler.create(100):
self.assertTrue(len(obj.chars) > 0)
self.assertEqual(type(obj.chars), unicode)
self.assertTrue(len(obj.shortchars) <= 2)
self.assertEqual(type(obj.shortchars), unicode)
self.assertTrue(type(obj.blankchars), unicode)
self.assertEqualOr(type(obj.nullchars), unicode, None)
self.assertEqual(type(obj.slugfield), unicode)
self.assertEqual(type(obj.defaultint), int)
self.assertEqual(obj.defaultint, 1)
self.assertEqual(type(obj.intfield), int)
self.assertEqual(type(obj.sintfield), int)
self.assertEqual(type(obj.pintfield), int)
self.assertEqual(type(obj.psintfield), int)
self.assertEqual(type(obj.datefield), date)
self.assertEqual(type(obj.datetimefield), datetime)
self.assertEqual(type(obj.defaultdatetime), datetime)
self.assertEqual(obj.defaultdatetime, y2k())
self.assertEqual(type(obj.decimalfield), Decimal)
self.assertTrue("@" in obj.emailfield)
self.assertTrue("." in obj.emailfield)
self.assertTrue(" " not in obj.emailfield)
self.assertTrue(obj.ipaddressfield.count("."), 3)
self.assertTrue(len(obj.ipaddressfield) >= 7)
self.assertEqual(BasicModel.objects.count(), 100)
示例2: test_follow_m2m
def test_follow_m2m(self):
related = Mockup(SimpleModel).create()[0]
self.assertEqual(SimpleModel.objects.count(), 1)
filler = Mockup(M2MModel, follow_m2m=(2, 10))
for obj in filler.create(10):
self.assertEqual(list(obj.m2m.all()), [related])
示例3: test_generate_m2m_with_intermediary_model
def test_generate_m2m_with_intermediary_model(self):
filler = Mockup(M2MModelThrough, generate_m2m=(1, 5))
all_m2m = set()
for obj in filler.create(10):
self.assertTrue(1 <= obj.m2m.count() <= 5)
all_m2m.update(obj.m2m.all())
self.assertEqual(SimpleModel.objects.count(), len(all_m2m))
示例4: test_deep_generate_foreignkeys
def test_deep_generate_foreignkeys(self):
filler = Mockup(
DeepLinkModel2,
generate_fk=True)
for obj in filler.create(10):
self.assertEqual(obj.related.__class__, DeepLinkModel1)
self.assertEqual(obj.related.related.__class__, SimpleModel)
self.assertEqual(obj.related.related2.__class__, SimpleModel)
示例5: test_generate_foreignkeys
def test_generate_foreignkeys(self):
for m in RELATED_MODELS:
filler = Mockup(
m,
generate_fk=True)
for obj in filler.create(100):
self.assertEqual(obj.related.__class__, BasicModel)
self.assertEqual(obj.limitedfk.name, 'foo')
示例6: test_unique_together
def test_unique_together(self):
filler = Mockup(UniqueTogetherTestModel)
count1 = len(filler.model._meta.
get_field_by_name('choice1')[0].choices)
count2 = len(filler.model._meta.
get_field_by_name('choice2')[0].choices)
for obj in filler.create(count1 * count2):
pass
示例7: test_generate_only_some_foreignkeys
def test_generate_only_some_foreignkeys(self):
for m in RELATED_MODELS:
filler = Mockup(
m,
generate_fk=('related',))
for obj in filler.create(100):
self.assertEqual(obj.related.__class__, BasicModel)
self.assertEqual(obj.limitedfk, None)
示例8: test_generate_fk_for_o2o
def test_generate_fk_for_o2o(self):
# OneToOneField is the same as a ForeignKey with unique=True
filler = Mockup(O2OModel, generate_fk=True)
all_o2o = set()
for obj in filler.create(10):
all_o2o.add(obj.o2o)
self.assertEqual(set(SimpleModel.objects.all()), all_o2o)
示例9: test_follow_fk_for_o2o
def test_follow_fk_for_o2o(self):
# OneToOneField is the same as a ForeignKey with unique=True
filler = Mockup(O2OModel, follow_fk=True)
simple = SimpleModel.objects.create()
obj = filler.create()[0]
self.assertEqual(obj.o2o, simple)
self.assertRaises(CreateInstanceError, filler.create)
示例10: test_deep_generate_foreignkeys2
def test_deep_generate_foreignkeys2(self):
filler = Mockup(
DeepLinkModel2,
follow_fk=False,
generate_fk=('related', 'related__related'))
for obj in filler.create(10):
self.assertEqual(obj.related.__class__, DeepLinkModel1)
self.assertEqual(obj.related.related.__class__, SimpleModel)
self.assertEqual(obj.related.related2, None)
示例11: test_follow_only_some_m2m
def test_follow_only_some_m2m(self):
related = Mockup(SimpleModel).create()[0]
self.assertEqual(SimpleModel.objects.count(), 1)
other_related = Mockup(OtherSimpleModel).create()[0]
self.assertEqual(OtherSimpleModel.objects.count(), 1)
filler = Mockup(M2MModel, follow_m2m={"m2m": (2, 10)})
for obj in filler.create(10):
self.assertEqual(list(obj.m2m.all()), [related])
self.assertEqual(list(obj.secondm2m.all()), [])
示例12: test_generate_only_some_m2m
def test_generate_only_some_m2m(self):
filler = Mockup(M2MModel, generate_m2m={"m2m": (1, 5)})
all_m2m = set()
all_secondm2m = set()
for obj in filler.create(10):
self.assertTrue(1 <= obj.m2m.count() <= 5)
self.assertEqual(0, obj.secondm2m.count())
all_m2m.update(obj.m2m.all())
all_secondm2m.update(obj.secondm2m.all())
self.assertEqual(SimpleModel.objects.count(), len(all_m2m))
self.assertEqual(OtherSimpleModel.objects.count(), len(all_secondm2m))
示例13: test_follow_only_some_foreignkeys
def test_follow_only_some_foreignkeys(self):
related = Mockup(BasicModel).create()[0]
self.assertEqual(BasicModel.objects.count(), 1)
simple = SimpleModel.objects.create(name="foo")
simple2 = SimpleModel.objects.create(name="bar")
for m in RELATED_MODELS:
filler = Mockup(m, follow_fk=("related",))
for obj in filler.create(100):
self.assertEqual(obj.related, related)
self.assertEqual(obj.limitedfk, None)
示例14: test_follow_foreignkeys
def test_follow_foreignkeys(self):
related = Mockup(BasicModel).create()[0]
self.assertEqual(BasicModel.objects.count(), 1)
simple = SimpleModel.objects.create(name='foo')
simple2 = SimpleModel.objects.create(name='bar')
for m in RELATED_MODELS:
filler = Mockup(
m,
follow_fk=True)
for obj in filler.create(100):
self.assertEqual(obj.related, related)
self.assertEqual(obj.limitedfk, simple)
示例15: test_create
def test_create(self):
filler = Mockup(BasicModel)
filler.create(10)
self.assertEqual(BasicModel.objects.count(), 10)