-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correcting FormView.get_initial usage
Direct reference to self.initial is not threadsafe. initial should be copied first via a call to super.get_initial then modified.
- Loading branch information
Showing
2 changed files
with
25 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -435,12 +435,12 @@ def test_get_initial_anonymous(self): | |
view.request = RequestFactory().get('/contact/') | ||
view.request.session = {} | ||
view.request.user = AnonymousUser() | ||
view.get_initial() | ||
initial = view.get_initial() | ||
|
||
self.assertIsNotNone(view.initial['issue_date']) | ||
self.assertFalse('name' in view.initial) | ||
self.assertFalse('email' in view.initial) | ||
self.assertFalse('username' in view.initial) | ||
self.assertIsNotNone(initial['issue_date']) | ||
self.assertFalse('name' in initial) | ||
self.assertFalse('email' in initial) | ||
self.assertFalse('username' in initial) | ||
|
||
def test_get_initial_not_anonymous(self): | ||
view = ContactUsView() | ||
|
@@ -450,12 +450,20 @@ def test_get_initial_not_anonymous(self): | |
last_name='Bar', | ||
email='[email protected]') | ||
|
||
view.get_initial() | ||
initial = view.get_initial() | ||
self.assertIsNotNone(initial['issue_date']) | ||
self.assertEquals(initial['name'], 'Foo Bar') | ||
self.assertEquals(initial['email'], '[email protected]') | ||
self.assertEquals(initial['username'], view.request.user.username) | ||
|
||
self.assertIsNotNone(view.initial['issue_date']) | ||
self.assertEquals(view.initial['name'], 'Foo Bar') | ||
self.assertEquals(view.initial['email'], '[email protected]') | ||
self.assertEquals(view.initial['username'], view.request.user.username) | ||
# a subsequent call using an anonymous session returns a clean initial | ||
view.request.session = {} | ||
view.request.user = AnonymousUser() | ||
initial = view.get_initial() | ||
self.assertIsNotNone(initial['issue_date']) | ||
self.assertFalse('name' in initial) | ||
self.assertFalse('email' in initial) | ||
self.assertFalse('username' in initial) | ||
|
||
def test_form_valid(self): | ||
view = ContactUsView() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters