本文整理汇总了Python中test_haystack.core.models.MockModel类的典型用法代码示例。如果您正苦于以下问题:Python MockModel类的具体用法?Python MockModel怎么用?Python MockModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MockModel类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_prepare
def test_prepare(self):
mock = MockModel()
mock.pk = 1
mock.user = "daniel"
template1 = CharField(use_template=True)
self.assertRaises(SearchFieldError, template1.prepare, mock)
template2 = CharField(use_template=True)
template2.instance_name = "template_x"
self.assertRaises(TemplateDoesNotExist, template2.prepare, mock)
template3 = CharField(use_template=True)
template3.instance_name = "template"
self.assertEqual(template3.prepare(mock), "Indexed!\n1")
template4 = CharField(use_template=True, template_name="search/indexes/foo.txt")
template4.instance_name = "template"
self.assertEqual(template4.prepare(mock), "FOO!\n")
template5 = CharField(
use_template=True, template_name=["foo.txt", "search/indexes/bar.txt"]
)
template5.instance_name = "template"
self.assertEqual(template5.prepare(mock), "BAR!\n")
开发者ID:acdha,项目名称:django-haystack,代码行数:25,代码来源:test_fields.py
示例2: test_prepare
def test_prepare(self):
mock = MockModel()
mock.user = 'daniel'
mock.created = datetime.datetime(2010, 10, 30, 3, 14, 25)
created = FacetDateTimeField(model_attr='created')
self.assertEqual(created.prepare(mock), datetime.datetime(2010, 10, 30, 3, 14, 25))
开发者ID:DevHugo,项目名称:django-haystack,代码行数:7,代码来源:test_fields.py
示例3: test_prepare_from_string
def test_prepare_from_string(self):
mock = MockModel()
mock.pub_date = "2016-02-16T10:01:02Z"
pub_date = DateTimeField(model_attr="pub_date")
self.assertEqual(
pub_date.prepare(mock), datetime.datetime(2016, 2, 16, 10, 1, 2)
)
开发者ID:acdha,项目名称:django-haystack,代码行数:8,代码来源:test_fields.py
示例4: test_prepare
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,代码行数:8,代码来源:test_indexes.py
示例5: test_custom_index_fieldname
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,代码行数:11,代码来源:test_indexes.py
示例6: test_custom_prepare
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,代码行数:11,代码来源:test_indexes.py
示例7: test_prepare
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,代码行数:11,代码来源:test_indexes.py
示例8: test_update_object
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,代码行数:12,代码来源:test_indexes.py
示例9: test_nullable
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,代码行数:13,代码来源:test_indexes.py
示例10: test_more_like_this
def test_more_like_this(self):
mock = MockModel()
mock.id = 1
msq = MockSearchQuery()
msq.backend = MockSearchBackend("mlt")
ui = connections["default"].get_unified_index()
bmmsi = BasicMockModelSearchIndex()
ui.build(indexes=[bmmsi])
bmmsi.update()
msq.more_like_this(mock)
self.assertEqual(msq.get_count(), 23)
self.assertEqual(int(msq.get_results()[0].pk), MOCK_SEARCH_RESULTS[0].pk)
开发者ID:antonyr,项目名称:django-haystack,代码行数:13,代码来源:test_query.py
示例11: test_custom_index_fieldname
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,代码行数:14,代码来源:test_indexes.py
示例12: test_remove_object
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,代码行数:28,代码来源:test_indexes.py
示例13: test_custom_facet_fields
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,代码行数:15,代码来源:test_indexes.py
示例14: test_update_object
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,代码行数:15,代码来源:test_indexes.py
示例15: test_custom_prepare_author
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,代码行数:43,代码来源:test_indexes.py
示例16: test_custom_facet_fields
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"], "Hi, I'm daniel")
self.assertEqual(prepared_data["pub_date_exact"], "2010-10-26T01:54:32")
开发者ID:acdha,项目名称:django-haystack,代码行数:39,代码来源:test_indexes.py
注:本文中的test_haystack.core.models.MockModel类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论