Skip to content

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

Closed

Description

@BossGrand

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

Activity

  1. changed the title [-]How to unit test a resolver with creating a Query[/-] [+]How to unit test a resolver without creating a Query[/+] on Oct 9, 2018
  2. evansmwendwa commented on Mar 2, 2019

    @evansmwendwa

    Was there any success in this?

  3. BossGrand commented on Mar 3, 2019

    @BossGrand
    MemberAuthor

    no, no updates

  4. stale commented on Jun 11, 2019

    @stale

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

  5. zbyte64 commented on Apr 14, 2021

    @zbyte64
    Collaborator

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

  6. locked and limited conversation to collaborators on Apr 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions