本文整理汇总了Python中fixtureless.Factory.create方法的典型用法代码示例。如果您正苦于以下问题:Python Factory.create方法的具体用法?Python Factory.create怎么用?Python Factory.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fixtureless.Factory
的用法示例。
在下文中一共展示了Factory.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ReviewTestCase
# 需要导入模块: from fixtureless import Factory [as 别名]
# 或者: from fixtureless.Factory import create [as 别名]
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)
示例2: test_create_with_multi_model_and_single_count_and_single_initial
# 需要导入模块: from fixtureless import Factory [as 别名]
# 或者: from fixtureless.Factory import create [as 别名]
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_create_with_multi_model_and_multi_count
# 需要导入模块: from fixtureless import Factory [as 别名]
# 或者: from fixtureless.Factory import create [as 别名]
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)
示例4: SuperSnazzyModelTests
# 需要导入模块: from fixtureless import Factory [as 别名]
# 或者: from fixtureless.Factory import create [as 别名]
class SuperSnazzyModelTests(TestCase):
def setUp(self):
self.factory = Factory()
def test_sum_fib_nums(self):
initial = {
'fib_index': 0,
'fib_num': '1000',
}
fib_history = self.factory.create(FibHistory, initial)
self.assertEqual(fib_history.do_something_pointless(), 0)
initial = {
'fib_index': 100,
'fib_num': 10,
}
fib_history = self.factory.create(FibHistory, initial)
self.assertEqual(fib_history.do_something_pointless(), 1000)
示例5: test_create_trivial
# 需要导入模块: from fixtureless import Factory [as 别名]
# 或者: from fixtureless.Factory import create [as 别名]
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)
示例6: MageTestCase
# 需要导入模块: from fixtureless import Factory [as 别名]
# 或者: from fixtureless.Factory import create [as 别名]
class MageTestCase(TestCase):
def setUp(self):
self.factory = Factory()
def test_brothers_in_arms(self):
# Exclude the mage itself
mage_1 = self.factory.create(
models.Mage, {'magic_type': constants.ARCANE})
expected = 0
self.assertEqual(mage_1.brothers_in_arms.count(), expected)
# Let's add another mage with another magic_type
self.factory.create(models.Mage, {'magic_type': constants.BLACK})
expected = 0
self.assertEqual(mage_1.brothers_in_arms.count(), expected)
# Let's add another mage with the same magic_type
self.factory.create(models.Mage, {'magic_type': constants.ARCANE})
expected = 1
self.assertEqual(mage_1.brothers_in_arms.count(), expected)
示例7: test_create_with_single_count
# 需要导入模块: from fixtureless import Factory [as 别名]
# 或者: from fixtureless.Factory import create [as 别名]
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)
示例8: create_question
# 需要导入模块: from fixtureless import Factory [as 别名]
# 或者: from fixtureless.Factory import create [as 别名]
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)
示例9: test_create_with_count_and_initial
# 需要导入模块: from fixtureless import Factory [as 别名]
# 或者: from fixtureless.Factory import create [as 别名]
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)
示例10: test_create_with_multi_count
# 需要导入模块: from fixtureless import Factory [as 别名]
# 或者: from fixtureless.Factory import create [as 别名]
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)
示例11: test_create_with_multi_model_trivial
# 需要导入模块: from fixtureless import Factory [as 别名]
# 或者: from fixtureless.Factory import create [as 别名]
def test_create_with_multi_model_trivial(self):
models = ModelOne.objects.all()
self.assertEqual(len(models), 0)
models = ModelTwo.objects.all()
self.assertEqual(len(models), 0)
factory = Factory()
models = factory.create((ModelOne, ), (ModelTwo, ))
self.assertEqual(len(models), 2)
self.assertIsInstance(models[0], ModelOne)
self.assertIsInstance(models[1], ModelTwo)
# Since ModelTwo has a FK and OneToOne to ModelOne we expect 2
models = ModelOne.objects.all()
self.assertEqual(len(models), 2)
models = ModelTwo.objects.all()
self.assertEqual(len(models), 1)
示例12: test_create_with_multi_model_and_multi_count_and_single_initial
# 需要导入模块: from fixtureless import Factory [as 别名]
# 或者: from fixtureless.Factory import create [as 别名]
def test_create_with_multi_model_and_multi_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()
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.create(*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'])
# 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)
示例13: test_create_with_multi_model_and_single_count
# 需要导入模块: from fixtureless import Factory [as 别名]
# 或者: from fixtureless.Factory import create [as 别名]
def test_create_with_multi_model_and_single_count(self):
models = ModelOne.objects.all()
self.assertEqual(len(models), 0)
models = ModelTwo.objects.all()
self.assertEqual(len(models), 0)
factory = Factory()
count1 = 1
count2 = 1
args = ((ModelOne, count1), (ModelTwo, count2))
models = factory.create(*args)
self.assertEqual(len(models), 2)
self.assertIsInstance(models[0], ModelOne)
self.assertIsInstance(models[1], ModelTwo)
# Since ModelTwo has a FK and OneToOne to ModelOne we expect 2
models = ModelOne.objects.all()
self.assertEqual(len(models), 2)
models = ModelTwo.objects.all()
self.assertEqual(len(models), 1)
示例14: test_create_with_multi_count_and_multi_initial
# 需要导入模块: from fixtureless import Factory [as 别名]
# 或者: from fixtureless.Factory import create [as 别名]
def test_create_with_multi_count_and_multi_initial(self):
models = ModelOne.objects.all()
self.assertEqual(len(models), 0)
factory = Factory()
initial1 = {
'decimal_field': Decimal('10.00')
}
initial2 = {
'decimal_field': Decimal('8.00')
}
args = (ModelOne, [initial1, initial2])
models = factory.create(*args)
self.assertEqual(len(models), 2)
self.assertIsInstance(models[0], ModelOne)
self.assertEqual(models[0].decimal_field, initial1['decimal_field'])
self.assertIsInstance(models[1], ModelOne)
self.assertEqual(models[1].decimal_field, initial2['decimal_field'])
models = ModelOne.objects.all()
self.assertEqual(len(models), 2)
示例15: test_create_with_multi_model_and_multi_count_and_multi_initial
# 需要导入模块: from fixtureless import Factory [as 别名]
# 或者: from fixtureless.Factory import create [as 别名]
def test_create_with_multi_model_and_multi_count_and_multi_initial(self):
models = ModelOne.objects.all()
self.assertEqual(len(models), 0)
models = ModelTwo.objects.all()
self.assertEqual(len(models), 0)
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.create(*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'])
# 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), 4)
models = ModelTwo.objects.all()
self.assertEqual(len(models), 2)