def test(self): self.assertEqual(set([ExtendingModel, TestModel0, TestModel1, TestModelA, TestModelB, TestModelC, TestModelD, TestModelE, TestModelX, TestModelY, TestModelFields, SuperClass, ExtendAbstract, ExtendSuperClass, ProxyExtend, SuperAbstract, TestModelFieldsTwo, CycleA, CycleB, CycleC, CycleD, CycleE, CycleF, AllFieldsModel]), set(list_of_models(mdls, keep_abstract=True))) self.assertEqual(set([ExtendingModel, TestModel0, TestModel1, TestModelA, TestModelB, TestModelC, TestModelD, TestModelE, TestModelX, TestModelY, TestModelFields, SuperClass, ExtendAbstract, ExtendSuperClass, TestModelFieldsTwo, ProxyExtend, CycleA, CycleB, CycleC, CycleD, CycleE, CycleF, AllFieldsModel]), set(list_of_models(mdls)))
def test(self): generate_test_data('tests.models', 10) length = len(list_of_models(mdls)) visited = dict(zip(list_of_models(mdls), length * [False])) pairs = [] data_base = dict([(mdl, list(mdl.objects.all())) for mdl in list_of_models(mdls)]) generated_data = data_base.values() nodes = 0 edges = 0 for list_model in generated_data: for model in list_model: visited[model.__class__] = True fields = list_of_fields(model.__class__) nodes += 1 for field in fields: if (not is_auto_field(field) and not is_reverse_related(field)): val = getattr(model, field.name) if is_related(field): if 'ManyToMany' in relation_type(field): r = data_base[field.rel.to] self.assertTrue(list(val.all())) self.assertTrue(all([x in r for x in list(val.all())])) else: r = data_base[field.rel.to] self.assertTrue(val in r) edges += 1 else: this_model = field.model while (this_model != Model and not (hasattr(this_model, 'TestData') and hasattr(this_model.TestData, field.name)) and not os.path.exists( '%s/TestTemplates/sample__%s__%s' % (this_model._meta.app_label, this_model.__name__, field.name))): this_model = this_model.__base__ if this_model == Model: self.assertEqual(model.__class__, AllFieldsModel) sample_values = field_sample_values(field) if val.__class__ == unicode: val = str(val) self.assertTrue(val.__class__ in map(lambda val: val.__class__, sample_values)) elif (field.__class__.__name__ == 'DecimalField' or field.__class__.__name__ == 'FloatField'): sample_values = map(float, field_sample_values(field)) val = float(val) self.assertTrue(any(abs(val - fld_value) < 1e-5 for fld_value in sample_values)) else: sample_values = map(str, field_sample_values(field)) val = str(val) self.assertTrue(val in sample_values) if model.__class__ == TestModelFields: pr = (model.fieldC, model.fieldA) self.assertFalse(pr in pairs) pairs.append(pr) self.assertTrue((model.fieldB < 50) or (model.fieldD / 2 % 2 == 1)) self.assertTrue(all(visited.values()), "Not all the models with sample data are generated.")