代码之家  ›  专栏  ›  技术社区  ›  joe

Django GraphQL终结点测试无法使用“variables”字典

  •  0
  • joe  · 技术社区  · 6 年前

    variables 在里面 django-graphql-jwt ? 我可以用 mutation iGraphQL 具有 变量 正常情况下。那它应该在我的 TestCase

    from django.contrib.auth import get_user_model
    from graphql_jwt.testcases import JSONWebTokenTestCase
    from model_mommy import mommy
    
    from multy_herr.commons.tests import JCMixin
    from multy_herr.objections.models import Objection
    from multy_herr.tweets.models import Tweet
    
    User = get_user_model()
    
    
    class UsersTest(JCMixin, JSONWebTokenTestCase):
    
        def setUp(self) -> None:
            super().setUp()
            mommy.make(Objection, _quantity=3)
    
        def test_authorized_user_hide_success(self):
            """
            Hide success
            :return:
            """
            tweet = Tweet.objects.first()
    
            query: str = '''
                mutation{
                  objection(input: {
                    tweet: $tweetId
                    hidden: $hidden
                  }){
                    id
                    hidden
                    report
                    tweet
                    errors{
                      field
                      messages
                    }
                  }
                }
            '''
            variables = {
                'tweetId': str(tweet.id),
                'hidden': True,
            }
            self.client.authenticate(self.jc)
            res = self.client.execute(query, variables)
    

    res.error

    res.errors
    Out[3]: 
    [graphql.error.base.GraphQLError('Variable "$tweetId" is not defined.'),
     graphql.error.base.GraphQLError('Variable "$hidden" is not defined.')]
    

    解决方法:
    我用 .replace() Python 给变量赋值,但我不喜欢那种老套的方式


    是虫子吗?

    0 回复  |  直到 6 年前
    推荐文章