Implement a TestClient class to test routes more efficiently
Description
This PR adds a new class TestClient that can be used to directly test methods.
To use, a robyn.testing.TestClient object must be created using a Robyn application as a parameter. HTTP method calls can be simulated using the functions get, post, delete, patch, options, head, trace and connect. Specifications of the input parameters and output object match those of the requests library.
Issue #507: https://github.com/sparckles/robyn/issues/507
Deploy request for robyn pending review.
Visit the deploys page to approve it
| Name | Link |
|---|---|
| Latest commit | ca96326ad6011debd98c667878b0c70207bfb3cf |
Hey @ElyasMag 👋
Thanks for the PR 😄 I have had an initial look. I will have a deeper look as you make more progress 😄
Do let me know if you have any questions from my end!
Hey @ElyasMag 👋
Thanks for the PR 😄 I have had an initial look. I will have a deeper look as you make more progress 😄
Do let me know if you have any questions from my end!
Hello! I'm new here. I'd appreciate any help I can get. I have one main question: If you look at my testing.py, you'll see that I'm passing None to the route handler. I tried to create a Request object to pass into it, but I get an error saying "class has no constructor." If you have any advice to offer, it would be much appreciated.
Hey @ElyasMag 👋 Thanks for the PR 😄 I have had an initial look. I will have a deeper look as you make more progress 😄 Do let me know if you have any questions from my end!
Hello! I'm new here. I'd appreciate any help I can get. I have one main question: If you look at my testing.py, you'll see that I'm passing None to the route handler. I tried to create a Request object to pass into it, but I get an error saying "class has no constructor." If you have any advice to offer, it would be much appreciated.
@sansyrox Mentioning in case you didn't get a notification.
Hey @ElyasMag 👋
I tried to create a Request object to pass into it, but I get an error saying "class has no constructor." If you have any advice to offer, it would be much appreciated.
There are two reasons for this
One is that you need to inspect the kind of params the handler is expecting And second, where are you importing the request class from?
@sansyrox Sorry, I can't seem to figure it out,
- As far as I can tell, the only parameter passed into the handler - that is, the function written by the developer of a server using Robyn - is the Request object.
- I'm importing the Request class from the robyn library, which I believe comes from src/types/request.rs & robyn/robyn.pyi
I thought I would have to create a class implementing the Request class, but Request is not an acceptable base type. Creating my own class with the same fields as the Request class would probably work, but doesn't sound like a reasonable solution. I can't figure out any other method of passing a Request object to the handler. Once again, advice would be greatly appreciated.
Update the description of the PR and also attach the issue,
Undraft the PR so you can get a round of review from the maintainers
Hey @ElyasMag 👋
@sansyrox Sorry, I can't seem to figure it out, As far as I can tell, the only parameter passed into the handler - that is, the function written by the developer of a server using Robyn - is the Request object. I'm importing the Request class from the robyn library, which I believe comes from src/types/request.rs & robyn/robyn.pyi I thought I would have to create a class implementing the Request class, but Request is not an acceptable base type. Creating my own class with the same fields as the Request class would probably work, but doesn't sound like a reasonable solution. I can't figure out any other method of passing a Request object to the handler. Once again, advice would be greatly appreciated.
Apologies, I missed this message :( .
Thanks @parth-gr for the help 💖
Do you still have any queries??
And for the future, if I don't reply to a query within 48 hours, feel free to reach out to me on Discord 😄
Hey @ElyasMag 👋
@sansyrox Sorry, I can't seem to figure it out, As far as I can tell, the only parameter passed into the handler - that is, the function written by the developer of a server using Robyn - is the Request object. I'm importing the Request class from the robyn library, which I believe comes from src/types/request.rs & robyn/robyn.pyi I thought I would have to create a class implementing the Request class, but Request is not an acceptable base type. Creating my own class with the same fields as the Request class would probably work, but doesn't sound like a reasonable solution. I can't figure out any other method of passing a Request object to the handler. Once again, advice would be greatly appreciated.
Apologies, I missed this message :( .
Thanks @parth-gr for the help 💖
Do you still have any queries??
And for the future, if I don't reply to a query within 48 hours, feel free to reach out to me on Discord 😄
Hello @sansyrox! I'll keep that in note for the future. The CodeDay Labs program is ending soon but I'd definitely like to continue working on this after. How is my approach looking? I noticed that in the description of the issue, the functions' arguments and return values matched those of the request library instead of those of the robyn library, so I tried to implement them similarly.
@sansyrox the PR looks good for the final review from your side and get it merged,
Also approve the CI test for now
@sansyrox Hey! I have a couple of questions to ask, if you don't mind answering them!
- What is the Identity field of the Request class?
- Do redirects need to be handled by the testing client? I'm looking at the Digest authentication and it involves some back-and-forth which the HttpDigestAuth class attaches hooks to the request for. This involves a lot of extra functions so if that's the case, then I might need to revisit my approach for the test requests entirely.
Hey @ElyasMag 👋
I see that there are quite a few formatting/linting issues - We have pre-commit set up in the repo with black and ruff to avoid these and fix them at the commit step.
If you follow the local development guide you can see how to set it up.
You can run pre-commit run --all-files after you set it up to run it on all files that you've previously committed.
Feel free to reach out if you're having issues!