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


Python MockModel.pk方法代码示例

本文整理汇总了Python中test_haystack.core.models.MockModel.pk方法的典型用法代码示例。如果您正苦于以下问题:Python MockModel.pk方法的具体用法?Python MockModel.pk怎么用?Python MockModel.pk使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在test_haystack.core.models.MockModel的用法示例。


在下文中一共展示了MockModel.pk方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_remove_object

# 需要导入模块: from test_haystack.core.models import MockModel [as 别名]
# 或者: from test_haystack.core.models.MockModel import pk [as 别名]
    def test_remove_object(self):
        self.mi.update()
        self.assertEqual(self.sb.search('*')['hits'], 3)

        mock = MockModel()
        mock.pk = 20
        mock.author = 'daniel%s' % mock.id
        mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)

        self.mi.update_object(mock)
        self.assertEqual(self.sb.search('*')['hits'], 4)

        self.mi.remove_object(mock)
        self.assertEqual([(res.content_type(), res.pk) for res in self.sb.search('*')['results']], [(u'core.mockmodel', u'1'), (u'core.mockmodel', u'2'), (u'core.mockmodel', u'3')])

        # Put it back so we can test passing kwargs.
        mock = MockModel()
        mock.pk = 20
        mock.author = 'daniel%s' % mock.id
        mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)

        self.mi.update_object(mock)
        self.assertEqual(self.sb.search('*')['hits'], 4)

        self.mi.remove_object(mock, commit=False)
        self.assertEqual([(res.content_type(), res.pk) for res in self.sb.search('*')['results']], [(u'core.mockmodel', u'1'), (u'core.mockmodel', u'2'), (u'core.mockmodel', u'3'), (u'core.mockmodel', u'20')])

        self.sb.clear()
开发者ID:Axiacore,项目名称:django-haystack,代码行数:30,代码来源:test_indexes.py

示例2: test_prepare

# 需要导入模块: from test_haystack.core.models import MockModel [as 别名]
# 或者: from test_haystack.core.models.MockModel import pk [as 别名]
    def test_prepare(self):
        mock = MockModel()
        mock.pk = 1
        pk = IntegerField(model_attr="pk")

        self.assertEqual(pk.prepare(mock), 1)

        # Simulate failed lookups.
        mock_tag = MockTag.objects.create(name="primary")

        mock = MockModel()
        mock.tag = mock_tag
        tag_count = IntegerField(model_attr="tag__count")

        self.assertRaises(SearchFieldError, tag_count.prepare, mock)

        # Simulate default=1.
        mock = MockModel()
        default = IntegerField(default=1)

        self.assertEqual(default.prepare(mock), 1)

        # Simulate null=True.
        mock = MockModel()
        pk_none = IntegerField(model_attr="pk", null=True)

        self.assertEqual(pk_none.prepare(mock), None)
开发者ID:acdha,项目名称:django-haystack,代码行数:29,代码来源:test_fields.py

示例3: test_thread_safety

# 需要导入模块: from test_haystack.core.models import MockModel [as 别名]
# 或者: from test_haystack.core.models.MockModel import pk [as 别名]
    def test_thread_safety(self):
        # This is a regression. ``SearchIndex`` used to write to
        # ``self.prepared_data``, which would leak between threads if things
        # went too fast.
        exceptions = []

        def threaded_prepare(index_queue, index, model):
            try:
                index.queue = index_queue
                prepped = index.prepare(model)
            except Exception as e:
                exceptions.append(e)
                raise

        class ThreadedSearchIndex(GoodMockSearchIndex):
            def prepare_author(self, obj):
                if obj.pk == 20:
                    time.sleep(0.1)
                else:
                    time.sleep(0.5)

                index_queue.put(self.prepared_data['author'])
                return self.prepared_data['author']

        tmi = ThreadedSearchIndex()
        index_queue = queue.Queue()
        mock_1 = MockModel()
        mock_1.pk = 20
        mock_1.author = 'foo'
        mock_1.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)
        mock_2 = MockModel()
        mock_2.pk = 21
        mock_2.author = 'daniel%s' % mock_2.id
        mock_2.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)

        th1 = Thread(target=threaded_prepare, args=(index_queue, tmi, mock_1))
        th2 = Thread(target=threaded_prepare, args=(index_queue, tmi, mock_2))

        th1.start()
        th2.start()
        th1.join()
        th2.join()

        mock_1_result = index_queue.get()
        mock_2_result = index_queue.get()
        self.assertEqual(mock_1_result, u'foo')
        self.assertEqual(mock_2_result, u'daniel21')
开发者ID:Axiacore,项目名称:django-haystack,代码行数:49,代码来源:test_indexes.py

示例4: test_prepare

# 需要导入模块: from test_haystack.core.models import MockModel [as 别名]
# 或者: from test_haystack.core.models.MockModel import pk [as 别名]
    def test_prepare(self):
        mock = MockModel()
        mock.pk = 20
        mock.author = 'daniel%s' % mock.id
        mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)

        self.assertEqual(len(self.mi.prepare(mock)), 7)
        self.assertEqual(sorted(self.mi.prepare(mock).keys()), ['author', 'django_ct', 'django_id', 'extra', 'id', 'pub_date', 'text'])
开发者ID:Axiacore,项目名称:django-haystack,代码行数:10,代码来源:test_indexes.py

示例5: test_prepare

# 需要导入模块: from test_haystack.core.models import MockModel [as 别名]
# 或者: from test_haystack.core.models.MockModel import pk [as 别名]
    def test_prepare(self):
        mock = MockModel()
        mock.pk = 20
        mock.author = "daniel%s" % mock.id
        mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)

        self.assertEqual(len(self.mi.prepare(mock)), 7)
        self.assertEqual(
            sorted(self.mi.prepare(mock).keys()),
            ["author", "django_ct", "django_id", "extra", "id", "pub_date", "text"],
        )
开发者ID:acdha,项目名称:django-haystack,代码行数:13,代码来源:test_indexes.py

示例6: test_custom_index_fieldname

# 需要导入模块: from test_haystack.core.models import MockModel [as 别名]
# 或者: from test_haystack.core.models.MockModel import pk [as 别名]
    def test_custom_index_fieldname(self):
        mock = MockModel()
        mock.pk = 20
        mock.author = 'daniel%s' % mock.id
        mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)

        cofnmi = GoodOverriddenFieldNameMockSearchIndex()
        self.assertEqual(len(cofnmi.prepare(mock)), 6)
        self.assertEqual(sorted(cofnmi.prepare(mock).keys()), ['django_ct', 'django_id', 'hello', 'id', 'more_content', 'name_s'])
        self.assertEqual(cofnmi.prepared_data['name_s'], u'daniel20')
        self.assertEqual(cofnmi.get_content_field(), 'more_content')
开发者ID:Axiacore,项目名称:django-haystack,代码行数:13,代码来源:test_indexes.py

示例7: test_custom_prepare

# 需要导入模块: from test_haystack.core.models import MockModel [as 别名]
# 或者: from test_haystack.core.models.MockModel import pk [as 别名]
    def test_custom_prepare(self):
        mock = MockModel()
        mock.pk = 20
        mock.author = 'daniel%s' % mock.id
        mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)

        self.assertEqual(len(self.cmi.prepare(mock)), 11)
        self.assertEqual(sorted(self.cmi.prepare(mock).keys()), ['author', 'author_exact', 'django_ct', 'django_id', 'extra', 'hello', 'id', 'pub_date', 'pub_date_exact', 'text', 'whee'])

        self.assertEqual(len(self.cmi.full_prepare(mock)), 11)
        self.assertEqual(sorted(self.cmi.full_prepare(mock).keys()), ['author', 'author_exact', 'django_ct', 'django_id', 'extra', 'hello', 'id', 'pub_date', 'pub_date_exact', 'text', 'whee'])
开发者ID:Axiacore,项目名称:django-haystack,代码行数:13,代码来源:test_indexes.py

示例8: test_update_object

# 需要导入模块: from test_haystack.core.models import MockModel [as 别名]
# 或者: from test_haystack.core.models.MockModel import pk [as 别名]
    def test_update_object(self):
        self.sb.clear()
        self.assertEqual(self.sb.search('*')['hits'], 0)

        mock = MockModel()
        mock.pk = 20
        mock.author = 'daniel%s' % mock.id
        mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)

        self.mi.update_object(mock)
        self.assertEqual([(res.content_type(), res.pk) for res in self.sb.search('*')['results']], [(u'core.mockmodel', u'20')])
        self.sb.clear()
开发者ID:Axiacore,项目名称:django-haystack,代码行数:14,代码来源:test_indexes.py

示例9: test_nullable

# 需要导入模块: from test_haystack.core.models import MockModel [as 别名]
# 或者: from test_haystack.core.models.MockModel import pk [as 别名]
    def test_nullable(self):
        mock = MockModel()
        mock.pk = 20
        mock.author = None
        mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)

        prepared_data = self.cnmi.prepare(mock)
        self.assertEqual(len(prepared_data), 6)
        self.assertEqual(sorted(prepared_data.keys()), ['author', 'author_exact', 'django_ct', 'django_id', 'id', 'text'])

        prepared_data = self.cnmi.full_prepare(mock)
        self.assertEqual(len(prepared_data), 4)
        self.assertEqual(sorted(prepared_data.keys()), ['django_ct', 'django_id', 'id', 'text'])
开发者ID:Axiacore,项目名称:django-haystack,代码行数:15,代码来源:test_indexes.py

示例10: test_proper_field_resolution

# 需要导入模块: from test_haystack.core.models import MockModel [as 别名]
# 或者: from test_haystack.core.models.MockModel import pk [as 别名]
    def test_proper_field_resolution(self):
        mrofsc = MROFieldsSearchChild()
        mock = MockModel()
        mock.pk = 20
        mock.author = 'daniel%s' % mock.id
        mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)
        mock.test_a = 'This is A'
        mock.test_b = 'This is B'

        self.assertEqual(len(mrofsc.fields), 1)
        prepped_data = mrofsc.prepare(mock)
        self.assertEqual(len(prepped_data), 4)
        self.assertEqual(prepped_data['text'], 'This is A')
开发者ID:Axiacore,项目名称:django-haystack,代码行数:15,代码来源:test_indexes.py

示例11: test_remove_object

# 需要导入模块: from test_haystack.core.models import MockModel [as 别名]
# 或者: from test_haystack.core.models.MockModel import pk [as 别名]
    def test_remove_object(self):
        self.mi.update()
        self.assertEqual(self.sb.search("*")["hits"], 3)

        mock = MockModel()
        mock.pk = 20
        mock.author = "daniel%s" % mock.id
        mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)

        self.mi.update_object(mock)
        self.assertEqual(self.sb.search("*")["hits"], 4)

        self.mi.remove_object(mock)
        self.assertEqual(
            [(res.content_type(), res.pk) for res in self.sb.search("*")["results"]],
            [("core.mockmodel", "1"), ("core.mockmodel", "2"), ("core.mockmodel", "3")],
        )

        # Put it back so we can test passing kwargs.
        mock = MockModel()
        mock.pk = 20
        mock.author = "daniel%s" % mock.id
        mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)

        self.mi.update_object(mock)
        self.assertEqual(self.sb.search("*")["hits"], 4)

        self.mi.remove_object(mock, commit=False)
        self.assertEqual(
            [(res.content_type(), res.pk) for res in self.sb.search("*")["results"]],
            [
                ("core.mockmodel", "1"),
                ("core.mockmodel", "2"),
                ("core.mockmodel", "3"),
                ("core.mockmodel", "20"),
            ],
        )

        self.sb.clear()
开发者ID:acdha,项目名称:django-haystack,代码行数:41,代码来源:test_indexes.py

示例12: test_custom_index_fieldname

# 需要导入模块: from test_haystack.core.models import MockModel [as 别名]
# 或者: from test_haystack.core.models.MockModel import pk [as 别名]
    def test_custom_index_fieldname(self):
        mock = MockModel()
        mock.pk = 20
        mock.author = "daniel%s" % mock.id
        mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)

        cofnmi = GoodOverriddenFieldNameMockSearchIndex()
        self.assertEqual(len(cofnmi.prepare(mock)), 6)
        self.assertEqual(
            sorted(cofnmi.prepare(mock).keys()),
            ["django_ct", "django_id", "hello", "id", "more_content", "name_s"],
        )
        self.assertEqual(cofnmi.prepared_data["name_s"], "daniel20")
        self.assertEqual(cofnmi.get_content_field(), "more_content")
开发者ID:acdha,项目名称:django-haystack,代码行数:16,代码来源:test_indexes.py

示例13: test_custom_facet_fields

# 需要导入模块: from test_haystack.core.models import MockModel [as 别名]
# 或者: from test_haystack.core.models.MockModel import pk [as 别名]
    def test_custom_facet_fields(self):
        mock = MockModel()
        mock.pk = 20
        mock.author = 'daniel'
        mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)

        prepared_data = self.gfmsi.prepare(mock)
        self.assertEqual(len(prepared_data), 8)
        self.assertEqual(sorted(prepared_data.keys()), ['author', 'author_foo', 'django_ct', 'django_id', 'id', 'pub_date', 'pub_date_exact', 'text'])

        prepared_data = self.gfmsi.full_prepare(mock)
        self.assertEqual(len(prepared_data), 8)
        self.assertEqual(sorted(prepared_data.keys()), ['author', 'author_foo', 'django_ct', 'django_id', 'id', 'pub_date', 'pub_date_exact', 'text'])
        self.assertEqual(prepared_data['author_foo'], u"Hi, I'm daniel")
        self.assertEqual(prepared_data['pub_date_exact'], '2010-10-26T01:54:32')
开发者ID:Axiacore,项目名称:django-haystack,代码行数:17,代码来源:test_indexes.py

示例14: test_update_object

# 需要导入模块: from test_haystack.core.models import MockModel [as 别名]
# 或者: from test_haystack.core.models.MockModel import pk [as 别名]
    def test_update_object(self):
        self.sb.clear()
        self.assertEqual(self.sb.search("*")["hits"], 0)

        mock = MockModel()
        mock.pk = 20
        mock.author = "daniel%s" % mock.id
        mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)

        self.mi.update_object(mock)
        self.assertEqual(
            [(res.content_type(), res.pk) for res in self.sb.search("*")["results"]],
            [("core.mockmodel", "20")],
        )
        self.sb.clear()
开发者ID:acdha,项目名称:django-haystack,代码行数:17,代码来源:test_indexes.py

示例15: test_custom_prepare_author

# 需要导入模块: from test_haystack.core.models import MockModel [as 别名]
# 或者: from test_haystack.core.models.MockModel import pk [as 别名]
    def test_custom_prepare_author(self):
        mock = MockModel()
        mock.pk = 20
        mock.author = "daniel%s" % mock.id
        mock.pub_date = datetime.datetime(2009, 1, 31, 4, 19, 0)

        self.assertEqual(len(self.cmi.prepare(mock)), 11)
        self.assertEqual(
            sorted(self.cmi.prepare(mock).keys()),
            [
                "author",
                "author_exact",
                "django_ct",
                "django_id",
                "extra",
                "hello",
                "id",
                "pub_date",
                "pub_date_exact",
                "text",
                "whee",
            ],
        )

        self.assertEqual(len(self.cmi.full_prepare(mock)), 11)
        self.assertEqual(
            sorted(self.cmi.full_prepare(mock).keys()),
            [
                "author",
                "author_exact",
                "django_ct",
                "django_id",
                "extra",
                "hello",
                "id",
                "pub_date",
                "pub_date_exact",
                "text",
                "whee",
            ],
        )
        self.assertEqual(self.cmi.prepared_data["author"], "Hi, I'm daniel20")
        self.assertEqual(self.cmi.prepared_data["author_exact"], "Hi, I'm daniel20")
开发者ID:acdha,项目名称:django-haystack,代码行数:45,代码来源:test_indexes.py


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