Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Ensured that about half of the files opened in the formtools tests we…

…re explicitly closed.
  • Loading branch information...
commit 64a3c7f9aeda347a72e3f1e8e88381b5b3d479d8 1 parent 187ec5a
Alex Gaynor alex authored Alex Gaynor committed
17 django/contrib/formtools/tests/wizard/namedwizardtests/tests.py
View
@@ -122,6 +122,7 @@ def test_form_finish(self):
self.assertEqual(response.context['wizard']['steps'].current, 'form2')
post_data = self.wizard_step_data[1]
+ post_data['form2-file1'].close()
post_data['form2-file1'] = open(__file__, 'rb')
response = self.client.post(
reverse(self.wizard_urlname,
@@ -149,7 +150,9 @@ def test_form_finish(self):
self.assertEqual(response.status_code, 200)
all_data = response.context['form_list']
- self.assertEqual(all_data[1]['file1'].read(), open(__file__, 'rb').read())
+ with open(__file__, 'rb') as f:
+ self.assertEqual(all_data[1]['file1'].read(), f.read())
+ all_data[1]['file1'].close()
del all_data[1]['file1']
self.assertEqual(all_data, [
{'name': 'Pony', 'thirsty': True, 'user': self.testuser},
@@ -182,9 +185,10 @@ def test_cleaned_data(self):
response = self.client.get(step2_url)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.context['wizard']['steps'].current, 'form2')
- self.assertEqual(
- response.context['wizard']['form'].files['form2-file1'].read(),
- open(__file__, 'rb').read())
+ with open(__file__, 'rb') as f:
+ self.assertEqual(
+ response.context['wizard']['form'].files['form2-file1'].read(),
+ f.read())
response = self.client.post(
reverse(self.wizard_urlname,
@@ -201,7 +205,9 @@ def test_cleaned_data(self):
self.assertEqual(response.status_code, 200)
all_data = response.context['all_cleaned_data']
- self.assertEqual(all_data['file1'].read(), open(__file__, 'rb').read())
+ with open(__file__, 'rb') as f:
+ self.assertEqual(all_data['file1'].read(), f.read())
+ all_data['file1'].close()
del all_data['file1']
self.assertEqual(
all_data,
@@ -225,6 +231,7 @@ def test_manipulated_data(self):
self.assertEqual(response.status_code, 200)
post_data = self.wizard_step_data[1]
+ post_data['form2-file1'].close()
post_data['form2-file1'] = open(__file__, 'rb')
response = self.client.post(
reverse(self.wizard_urlname,
15 django/contrib/formtools/tests/wizard/wizardtests/tests.py
View
@@ -95,7 +95,9 @@ def test_form_finish(self):
self.assertEqual(response.status_code, 200)
all_data = response.context['form_list']
- self.assertEqual(all_data[1]['file1'].read(), open(__file__, 'rb').read())
+ with open(__file__, 'rb') as f:
+ self.assertEqual(all_data[1]['file1'].read(), f.read())
+ all_data[1]['file1'].close()
del all_data[1]['file1']
self.assertEqual(all_data, [
{'name': 'Pony', 'thirsty': True, 'user': self.testuser},
@@ -112,8 +114,9 @@ def test_cleaned_data(self):
self.assertEqual(response.status_code, 200)
post_data = self.wizard_step_data[1]
- post_data['form2-file1'] = open(__file__, 'rb')
- response = self.client.post(self.wizard_url, post_data)
+ with open(__file__, 'rb') as post_file:
+ post_data['form2-file1'] = post_file
+ response = self.client.post(self.wizard_url, post_data)
self.assertEqual(response.status_code, 200)
response = self.client.post(self.wizard_url, self.wizard_step_data[2])
@@ -123,7 +126,9 @@ def test_cleaned_data(self):
self.assertEqual(response.status_code, 200)
all_data = response.context['all_cleaned_data']
- self.assertEqual(all_data['file1'].read(), open(__file__, 'rb').read())
+ with open(__file__, 'rb') as f:
+ self.assertEqual(all_data['file1'].read(), f.read())
+ all_data['file1'].close()
del all_data['file1']
self.assertEqual(all_data, {
'name': 'Pony', 'thirsty': True, 'user': self.testuser,
@@ -140,6 +145,7 @@ def test_manipulated_data(self):
self.assertEqual(response.status_code, 200)
post_data = self.wizard_step_data[1]
+ post_data['form2-file1'].close()
post_data['form2-file1'] = open(__file__, 'rb')
response = self.client.post(self.wizard_url, post_data)
self.assertEqual(response.status_code, 200)
@@ -167,6 +173,7 @@ def test_form_refresh(self):
self.assertEqual(response.context['wizard']['steps'].current, 'form2')
post_data = self.wizard_step_data[1]
+ post_data['form2-file1'].close()
post_data['form2-file1'] = open(__file__, 'rb')
response = self.client.post(self.wizard_url, post_data)
self.assertEqual(response.status_code, 200)
Please sign in to comment.
Something went wrong with that request. Please try again.