Skip to content
This repository was archived by the owner on Jun 1, 2022. It is now read-only.

Commit 7e4afcc

Browse files
committed
Fix bug for working with ContentTypes in tests
1 parent bf642ec commit 7e4afcc

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

editorsnotes/api/tests.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
from lxml import etree
66

7+
from django.contrib.contenttypes.models import ContentType
78
from django.core.urlresolvers import reverse
89
from django.test import TransactionTestCase
910

1011
from editorsnotes.main import models as main_models
11-
from editorsnotes.main.management import update_project_permissions
1212
from editorsnotes.search import en_index, activity_index
1313

1414
def flush_es_indexes():
@@ -58,13 +58,21 @@ def delete_es_indexes():
5858
BAD_PERMISSION_MESSAGE = u'You do not have permission to perform this action.'
5959
NO_AUTHENTICATION_MESSAGE = u'Authentication credentials were not provided.'
6060

61-
class TopicAPITestCase(TransactionTestCase):
61+
class ClearContentTypesTransactionTestCase(TransactionTestCase):
62+
"""
63+
See https://code.djangoproject.com/ticket/10827
64+
"""
65+
def _pre_setup(self, *args, **kwargs):
66+
ContentType.objects.clear_cache()
67+
super(ClearContentTypesTransactionTestCase, self)._pre_setup(*args, **kwargs)
68+
69+
70+
class TopicAPITestCase(ClearContentTypesTransactionTestCase):
6271
fixtures = ['projects.json']
6372
def setUp(self):
6473
self.user = main_models.User.objects.get(username='barry')
6574
self.project = main_models.Project.objects.get(slug='emma')
6675
self.client.login(username='barry', password='barry')
67-
update_project_permissions()
6876

6977
def create_test_topic(self):
7078
data = TEST_TOPIC
@@ -247,13 +255,12 @@ def test_topic_api_delete_logged_out(self):
247255
self.assertEqual(response.data['detail'], NO_AUTHENTICATION_MESSAGE)
248256

249257

250-
class DocumentAPITestCase(TransactionTestCase):
258+
class DocumentAPITestCase(ClearContentTypesTransactionTestCase):
251259
fixtures = ['projects.json']
252260
def setUp(self):
253261
self.user = main_models.User.objects.get(username='barry')
254262
self.project = main_models.Project.objects.get(slug='emma')
255263
self.client.login(username='barry', password='barry')
256-
update_project_permissions()
257264

258265
def create_test_document(self):
259266
data = TEST_DOCUMENT
@@ -425,13 +432,12 @@ def test_document_api_delete_logged_out(self):
425432
self.assertEqual(response.data['detail'], NO_AUTHENTICATION_MESSAGE)
426433

427434

428-
class NoteAPITestCase(TransactionTestCase):
435+
class NoteAPITestCase(ClearContentTypesTransactionTestCase):
429436
fixtures = ['projects.json']
430437
def setUp(self):
431438
self.user = main_models.User.objects.get(username='barry')
432439
self.project = main_models.Project.objects.get(slug='emma')
433440
self.client.login(username='barry', password='barry')
434-
update_project_permissions()
435441

436442
def create_test_note(self):
437443
data = TEST_NOTE

0 commit comments

Comments
 (0)