本文整理汇总了Python中fixtureless.Factory类的典型用法代码示例。如果您正苦于以下问题:Python Factory类的具体用法?Python Factory怎么用?Python Factory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Factory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_build_with_multi_model_and_multi_count_and_single_initial
def test_build_with_multi_model_and_multi_count_and_single_initial(self):
factory = Factory()
count1 = 2
initial1 = {
'decimal_field': Decimal('10.00')
}
initial_list1 = list()
for _ in itertools.repeat(None, count1):
initial_list1.append(initial1)
count2 = 3
initial2 = {
'char_field': 'test value'
}
initial_list2 = list()
for _ in itertools.repeat(None, count2):
initial_list2.append(initial2)
args = ((ModelOne, initial_list1), (ModelTwo, initial_list2))
models = factory.build(*args)
self.assertEqual(len(models), count1 + count2)
self.assertIsInstance(models[0], ModelOne)
self.assertIsInstance(models[1], ModelOne)
self.assertEqual(models[0].decimal_field, initial1['decimal_field'])
self.assertEqual(models[1].decimal_field, initial1['decimal_field'])
self.assertIsInstance(models[2], ModelTwo)
self.assertIsInstance(models[3], ModelTwo)
self.assertIsInstance(models[4], ModelTwo)
self.assertEqual(models[2].char_field, initial2['char_field'])
self.assertEqual(models[3].char_field, initial2['char_field'])
self.assertEqual(models[4].char_field, initial2['char_field'])
示例2: test_create_with_multi_model_and_single_count_and_single_initial
def test_create_with_multi_model_and_single_count_and_single_initial(self):
models = ModelOne.objects.all()
self.assertEqual(len(models), 0)
models = ModelTwo.objects.all()
self.assertEqual(len(models), 0)
factory = Factory()
initial1 = {
'decimal_field': Decimal('10.00')
}
initial2 = {
'char_field': 'test value'
}
args = ((ModelOne, initial1), (ModelTwo, initial2))
models = factory.create(*args)
self.assertIsInstance(models[0], ModelOne)
self.assertEqual(models[0].decimal_field, initial1['decimal_field'])
self.assertIsInstance(models[1], ModelTwo)
self.assertEqual(models[1].char_field, initial2['char_field'])
# Since ModelTwo has a FK and OneToOne to ModelOne we expect:
# 1 for the count in the factory models
# 1 for each OneToOne fields
models = ModelOne.objects.all()
self.assertEqual(len(models), 2)
models = ModelTwo.objects.all()
self.assertEqual(len(models), 1)
示例3: test_build_with_multi_model_and_multi_count_and_multi_initial
def test_build_with_multi_model_and_multi_count_and_multi_initial(self):
factory = Factory()
initial1_1 = {
'decimal_field': Decimal('10.00')
}
initial1_2 = {
'decimal_field': Decimal('8.00')
}
initial2_1 = {
'char_field': 'test value 1'
}
initial2_2 = {
'char_field': 'test value 2'
}
args = ((ModelOne, [initial1_1, initial1_2]),
(ModelTwo, [initial2_1, initial2_2]))
models = factory.build(*args)
self.assertEqual(len(models), 4)
self.assertIsInstance(models[0], ModelOne)
self.assertIsInstance(models[1], ModelOne)
self.assertEqual(models[0].decimal_field, initial1_1['decimal_field'])
self.assertEqual(models[1].decimal_field, initial1_2['decimal_field'])
self.assertIsInstance(models[2], ModelTwo)
self.assertIsInstance(models[3], ModelTwo)
self.assertEqual(models[2].char_field, initial2_1['char_field'])
self.assertEqual(models[3].char_field, initial2_2['char_field'])
示例4: test_create_with_multi_model_and_multi_count
def test_create_with_multi_model_and_multi_count(self):
models = ModelOne.objects.all()
self.assertEqual(len(models), 0)
models = ModelTwo.objects.all()
self.assertEqual(len(models), 0)
factory = Factory()
count1 = 2
count2 = 3
args = ((ModelOne, count1), (ModelTwo, count2))
models = factory.create(*args)
self.assertEqual(len(models), count1 + count2)
self.assertIsInstance(models[0], ModelOne)
self.assertIsInstance(models[1], ModelOne)
self.assertIsInstance(models[2], ModelTwo)
self.assertIsInstance(models[3], ModelTwo)
self.assertIsInstance(models[4], ModelTwo)
# Since ModelTwo has a FK and OneToOne to ModelOne we expect:
# 1 for the count in the factory models (count1)
# 1 for each OneToOne fields (count2)
models = ModelOne.objects.all()
self.assertEqual(len(models), count1 + count2)
models = ModelTwo.objects.all()
self.assertEqual(len(models), count2)
示例5: test_build_with_multi_count
def test_build_with_multi_count(self):
factory = Factory()
count = 2
models = factory.build(ModelOne, count)
self.assertEqual(len(models), count)
self.assertIsInstance(models[0], ModelOne)
self.assertIsInstance(models[1], ModelOne)
self.assertNotEqual(models[0], models[1])
示例6: test_build_with_multi_model_and_single_count
def test_build_with_multi_model_and_single_count(self):
factory = Factory()
count1 = 1
count2 = 1
args = ((ModelOne, count1), (ModelTwo, count2))
models = factory.build(*args)
self.assertEqual(len(models), 2)
self.assertIsInstance(models[0], ModelOne)
self.assertIsInstance(models[1], ModelTwo)
示例7: test_build_with_count_and_initial
def test_build_with_count_and_initial(self):
factory = Factory()
count = 1
initial = {
'decimal_field': Decimal('10.00')
}
args = (ModelOne, initial)
model = factory.build(*args)
self.assertIsInstance(model, ModelOne)
self.assertEqual(model.decimal_field, initial['decimal_field'])
示例8: test_create_trivial
def test_create_trivial(self):
models = ModelOne.objects.all()
self.assertEqual(len(models), 0)
factory = Factory()
model = factory.create(ModelOne)
self.assertIsInstance(model, ModelOne)
models = ModelOne.objects.all()
self.assertEqual(len(models), 1)
示例9: test_create_with_single_count
def test_create_with_single_count(self):
models = ModelOne.objects.all()
self.assertEqual(len(models), 0)
factory = Factory()
count = 1
args = (ModelOne, count)
model = factory.create(*args)
self.assertIsInstance(model, ModelOne)
models = ModelOne.objects.all()
self.assertEqual(len(models), count)
示例10: ReviewTestCase
class ReviewTestCase(TestCase):
def setUp(self):
self.factory = Factory()
def test_average_rating(self):
meal = self.factory.create(food_models.Meal)
review1_init = {'rating': 1, 'meal': meal}
review2_init = {'rating': 2, 'meal': meal}
self.factory.create(models.Review, (review1_init, review2_init))
expected_results = '1.5 Stars'
self.assertEqual(models.Review.average_rating(meal), expected_results)
示例11: test_build_with_multi_model_and_multi_count
def test_build_with_multi_model_and_multi_count(self):
factory = Factory()
count1 = 2
count2 = 3
args = ((ModelOne, count1), (ModelTwo, count2))
models = factory.build(*args)
self.assertEqual(len(models), count1 + count2)
self.assertIsInstance(models[0], ModelOne)
self.assertIsInstance(models[1], ModelOne)
self.assertIsInstance(models[2], ModelTwo)
self.assertIsInstance(models[3], ModelTwo)
self.assertIsInstance(models[4], ModelTwo)
示例12: create_question
def create_question(question_text='', days=None, time=None):
"""
Creates a question with the given `question_text` and published the
given number of `days` offset to now (negative for questions published
in the past, positive for questions that have yet to be published).
"""
factory = Factory()
if not time:
time = timezone.now() + datetime.timedelta(days=days)
initial = {
'question_text': question_text,
'pub_date': time,
}
return factory.create(Question, initial)
示例13: test_create_with_count_and_initial
def test_create_with_count_and_initial(self):
models = ModelOne.objects.all()
self.assertEqual(len(models), 0)
factory = Factory()
initial = {
'decimal_field': Decimal('10.00')
}
args = (ModelOne, initial)
model = factory.create(*args)
self.assertIsInstance(model, ModelOne)
self.assertEqual(model.decimal_field, initial['decimal_field'])
models = ModelOne.objects.all()
self.assertEqual(len(models), 1)
示例14: test_create_with_multi_count
def test_create_with_multi_count(self):
models = ModelOne.objects.all()
self.assertEqual(len(models), 0)
factory = Factory()
count = 2
args = (ModelOne, count)
models = factory.create(*args)
self.assertEqual(len(models), count)
self.assertIsInstance(models[0], ModelOne)
self.assertIsInstance(models[1], ModelOne)
self.assertNotEqual(models[0], models[1])
models = ModelOne.objects.all()
self.assertEqual(len(models), count)
示例15: test_build_with_multi_model_and_single_count_and_single_initial
def test_build_with_multi_model_and_single_count_and_single_initial(self):
factory = Factory()
initial1 = {
'decimal_field': Decimal('10.00')
}
initial2 = {
'char_field': 'test value'
}
args = ((ModelOne, initial1), (ModelTwo, initial2))
models = factory.build(*args)
self.assertIsInstance(models[0], ModelOne)
self.assertEqual(models[0].decimal_field, initial1['decimal_field'])
self.assertIsInstance(models[1], ModelTwo)
self.assertEqual(models[1].char_field, initial2['char_field'])