Skip to content

Add comprehensive test coverage for settings view#14

Open
jpartovi wants to merge 1 commit intomainfrom
devin/1762271616-add-settings-view-tests
Open

Add comprehensive test coverage for settings view#14
jpartovi wants to merge 1 commit intomainfrom
devin/1762271616-add-settings-view-tests

Conversation

@jpartovi
Copy link

@jpartovi jpartovi commented Nov 4, 2025

Add comprehensive test coverage for settings view

Summary

This PR adds comprehensive test coverage for the settings view function in realworld/accounts/views.py (lines 46-61). The view previously had no test coverage. The new TestSettingsView test class includes 5 test methods that cover:

  • Unauthenticated access: Verifies redirect to login page for unauthenticated users
  • Authenticated GET request: Verifies form is displayed with current user data
  • Valid POST request: Verifies user settings are successfully updated and user is redirected to profile
  • Invalid POST request: Verifies form errors are returned for invalid data
  • Password update: Verifies password can be optionally updated through the settings form

The tests follow existing patterns from TestRegisterView and TestFollowView in the same file, using setUpTestData, force_login, and checking both HTTP status codes and database state.

Test Results: All 18 tests in realworld.accounts pass successfully (13 existing + 5 new).

Review & Testing Checklist for Human

  • Run python manage.py test realworld.accounts.tests.TestSettingsView to verify all 5 tests pass in your environment
  • Manually test the settings page to confirm the test scenarios match actual behavior (especially the login redirect path and HTMX redirect header)
  • Review the password update test to ensure it correctly validates the optional password field behavior in SettingsForm

Notes

  • This is a test-only PR - no production code was modified
  • Tests were verified locally with all 18 accounts tests passing
  • Follows Django TestCase patterns consistent with existing test classes

Link to Devin run: https://app.devin.ai/sessions/1a8d2469f5174b2ca7b0eaf5c3b52765
Requested by: Jude Partovi (@jpartovi)

- Test unauthenticated access (redirects to login)
- Test authenticated GET request (displays form with user data)
- Test POST with valid data (updates settings and redirects)
- Test POST with invalid data (returns form with errors)
- Test POST with password update (changes password)

Follows existing test patterns from TestRegisterView and TestFollowView.
All tests pass successfully.

Co-Authored-By: Jude Partovi <jude@partovi.org>
@devin-ai-integration
Copy link

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant