Implement Backend Test Cases for fAIr
Issue Description:
Objective:
We are seeking an enthusiastic intern to collaborate on enhancing our Django backend project by integrating backend test cases. This issue aims to ensure the robustness and reliability of our application through systematic testing practices. Your contribution will involve writing test cases, determining code coverage, and ensuring all functionalities are tested following industry best practices.
Responsibilities:
-
Understand the current project structure and functionality by reviewing the existing models, views, and URLs. Backend is available here. If you have trouble installing the application to do raise issue or ask for help
-
Collaborate with the development team to identify critical areas lacking test coverage.
-
Write comprehensive test cases for the Django backend, focusing on models, APIs, and integration points.
-
Utilize Django's testing framework effectively to automate tests.
-
Ensure test cases are well-documented and maintainable.
-
Measure and report code coverage to identify untested code segments.
-
Propose improvements or bug fixes identified during testing.
-
Participate in code reviews to receive feedback and iterate on your work.
Expected Outcomes:
- A suite of automated tests covering critical functionalities of the Django backend.
- Documentation accompanying each test case, explaining its purpose and methodology.
- A code coverage report highlighting tested vs. untested code segments.
- Recommendations for improving code quality and application performance based on test findings.
Resources
Test Folder Structure :
└── backend
└── tests
├── __init__.py
├── test_worker_example.py
├── test_models_example.py
└── test_views_example.py
Tests should cover Any of the following :
- models
- views
- & the API. Find API swagger here
Videos and docs :
- Find begineer guide to contribute to HOTOSM Tools here
- Know about fAIr as a project and what does is do here
- Django test coverage tool : https://coverage.readthedocs.io/en/latest/
- Find HOTOSM Developer guidelines here
- factory_boy, model_backery, and mock: all are used in place of fixtures or the ORM for populating needed data for testing. Both fixtures and the ORM can be slow and need to be updated whenever your model changes.
- Documentation on getting started with django projects testing by realpython
What should be included in PR:
- Black formatter should be used
- At least mention following section
--- What does this PR do ?
- Detail summary about the changes you have done, Which backend functionality you have worked on , Mention link of issue you have worked on
--- Consideration:
- What are the steps/alternatives you have considered while developing
--- How to test ?
- Steps to tests
Support:
Feel free to ask questions or seek clarifications by commenting on this issue. We're excited to see your contributions.
How to Proceed:
- Fork the repository and set up the project locally.
- Comment on this issue mentioning you will be contributing
- Familiarize yourself with the codebase and Django's testing framework.
- Start by creating new branch in your fork with functional branch name like
tests/aoi-models - Write a few test cases and submit them as a pull request in your own fork
- Come back to this issue thread and drop your pull request URL for initial feedback.
- Gradually work on covering more components and functionalities. Once approved, you can raise PR to this main repo
Issue will be completed when :
- All critical backend functionalities are covered by test cases.
- Code coverage is significantly improved, aiming at least 80%.
- Tests are well-documented and follow coding standards.
Kindly assign this issue to me
Sure go ahead , This issue can be worked by multiple people hence no need for assignee , You can fork the repo and start working on it ! Feel free to drop questions.
I will also be working on this.
i would like to work on this issue as well. Would like to know if the project can be run on windows.
Hello! I will also be working on this.
please @kshitijrajsharma can you assign it to me too ?
Yes project can run on windows ! There is a windows installation doc in repo
I will be working on this too
Hello, I would also be working on this issue
@kshitijrajsharma please i'm trying to install the requirements.txt file and it throws an error concerning the tensorflow version, ERROR: Could not find a version that satisfies the requirement tflite-runtime==2.14.0 (from versions: none) ERROR: No matching distribution found for tflite-runtime==2.14.0 any suggestions?
I will also be working on this.
I'd also like to work on this. Thank you.
@kshitijrajsharma please i'm trying to install the requirements.txt file and it throws an error concerning the tensorflow version,
ERROR: Could not find a version that satisfies the requirement tflite-runtime==2.14.0 (from versions: none)
ERROR: No matching distribution found for tflite-runtime==2.14.0
any suggestions?
Are you using docker ?
Working on this, thank you.
@kshitijrajsharma please i'm trying to install the requirements.txt file and it throws an error concerning the tensorflow version, ERROR: Could not find a version that satisfies the requirement tflite-runtime==2.14.0 (from versions: none) ERROR: No matching distribution found for tflite-runtime==2.14.0 any suggestions?
Are you using docker ?
i have docker installed, but I'm not using it
I would like to working on this issue
Hello World!
I would love to work on this project!
Happy contributing :)
@kshitijrajsharma I have the project running now.
There is a slight issue I ran into that might be helpful for others to note.
I was initially not able to login to OSM from the fair frontend server, as its requests to the backend kept getting bounced due to CORS errors.
Looking at the .env file for the backend, and the settings.py file, everything was already configured. I thought it was due to some errors from the backend and database container logs but that turned out to not be the case.
All I had to do was open the frontend using "127.0.0.1:3000" instead of "localhost:3000" and that fixed everything.
I would also recommend for others to use docker and follow the instructions from https://github.com/hotosm/fAIr/blob/master/docs/Docker-installation.md.
Lovely @owolabioromidayo !
All I had to do was open the frontend using "127.0.0.1:3000" instead of "localhost:3000" and that fixed everything.
That is fully correct ! We should mention this in .md
Thank you! On it.
@kshitijrajsharma https://github.com/owolabioromidayo/fAIr/pull/1
@kshitijrajsharma I have the project running now.
There is a slight issue I ran into that might be helpful for others to note.
I was initially not able to login to OSM from the fair frontend server, as its requests to the backend kept getting bounced due to CORS errors.
Looking at the .env file for the backend, and the settings.py file, everything was already configured. I thought it was due to some errors from the backend and database container logs but that turned out to not be the case.
All I had to do was open the frontend using "127.0.0.1:3000" instead of "localhost:3000" and that fixed everything.
I would also recommend for others to use docker and follow the instructions from https://github.com/hotosm/fAIr/blob/master/docs/Docker-installation.md.
@owolabioromidayo thank you for this suggestion Have been facing issues while setting up and the link you also shared would be helpful
@kshitijrajsharma Is the test_create_dataset testcase currently passing?
This is where mine fails:
I have tried changing the input data and headers to match different branches of the LabelViewSet create method but the error remains the same.
I have also tried debugging by printing, printing to stderr, and logging output to a file from the create method but none of those approaches yields anything. It could be that the request fails before it even reaches this method.
Is there something I might have misconfigured?
Hello @kshitijrajsharma my Outreachy initial application was approved and I would like to work on this issue. Is it still open, can I proceed to work on this issue? Pls respond
@kshitijrajsharma You should mention the need to set up a virtual environment when writing tests.
Hello can I contribute here too.
@kshitijrajsharma Is the test_create_dataset testcase currently passing?
This is where mine fails:
I have tried changing the input data and headers to match different branches of the LabelViewSet create method but the error remains the same.
I have also tried debugging by printing, printing to stderr, and logging output to a file from the
createmethod but none of those approaches yields anything. It could be that the request fails before it even reaches this method.Is there something I might have misconfigured?
You are missing authentication in header , You can get your authentication from /auth endpoints . In your logs it says forbidden 🚫
Hello @kshitijrajsharma my Outreachy initial application was approved and I would like to work on this issue. Is it still open, can I proceed to work on this issue? Pls respond
Go ahead
@kshitijrajsharma
I have my TESTING_TOKEN set using the token value in the localStorage of the frontend website. It seems to work fine for the auth endpoint tests.
The 403 comes from the first dataset test without the header. The 500 however, is due an internal server error from the request with the correct header set.
@kshitijrajsharma
I have my TESTING_TOKEN set using the token value in the localStorage of the frontend website.
It seems to work fine for the auth endpoint tests.
The 403 comes from the first dataset test without the header.
The 500 however, is due an internal server error from the request with the correct header set.
Right , Do you have export tool api env variable set ? If yes , remove it and let it use default one ! It should work