fAIr icon indicating copy to clipboard operation
fAIr copied to clipboard

Implement Backend Test Cases for fAIr

Open kshitijrajsharma opened this issue 1 year ago • 67 comments

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.

kshitijrajsharma avatar Mar 03 '24 02:03 kshitijrajsharma

Kindly assign this issue to me

ohthebrave avatar Mar 04 '24 16:03 ohthebrave

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.

kshitijrajsharma avatar Mar 05 '24 02:03 kshitijrajsharma

I will also be working on this.

shekinahmanyi avatar Mar 05 '24 07:03 shekinahmanyi

i would like to work on this issue as well. Would like to know if the project can be run on windows.

hamzambo avatar Mar 05 '24 08:03 hamzambo

Hello! I will also be working on this.

owolabioromidayo avatar Mar 05 '24 08:03 owolabioromidayo

please @kshitijrajsharma can you assign it to me too ?

angeangoh avatar Mar 05 '24 09:03 angeangoh

Yes project can run on windows ! There is a windows installation doc in repo

kshitijrajsharma avatar Mar 05 '24 09:03 kshitijrajsharma

I will be working on this too

Payne680 avatar Mar 05 '24 13:03 Payne680

Hello, I would also be working on this issue

Munaelekwa avatar Mar 05 '24 16:03 Munaelekwa

@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?

Munaelekwa avatar Mar 05 '24 17:03 Munaelekwa

I will also be working on this.

isiagi avatar Mar 05 '24 18:03 isiagi

I'd also like to work on this. Thank you.

Jojowangfy avatar Mar 05 '24 20:03 Jojowangfy

@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 ?

kshitijrajsharma avatar Mar 06 '24 02:03 kshitijrajsharma

Working on this, thank you.

Erickkaranja avatar Mar 06 '24 03:03 Erickkaranja

@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

Munaelekwa avatar Mar 06 '24 03:03 Munaelekwa

I would like to working on this issue

siva224513 avatar Mar 06 '24 07:03 siva224513

Hello World!

I would love to work on this project!

Happy contributing :)

Talikamuhib avatar Mar 07 '24 07:03 Talikamuhib

@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 avatar Mar 07 '24 08:03 owolabioromidayo

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

kshitijrajsharma avatar Mar 07 '24 09:03 kshitijrajsharma

Thank you! On it.

owolabioromidayo avatar Mar 07 '24 09:03 owolabioromidayo

@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

ademolaomosanya avatar Mar 07 '24 12:03 ademolaomosanya

@kshitijrajsharma Is the test_create_dataset testcase currently passing?

image

This is where mine fails: image

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?

owolabioromidayo avatar Mar 07 '24 17:03 owolabioromidayo

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

marameref avatar Mar 07 '24 19:03 marameref

@kshitijrajsharma You should mention the need to set up a virtual environment when writing tests.

ohthebrave avatar Mar 08 '24 09:03 ohthebrave

Hello can I contribute here too.

maryagiamah avatar Mar 08 '24 12:03 maryagiamah

@kshitijrajsharma Is the test_create_dataset testcase currently passing?

image

This is where mine fails:

image

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?

You are missing authentication in header , You can get your authentication from /auth endpoints . In your logs it says forbidden 🚫

kshitijrajsharma avatar Mar 09 '24 02:03 kshitijrajsharma

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 avatar Mar 09 '24 02:03 kshitijrajsharma

@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.

image

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.

owolabioromidayo avatar Mar 09 '24 10:03 owolabioromidayo

@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.

image

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

kshitijrajsharma avatar Mar 09 '24 10:03 kshitijrajsharma