test_querysetsequence.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:django-querysetsequence 作者: percipient 项目源码 文件源码
def test_model(self):
        """The model should be an instance of Book."""
        # The replaced model should be on both the QuerySet and Query.
        self.assertIs(self.all.query._querysets[0].model,
                      self.all.query._querysets[0].query.model)

        # It's still an instance of the original model.
        first = self.all[0]
        self.assertIsInstance(first, Book)
        # But it also has a new superclass.
        self.assertIn('queryset_sequence.QuerySequenceModel',
                      map(lambda cls: cls.__module__ + '.' + cls.__name__,
                          first.__class__.__mro__))

        # Note that a bunch of meta properties get re-labeled. This is OK.
        options = first._meta
        self.assertTrue(
            options.app_label.startswith('queryset_sequence.'))
        self.assertEquals(options.model_name, 'querysequencemodel')
        self.assertEquals(options.object_name, 'QuerySequenceModel')

        # Django >= 1.9 the label attribute exists. Otherwise, cast to a string.
        object_name = 'QuerySequenceModel'
        try:
            label = options.label
        except AttributeError:
            label = str(options)
            object_name = object_name.lower()
        self.assertTrue(label.startswith('queryset_sequence'))
        self.assertTrue(label.endswith(object_name))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号