Robyn
Robyn copied to clipboard
Add a testing client
Right now in Robyn, you need to make a network request(using the requests library). Adding a test client will essentially avoid the need to that, making the responses much faster!
Sample usage
from robyn.testing import TestClient
from myapp import app
client = TestClient(app)
def test_index():
response = client.get("/")
assert response.status_code == 200
assert response.text == "Hello, Robyn!"
def test_upload():
file_data = b"This is a test file"
response = client.post("/upload", files={"file": ("test_file.txt", file_data)})
assert response.status_code == 200
assert response.json() == {"message": "File uploaded successfully"}
Hello, I understand that we are trying to run the methods using the TestClient instead of using the http requests. However, we don't know where the functions are so that we can run them directly so that we can understand how it works. Would you be able to give some guidance on this ?
@sansyrox ^^
@sansyrox how we should contribute to this, Should it be a single PR with multiple commits, or we can have multiple PRs
Hey @tushart29 @parth-gr 👋
Apologies for the late revert.
Hello, I understand that we are trying to run the methods using the TestClient instead of using the http requests. However, we don't know where the functions are so that we can run them directly so that we can understand how it works.
There could be two ways how we can proceed with this.
Firstly, we know where the functions are. They are present in a router, which is present in src/router
module. Also, this module is being populated under the robyn/__init__.py
file.
Now, the steps to approach could be to have a test client in the rust side, which will be populated along the main router. Or have a Python Router, which will be populated from __init__.py
.
Then these routers will be exported from the __init__.py
file. Finally, when a HTTP request will be made to these routes, they should execute the function being fetched and execute it.
I hope this helps 😄
@parth-gr ,
@sansyrox how we should contribute to this, Should it be a single PR with multiple commits, or we can have multiple PRs
I would prefer a single PR with multiple commits. However, you folks can open a draft PR as soon as you folks start working on it. This would allow us to easily collaborate 😄
@parth-gr @tushart29 I've been trying to work on it too...i don't mind collaborating
@Oluwaseun241 yes you can but,
We are working here as a part of Code Day challenge, not sure if we can include you are you also part of codeday challenge
@parth-gr no I'm not part of code day challenge But I would still love to join
@sansyrox please give the intial round of review as per the project standards. https://github.com/sparckles/robyn/pull/567
And can you also tell can we take @Oluwaseun241 in?
Hey @parth-gr 👋
I have given the initial review of the PR 😄 Let me know if you have any questions.
And also, yes I love seeing collaboration! You may include @Oluwaseun241 😄
@Oluwaseun241 whats your email I can add it to the meetings
@parth-gr Are you on the discord channel so we can talk better I was kinda late to the meeting