Exemplo n.º 1
0
    def test(self):
        def func(cur_tuple, models, field):
            dic = dict(cur_tuple)
            keys = dic.keys()
            if not 'fieldD' in keys:
                return True
            elif dic['fieldD'] % 3 != 1:
                return False
            if not ('fieldE' in keys and 'fieldH' in keys):
                return True
            elif dic['fieldE'] ^ dic['fieldH']:
                return False
            return True

        dfs.size = 30
        dfs.total = 0
        to_be_computed = []
        cur_tup = [('fieldA', 'X'), ('fieldB', 199), ('fieldC', 'general')]
        unique_together = TestModelFieldsTwo._meta.unique_together
        unique = list(unique_together)
        unique = sort_unique_tuples(unique, TestModelFieldsTwo)
        unique_constraints = [unique_items(un_tuple) for un_tuple in unique]
        constraints = [func] + unique_constraints
        dfs(30, cur_tup, 4, to_be_computed, constraints,
            TestModelFieldsTwo, False)
        self.assertEqual(len(list(TestModelFieldsTwo.objects.all())), 30)
        for mdl in list(TestModelFieldsTwo.objects.all()):
            self.assertEqual(mdl.fieldA, 'X')
            self.assertEqual(mdl.fieldB, 199)
            self.assertEqual(mdl.fieldC, 'general')
            self.assertTrue(mdl.fieldD in [13, 19, 31, 43])
            self.assertTrue(mdl.fieldF in [6, 28, 496, 8128, 33550336])
            self.assertTrue(mdl.fieldG in ['Mathematics', 'Physics',
                                           'Chemistry', 'Biology'])
            self.assertTrue(not (mdl.fieldE ^ mdl.fieldH))
Exemplo n.º 2
0
 def test(self):
     constraint = unique_items(('fieldA', 'fieldD',))
     model = TestModelFieldsTwo(fieldA='A', fieldD=5, fieldB=10,
                                fieldC='Winner', fieldE=True, fieldF=6,
                                fieldG='Mathematics', fieldH=False)
     model.save()
     fields = list_of_fields(TestModelFields)
     self.assertFalse(constraint([('fieldA', 'A'), ('fieldD', 5)],
                                 TestModelFieldsTwo, fields[5]))
     self.assertTrue(constraint([('fieldA', 'A')],
                                TestModelFields, fields[5]))
     self.assertFalse(constraint([('fieldA', 'A'), ('fieldD', 5)],
                                 TestModelFieldsTwo, fields[5]))
     self.assertTrue(constraint([('fieldA', 'A'), ('fieldD', 3)],
                                TestModelFieldsTwo, fields[5]))
     self.assertTrue(constraint([('fieldA', 'A')],
                                TestModelFieldsTwo, fields[5]))
     self.assertTrue(constraint([('fieldA', 'A'), ('fieldD', 3)],
                                TestModelFieldsTwo, fields[5]))