Beispiel #1
0
    def test__get_fields_returns_correct_model(self):
        post_models = [
            i[1] for i in UniqueFieldMixin._get_fields(PostWithUniqField)
        ]
        self.assertTrue(all(model is None for model in post_models))

        inherited_post_models = [
            i[1] for i in UniqueFieldMixin._get_fields(
                InheritedFromPostWithUniqField) if i[1]
        ]

        self.assertEqual(len(inherited_post_models), 6)
        self.assertTrue(
            all(model is PostWithUniqField) for model in inherited_post_models)
Beispiel #2
0
    def test__get_fields_returns_correct_fields(self):
        option_fields = PostWithUniqField._meta.get_fields()
        uniq_mixin_fields = [
            i[0] for i in UniqueFieldMixin._get_fields(PostWithUniqField)
        ]

        self.assertEqual(len(option_fields), 9)
        self.assertEqual(len(uniq_mixin_fields), 7)

        fields_to_be_excluded_from_uniq_mixin_fields = [
            f for f in option_fields if f.is_relation and not f.one_to_one
            and not (f.many_to_one and f.related_model)
        ]

        for field in fields_to_be_excluded_from_uniq_mixin_fields:
            self.assertNotIn(field, uniq_mixin_fields)
Beispiel #3
0
 def test__get_fields_returns_list_of_tulpes(self):
     uniq_mixin_fields = UniqueFieldMixin._get_fields(PostWithUniqField)
     self.assertIsInstance(uniq_mixin_fields, list)
     for field in uniq_mixin_fields:
         self.assertIsInstance(field, tuple)