Skip to content

Commit bd8e512

Browse files
committed
Tests: update test object creation for Django 1.8
Several of the field tests previously assigned a related test model instance before saving it:: mock_tag = MockTag(name='primary') mock = MockModel() mock.tag = mock_tag Django 1.8 now validates this dodgy practice and throws an error. This commit simply changes it to use `create()` so the mock_tag will have a pk before assignment.
1 parent e9849a2 commit bd8e512

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

test_haystack/test_fields.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ def test_prepare(self):
2727
self.assertEqual(author.prepare(mock), u'daniel')
2828

2929
# Do a lookup through the relation.
30-
mock_tag = MockTag(name='primary')
30+
mock_tag = MockTag.objects.create(name='primary')
31+
3132
mock = MockModel()
3233
mock.tag = mock_tag
3334
tag_name = CharField(model_attr='tag__name')
@@ -41,7 +42,8 @@ def test_prepare(self):
4142
self.assertEqual(author.prepare(mock), u'')
4243

4344
# Simulate failed lookups.
44-
mock_tag = MockTag(name='primary')
45+
mock_tag = MockTag.objects.create(name='primary')
46+
4547
mock = MockModel()
4648
mock.tag = mock_tag
4749
tag_slug = CharField(model_attr='tag__slug')
@@ -84,7 +86,8 @@ def test_prepare(self):
8486
self.assertEqual(author.prepare(mock), u'daniel')
8587

8688
# Do a lookup through the relation.
87-
mock_tag = MockTag(name='primary')
89+
mock_tag = MockTag.objects.create(name='primary')
90+
8891
mock = MockModel()
8992
mock.tag = mock_tag
9093
tag_name = NgramField(model_attr='tag__name')
@@ -98,7 +101,8 @@ def test_prepare(self):
98101
self.assertEqual(author.prepare(mock), u'')
99102

100103
# Simulate failed lookups.
101-
mock_tag = MockTag(name='primary')
104+
mock_tag = MockTag.objects.create(name='primary')
105+
102106
mock = MockModel()
103107
mock.tag = mock_tag
104108
tag_slug = NgramField(model_attr='tag__slug')
@@ -141,7 +145,8 @@ def test_prepare(self):
141145
self.assertEqual(author.prepare(mock), u'daniel')
142146

143147
# Do a lookup through the relation.
144-
mock_tag = MockTag(name='primary')
148+
mock_tag = MockTag.objects.create(name='primary')
149+
145150
mock = MockModel()
146151
mock.tag = mock_tag
147152
tag_name = EdgeNgramField(model_attr='tag__name')
@@ -155,7 +160,8 @@ def test_prepare(self):
155160
self.assertEqual(author.prepare(mock), u'')
156161

157162
# Simulate failed lookups.
158-
mock_tag = MockTag(name='primary')
163+
mock_tag = MockTag.objects.create(name='primary')
164+
159165
mock = MockModel()
160166
mock.tag = mock_tag
161167
tag_slug = EdgeNgramField(model_attr='tag__slug')
@@ -196,7 +202,8 @@ def test_prepare(self):
196202
self.assertEqual(pk.prepare(mock), 1)
197203

198204
# Simulate failed lookups.
199-
mock_tag = MockTag(name='primary')
205+
mock_tag = MockTag.objects.create(name='primary')
206+
200207
mock = MockModel()
201208
mock.tag = mock_tag
202209
tag_count = IntegerField(model_attr='tag__count')

0 commit comments

Comments
 (0)