测试石墨烯返回错误JSONDecodeError:期望值:第2行第1列(字符1)

2024-04-26 23:25:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我对石墨烯和DJango的单元测试还不熟悉。我正试图用graphenehttps://docs.graphene-python.org/projects/django/en/latest/testing/测试我的graphql查询 但是我不知道为什么我会犯这个错误。请帮帮我

导入json 从graphene_django.utils.testing导入GraphQLTestCase

# Create your tests here.
class CryptoBankQueryTestCase(GraphQLTestCase):
    def test_cryptobank_query(self):
        response = self.query(
            '''
            query cryptoBank($id: Int!){
                cryptoBank(cryptoBankId: $id) {
                    id,
                    name,
                    phoneNumber,
                    address
                }
            }
            ''',
            op_name="cryptoBank",
            variables={"cryptoBankId": 1}
        )

        content = json.loads(response.content)
        
        # This validates the status code and if you get errors
        self.assertResponseNoErrors(response)

        # Add some more asserts if you like

错误:

ERROR: test_cryptobank_query (cryptobank.tests.test_cryptobank_query.CryptoBankQueryTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/cafafanscoders/Desktop/python/CryptoBankGraphQL/src/cryptobank/tests/test_cryptobank_query.py", line 22, in test_cryptobank_query
    content = json.loads(response.content)
  File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 2 column 1 (char 1)

Tags: inpytestselfjsonresponselinetests