-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tests for add_student view and moved tests in students app to tests folder #262
Conversation
Congratulations for making your first Pull Request at JagratiWebApp!! 🎉 Someone from our team will review it soon. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@harshakhmk I don't understand what you're actually testing here? You've created 2 users but you're running both tests for the same user (logged in one). You've written in the comment that the above test is for the unauthenticated user but that test is also running for the [email protected] (it is being redirected because this user also doesn't have an authenticated profile, which you need to create).
Here are a few more pointers:
- Use specific class name based on the view you are testing (like
AddStudentViewTest
for this particular class. - You need to create separate functions for each case you are testing, and not just test everything at a single place.
- You need to test the flow of the complete view in different scenarios, like without login, with login and no profile, with login and complete profile, test if the user is being redirected correctly in each case and if user is logged in with authenticated profile, test if correct template is being displayed, etc.
You can refer to this comment on the issue for more details on how the tests are to be written.
Also, you may refer to this tests file to get an idea of how tests are actually written: https://github.com/garg3133/fossee/blob/master/roomslotbooking/home/tests/test_views.py (Also notice the name of the class and different functions there).
At last, you should give this tutorial a read: https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django/Testing#views
Everything is mentioned in great details here on how tests are actually written in Django.
Feel free to reply back here if you're stuck somewhere or don't understand anything.
Ok, I will update my PR within 2 days |
No, you should replicate the real situation in the tests, how actual users might behave while using the application. |
I had a doubt, even though when I log in and try to make a request to add_student URL then the redirected URL becomes |
@harshakhmk You must have forgotten to set |
How do I handle authenticating the user by admin in testing, also
but response doesn't get changed, also there is no approved field in user for admin to approve an account |
@harshakhmk For successfully accessing the
|
Related Issue
Fixes: 79
Prosposed Changes
Additional Info
apps/students
folder, we need to delete existing tests.py to run the test scriptsScreenshots