当前位置: 首页>>代码示例>>Python>>正文


Python fixtureless.Factory类代码示例

本文整理汇总了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'])
开发者ID:neutroninteractive,项目名称:django-fixtureless,代码行数:30,代码来源:factory.py

示例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)
开发者ID:neutroninteractive,项目名称:django-fixtureless,代码行数:28,代码来源:factory.py

示例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'])
开发者ID:neutroninteractive,项目名称:django-fixtureless,代码行数:26,代码来源:factory.py

示例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)
开发者ID:neutroninteractive,项目名称:django-fixtureless,代码行数:26,代码来源:factory.py

示例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])
开发者ID:neutroninteractive,项目名称:django-fixtureless,代码行数:8,代码来源:factory.py

示例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)
开发者ID:neutroninteractive,项目名称:django-fixtureless,代码行数:9,代码来源:factory.py

示例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'])
开发者ID:neutroninteractive,项目名称:django-fixtureless,代码行数:10,代码来源:factory.py

示例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)
开发者ID:neutroninteractive,项目名称:django-fixtureless,代码行数:10,代码来源:factory.py

示例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)
开发者ID:neutroninteractive,项目名称:django-fixtureless,代码行数:12,代码来源:factory.py

示例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)
开发者ID:ricomoss,项目名称:july-2015-django-class,代码行数:12,代码来源:test_models.py

示例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)
开发者ID:neutroninteractive,项目名称:django-fixtureless,代码行数:13,代码来源:factory.py

示例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)
开发者ID:alexrybrown,项目名称:django_test,代码行数:14,代码来源:tests.py

示例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)
开发者ID:neutroninteractive,项目名称:django-fixtureless,代码行数:15,代码来源:factory.py

示例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)
开发者ID:neutroninteractive,项目名称:django-fixtureless,代码行数:15,代码来源:factory.py

示例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'])
开发者ID:neutroninteractive,项目名称:django-fixtureless,代码行数:15,代码来源:factory.py


注:本文中的fixtureless.Factory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。