1

this is my first question and I would like to know how to send the following test parameters to my FastAPI API:

to: (string)
name: (string)
files: (array)

what is the correct syntax? I am trying with the following:

self.client.post ("/ email", dict (to = "", name = "", files = "hi.pdf"))
Balaji Ambresh
  • 4,977
  • 2
  • 5
  • 17
ninjaking
  • 21
  • 2
  • As per https://docs.locust.io/en/v0.5.1/writing-a-locustfile.html, it looks correct(other than the space after the slash). You may want to modify it to from locust import ResponseError with self.client.post("/email", dict (to = "", name = "", files = "hi.pdf")}, catch_response=True) as response: if response.data == "fail": raise ResponseError("Failed to post") – Yuvika Aug 02 '20 at 16:43

1 Answers1

0

Here's the Locust doc on post requests. https://docs.locust.io/en/stable/api.html#locust.clients.HttpSession.post

Locust's http classes are based on requests. There are multiple ways to do it. One way is to read file directly and post it by itself:

with open("hi.pdf", "rb") as hi:
    self.client.post("/email", data=hi.read())

I'm not familiar with FastAPI so I don't know where your to and name need to go. If they're headers, you can do:

with open("hi.pdf", "rb") as hi:
    self.client.post("/email", data=hi.read(), headers={"to": "", "name": ""})
Solowalker
  • 2,431
  • 8
  • 13