Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在django中编写石墨烯graphql测试_Python_Django_Graphql - Fatal编程技术网

Python 如何在django中编写石墨烯graphql测试

Python 如何在django中编写石墨烯graphql测试,python,django,graphql,Python,Django,Graphql,请任何人帮助django测试石墨烯和graphql 我尝试使用内置的django测试,但它没有看到我的文件 我使用了pytest,但它在导入模式时抱怨ModuleNotFoundError 我希望有人给我看一门关于高级python的课程 class Query(ObjectType): calculate_price = Float(margin=Float(), exchangeRate=String( ), saleType=Argument(SaleType, requir

请任何人帮助django测试石墨烯和graphql

我尝试使用内置的django测试,但它没有看到我的文件 我使用了pytest,但它在导入模式时抱怨ModuleNotFoundError 我希望有人给我看一门关于高级python的课程

class Query(ObjectType):
    calculate_price = Float(margin=Float(), exchangeRate=String(
    ), saleType=Argument(SaleType, required=True))

    def resolve_calculate_price(self, info, **kwargs):
        margin = kwargs.get('margin')
        exchangeRate = kwargs.get('exchangeRate')
        saleType = kwargs.get('saleType')

        request_from_coindesk = requests.get(
            url='https://api.coindesk.com/v1/bpi/currentprice.json')
        json_result_from_coindesk = json.dumps(request_from_coindesk.text)
        coindesk_result = json.loads(json_result_from_coindesk)
        result = json.loads(coindesk_result)

        rate_to_calculate = result["bpi"]["USD"]["rate_float"]

        if saleType == SaleType.sell:
            calculated_value = (margin/100) * rate_to_calculate
            new_rate = (rate_to_calculate - calculated_value) * 360
            print(18, new_rate)
            return new_rate
        elif saleType == SaleType.buy:
            calculated_value = (margin/100) * rate_to_calculate
            new_rate = (rate_to_calculate - calculated_value) * 360
            print(19, new_rate)
            return new_rate
        else:
            raise GraphQLError('please saleType can either be buy or sell')
我希望能够测试所有可能的案例。 我想了解模块导入问题
我希望有人能参考一门高级python课程

下面是一个关于如何使用django和graphene测试graphql的示例,graphene django:

这是基于:


下面是一个关于如何使用django和graphene测试graphql的示例,graphene django:

这是基于:

#my test file
from graphene.test import Client
from buy_coins.schema import schema



def test_hey():
    client = Client(schema)
    executed = client.execute('''calculatePrice(margin, exchangeRate, saleType)''', context={
                              'margin': '1.2', 'exchangeRate': 'USD', 'saleType': 'sell'})
    assert executed == {
        "data": {
            "calculatePrice": 3624484.7302560005
        }
    }

from buy_coins.schema import Query
from django.test.testcases import TestCase
import graphene

class AnExampleTest(TestCase):

    def setUp(self):
        super().setUp()
        self.query = """
            query {
              reporter {
                id
              }
            }
        """

    def test_an_example(self):
        schema = graphene.Schema(query=Query)
        result = schema.execute(query)
        self.assertIsNone(result.errors)
        self.assertDictEqual({"reporter": {"id": "1"}}, result.data)