JagratiWebApp icon indicating copy to clipboard operation
JagratiWebApp copied to clipboard

Unit tests for new_student view

Open garg3133 opened this issue 4 years ago • 27 comments

Write unit tests for new_student view in the students app. The tests need to be added in a file test_views in test directory of students app.

To learn about how to write unit tests in Django, you may follow this tutorial from MDN: https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django/Testing

For any further doubts and queries, feel free to join the community and ask there: https://discord.gg/Ek9q45ZjAv

garg3133 avatar Jan 25 '21 14:01 garg3133

@garg3133 Can I work on this issue. Please assign this issue to me.

Vrindagupta6828 avatar Jan 25 '21 14:01 Vrindagupta6828

Sure @Vrindagupta6828!

garg3133 avatar Jan 25 '21 14:01 garg3133

@garg3133 Can you please tell me how to run the test written as when i am executing the statement manage.py test students it is showing the following error: ModuleNotFoundError: No module named 'students'

Vrindagupta6828 avatar Feb 03 '21 16:02 Vrindagupta6828

Try to run python manage.py test apps/students

Also, add an empty __init__.py file in tests directory.

garg3133 avatar Feb 03 '21 16:02 garg3133

I did all that but when i am running this it is showing ran 0 test

Vrindagupta6828 avatar Feb 03 '21 17:02 Vrindagupta6828

It should show ran 1 test

Vrindagupta6828 avatar Feb 03 '21 17:02 Vrindagupta6828

Have you deleted the tests.py file? If not, you should delete it.

You may also add a __init__.py file in apps directory if you face any ModuleNotFoundError.

garg3133 avatar Feb 03 '21 17:02 garg3133

I have deleted the file and create a folder named tests and in that have made a file test_views.py

Vrindagupta6828 avatar Feb 04 '21 05:02 Vrindagupta6828

@garg3133 Can you please assist me how to advance further?

Vrindagupta6828 avatar Feb 04 '21 13:02 Vrindagupta6828

@Vrindagupta6828 Where are you stuck at?

You first need to create a class with name that matches function view name like NewStudentViewTest.

In that class, create a function setUpTestData in which you'll need to create some sample user (with auth & is_active as True), and then create that user's volunteer profile so that the user can access new_student view.

Then the first few functions will be same as in https://github.com/garg3133/fossee/blob/master/roomslotbooking/home/tests/test_views.py IndexViewTest which just tests if the user is being redirected properly if the user is not a volunteer, hasn't completed the profile or not authenticated. Then it should test if the correct template is being shown to the user. Then just the basic working of the new_student view to check if everything is working as expected.

Everything is explained in great details in this tutorial: https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django/Testing

Testing is a very major part of any software and hence should be done properly.

You can watch this video to get an essence of why we actually do testing: https://www.youtube.com/watch?v=1Lfv5tUGsn8

garg3133 avatar Feb 04 '21 14:02 garg3133

@garg3133 please assign this to me under GSSOC'21

anurag0singh avatar Mar 12 '21 14:03 anurag0singh

Sure @anurag0singh!

garg3133 avatar Mar 12 '21 14:03 garg3133

Hello @anurag0singh, you have been unassigned from this issue because you have not updated this issue or any referenced pull requests for over 14 days.

Thanks for your contributions, and hope to see you again soon!

Jagrati-Bot avatar Apr 14 '21 18:04 Jagrati-Bot

Is the issue still alive to add code, I am interested in adding the unit-tests

harshakhmk avatar May 02 '21 18:05 harshakhmk

Is the issue still alive to add code, I am interested in adding the unit-tests

Yes, you can work on it. @garg3133 I am sorry but I cannot do this work. Please assign @harshakhmk on this one.

anurag0singh avatar May 03 '21 02:05 anurag0singh

Is the issue still alive to add code, I am interested in adding the unit-tests

@harshakhmk I am assigning you this issue

AjaySharma132 avatar May 03 '21 19:05 AjaySharma132

Do I need to add test views in all apps

harshakhmk avatar May 04 '21 11:05 harshakhmk

Hello @harshakhmk, you claimed this issue to work on it, but this issue and any referenced pull requests haven't been updated for 10 days. Are you still working on this issue?

If so, please update this issue by leaving a comment on this issue to let me know that you're still working on it. Otherwise, I'll automatically remove you from this issue in 4 days.

If you've decided to work on something else, simply unassign yourself from this issue by going to the Assignees section and clicking on unassign me, so that someone else can claim it and continue from where you left off.

Thank you for your valuable contributions to JagratiWebApp!

Jagrati-Bot avatar May 14 '21 12:05 Jagrati-Bot

I am working on it @Jagrati-Bot

harshakhmk avatar May 14 '21 16:05 harshakhmk

Do I need to add test views in all apps

No, you just need to add the tests in the students app for this issue.

garg3133 avatar May 14 '21 16:05 garg3133

I have created the PR 262 please review it @garg3133

harshakhmk avatar May 14 '21 18:05 harshakhmk

@Jagrati-Bot review pending

harshakhmk avatar May 14 '21 18:05 harshakhmk

Hello @harshakhmk, you claimed this issue to work on it, but this issue and any referenced pull requests haven't been updated for 10 days. Are you still working on this issue?

If so, please update this issue by leaving a comment on this issue to let me know that you're still working on it. Otherwise, I'll automatically remove you from this issue in 4 days.

If you've decided to work on something else, simply unassign yourself from this issue by going to the Assignees section and clicking on unassign me, so that someone else can claim it and continue from where you left off.

Thank you for your valuable contributions to JagratiWebApp!

Jagrati-Bot avatar May 24 '21 18:05 Jagrati-Bot

I am sorry, I was not able to work @priyansh3133 you guided me well with the workflow, but it failed on my local system and I was not clear with flow of user signup process, unassign me this issue

harshakhmk avatar May 25 '21 16:05 harshakhmk

@garg3133 is this issue open? if so pls assign me, i have never worked with unit tests i want to give it a try

akshay399 avatar May 28 '21 14:05 akshay399

Hello @akshay399, you claimed this issue to work on it, but this issue and any referenced pull requests haven't been updated for 10 days. Are you still working on this issue?

If so, please update this issue by leaving a comment on this issue to let me know that you're still working on it. Otherwise, I'll automatically remove you from this issue in 4 days.

If you've decided to work on something else, simply unassign yourself from this issue by going to the Assignees section and clicking on unassign me, so that someone else can claim it and continue from where you left off.

Thank you for your valuable contributions to JagratiWebApp!

Jagrati-Bot avatar Jun 07 '21 19:06 Jagrati-Bot

Hello @akshay399, you have been unassigned from this issue because you have not updated this issue or any referenced pull requests for over 14 days.

Thanks for your contributions, and hope to see you again soon!

Jagrati-Bot avatar Jun 18 '21 00:06 Jagrati-Bot