Skip to content

Commit

Permalink
Fix content type cache issue in test
Browse files Browse the repository at this point in the history
  • Loading branch information
thenav56 committed May 2, 2024
1 parent b6a961c commit 0503c5f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 31 deletions.
1 change: 1 addition & 0 deletions apps/notification/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class Meta:
project = graphene.Field(AssignmentProjectDetailType)
content_data = graphene.Field(AssignmentContentDataType)

@staticmethod
def resolve_content_data(root, info):
return info.context.dl.notification.assignment.load(root.pk)

Expand Down
6 changes: 4 additions & 2 deletions apps/notification/tests/test_apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,13 +506,15 @@ def test_assignment_create_on_entry_comment_assignee_change(self):
assert data['count'] == 1 # assignment for user2

def test_assignment_is_done(self):
# XXX: To avoid using content type cache from pre-tests
ContentType.objects.clear_cache()

project = self.create(Project)
user1 = self.create(User)
user2 = self.create(User)
lead = self.create(Lead, project=project)
kwargs = {
'object_id': lead.id,
'content_type': ContentType.objects.get_for_model(Lead),
'content_object': lead,
'project': project,
'created_for': user1,
'created_by': user2,
Expand Down
58 changes: 29 additions & 29 deletions apps/notification/tests/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
import pytz

from django.contrib.contenttypes.models import ContentType

from utils.graphene.tests import GraphQLTestCase
from lead.models import Lead
from notification.models import Assignment, Notification
from quality_assurance.models import EntryReviewComment
from notification.models import Notification

from user.factories import UserFactory
from project.factories import ProjectFactory
from notification.factories import AssignmentFactory, NotificationFactory
from lead.factories import LeadFactory
from entry.factories import EntryCommentFactory, EntryFactory
from entry.factories import EntryFactory
from quality_assurance.factories import EntryReviewCommentFactory
from analysis_framework.factories import AnalysisFrameworkFactory


Expand Down Expand Up @@ -230,7 +230,11 @@ def test_assignments_query(self):
totalCount
}
}
'''
'''

# XXX: To avoid using content type cache from pre-tests
ContentType.objects.clear_cache()

project = ProjectFactory.create()
user = UserFactory.create()
another = UserFactory.create()
Expand All @@ -240,17 +244,16 @@ def test_assignments_query(self):
analysis_framework=af,
lead=lead
)
entry_comment = EntryCommentFactory.create(
entry_comment = EntryReviewCommentFactory.create(
entry=entry,
created_by=user
)
Assignment.objects.all().delete()

AssignmentFactory.create_batch(
3,
project=project,
object_id=lead.id,
content_type=ContentType.objects.get_for_model(Lead),
created_for=user
content_object=lead,
created_for=user,
)

def _query_check(**kwargs):
Expand All @@ -271,28 +274,27 @@ def _query_check(**kwargs):
AssignmentFactory.create_batch(
3,
project=project,
object_id=entry_comment.id,
content_type=ContentType.objects.get_for_model(EntryReviewComment),
content_object=entry_comment,
created_for=user
)
content = _query_check()
self.assertEqual(content['data']['assignments']['totalCount'], 6)

def test_assignments_with_filter_query(self):
query = '''
query MyQuery (
$isDone : Boolean,
){
assignments(
isDone: $isDone,
){
totalCount
results{
id
}
}
query MyQuery($isDone: Boolean) {
assignments(isDone: $isDone) {
totalCount
results {
id
}
}
}
'''

# XXX: To avoid using content type cache from pre-tests
ContentType.objects.clear_cache()

project = ProjectFactory.create()
user = UserFactory.create()
lead = LeadFactory.create()
Expand All @@ -301,24 +303,22 @@ def test_assignments_with_filter_query(self):
analysis_framework=af,
lead=lead
)
entry_comment = EntryCommentFactory.create(
entry_comment = EntryReviewCommentFactory.create(
entry=entry,
created_by=user
)
Assignment.objects.all().delete()

AssignmentFactory.create_batch(
3,
project=project,
object_id=lead.id,
content_type=ContentType.objects.get_for_model(Lead),
content_object=lead,
created_for=user,
is_done=False
)
AssignmentFactory.create_batch(
5,
project=project,
object_id=entry_comment.id,
content_type=ContentType.objects.get_for_model(EntryReviewComment),
content_object=entry_comment,
created_for=user,
is_done=True
)
Expand Down

0 comments on commit 0503c5f

Please sign in to comment.