Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to unit test a resolver without creating a Query #1176

Unanswered
BossGrand asked this question in Q&A
Discussion options

I have this node

class ConversationNode(DjangoObjectType):
 unread_count = graphene.Int()
 def resolve_unread_count(self, info):
 comments = self.comments_set.all()
 unread_count = # logic for determing unread status
 return unread_count

and I want to run a test like this

def test_unread_count(create_mock_info, create_converstaion):
 mock_info = create_mock_info()
 conversation = create_converstaion()
 conversation_node = ConversationNode(conversation)
 
 assert conversation_node.resolve_unread_count(mock_info) == 3

but self is refering to the node and not the model,

so I get this error

E AttributeError: 'NoneType' object has no attribute 'all'

how do I run resolvers but have self refer to the model instead of the node?

Edit

Interestingly self.id refers to the model in the resolver

You must be logged in to vote

Replies: 3 comments

Comment options

Was there any success in this?

You must be logged in to vote
0 replies
Comment options

BossGrand
Mar 3, 2019
Maintainer Author

no, no updates

You must be logged in to vote
0 replies
Comment options

Does conversation_node.comment_set return a mocked queryset or is comment_set None?

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
Converted from issue

This discussion was converted from issue #531 on April 14, 2021 20:13.

AltStyle によって変換されたページ (->オリジナル) /