蝗虫graphql客户端graphql。这是相当于httplocast的graphqlocast
locust-graphql-client的Python项目详细描述
蝗虫graphql客户端
蝗虫是一个python性能测试库。蝗虫支持现成的http客户端。 这个库为蝗虫提供了graphql客户端。
这个graphql客户端基于prisma的简单的python graphql客户端(https://github.com/prisma/python-graphql-client)
APIclassGraphQLClient:defexecute(self,label,query,variables=None,type='graphql'):
####参数
- type=蝗虫请求类型。默认值为“graphql”
- label=蝗虫名称
- query=graphql查询
- variables=graphql变量。默认值为无
用法
fromlocustimportHttpLocust,TaskSet,taskfromlocustgraphqlclientimportGraphQLLocustclassUserBehavior(TaskSet):defon_start(self):""" on_start is called when a Locust start before any task is scheduled """self.login()defon_stop(self):""" on_stop is called when the TaskSet is stopping """self.logout()deflogin(self):query=''' mutation login($username: String!, $password: String!) { login(username: $username, password: $password) { access_token } }'''variables={'username':'gm','password':'centric8'}result=self.client.execute("login",query,variables)# Inject the Access Token in the Client, so subsequent requests can be madeself.client.inject_token(result['data']['login']['access_token'])deflogout(self):# Reset the Access Token in the Client, so no subsequent requests can be madeself.client.inject_token('')@task(2)defindex(self):query=''' query products { products { id name image } }'''result=self.client.execute("products",query)@task(1)defprofile(self):query=''' query me { me { id username firstName lastName } }'''result=self.client.execute("me",query)classWebsiteUser(GraphQLLocust):task_set=UserBehaviormin_wait=5000max_wait=9000