summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2014-06-09 10:28:39 +0200
committerClaude Paroz <claude@2xlibre.net>2014-06-09 10:28:39 +0200
commit1aaf4053f5bda3e064448ca5abfa20eb3d029565 (patch)
treeb787023d3d25da9a68bd2e81d30beda8dc79d449
parent96e4b52ab2c6fae3e46a197d44c42cb6ebde7d9c (diff)
Fixed formtools tests with Python 2
Fixes #19905 again.
-rw-r--r--django/contrib/formtools/tests/wizard/namedwizardtests/tests.py13
-rw-r--r--django/contrib/formtools/tests/wizard/wizardtests/tests.py14
2 files changed, 16 insertions, 11 deletions
diff --git a/django/contrib/formtools/tests/wizard/namedwizardtests/tests.py b/django/contrib/formtools/tests/wizard/namedwizardtests/tests.py
index 92280165c7..6a033612ce 100644
--- a/django/contrib/formtools/tests/wizard/namedwizardtests/tests.py
+++ b/django/contrib/formtools/tests/wizard/namedwizardtests/tests.py
@@ -5,6 +5,7 @@ import copy
from django.core.urlresolvers import reverse
from django.http import QueryDict
from django.test import TestCase, override_settings
+from django.utils._os import upath
from django.contrib.auth.models import User
from django.contrib.auth.tests.utils import skipIfCustomUser
@@ -16,6 +17,8 @@ from django.contrib.formtools.tests.wizard.test_forms import get_request, Step1,
from .forms import temp_storage
+# On Python 2, __file__ may end with .pyc
+THIS_FILE = upath(__file__).rstrip("c")
UPLOADED_FILE_NAME = 'tests.py'
@@ -141,7 +144,7 @@ class NamedWizardTests(object):
self.assertEqual(response.context['wizard']['steps'].current, 'form2')
post_data = self.wizard_step_data[1]
- with open(__file__, 'rb') as post_file:
+ with open(THIS_FILE, 'rb') as post_file:
post_data['form2-file1'] = post_file
response = self.client.post(
reverse(self.wizard_urlname,
@@ -153,7 +156,7 @@ class NamedWizardTests(object):
self.assertEqual(response.context['wizard']['steps'].current, 'form3')
# Check that the file got uploaded properly.
- with open(__file__, 'rb') as f, temp_storage.open(UPLOADED_FILE_NAME) as f2:
+ with open(THIS_FILE, 'rb') as f, temp_storage.open(UPLOADED_FILE_NAME) as f2:
self.assertEqual(f.read(), f2.read())
response = self.client.post(
@@ -196,7 +199,7 @@ class NamedWizardTests(object):
self.assertEqual(response.status_code, 200)
post_data = self.wizard_step_data[1]
- with open(__file__, 'rb') as post_file:
+ with open(THIS_FILE, 'rb') as post_file:
post_data['form2-file1'] = post_file
response = self.client.post(
reverse(self.wizard_urlname,
@@ -210,7 +213,7 @@ class NamedWizardTests(object):
response = self.client.get(step2_url)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.context['wizard']['steps'].current, 'form2')
- with open(__file__, 'rb') as f, temp_storage.open(UPLOADED_FILE_NAME) as f2:
+ with open(THIS_FILE, 'rb') as f, temp_storage.open(UPLOADED_FILE_NAME) as f2:
self.assertEqual(f.read(), f2.read())
response = self.client.post(
@@ -259,7 +262,7 @@ class NamedWizardTests(object):
self.assertEqual(response.status_code, 200)
post_data = self.wizard_step_data[1]
- with open(__file__, 'rb') as post_file:
+ with open(THIS_FILE, 'rb') as post_file:
post_data['form2-file1'] = post_file
response = self.client.post(
reverse(self.wizard_urlname,
diff --git a/django/contrib/formtools/tests/wizard/wizardtests/tests.py b/django/contrib/formtools/tests/wizard/wizardtests/tests.py
index 2928797bce..b880dcb0b3 100644
--- a/django/contrib/formtools/tests/wizard/wizardtests/tests.py
+++ b/django/contrib/formtools/tests/wizard/wizardtests/tests.py
@@ -16,6 +16,8 @@ from django.contrib.formtools.tests.models import Poet, Poem
from .forms import temp_storage
+# On Python 2, __file__ may end with .pyc
+THIS_FILE = upath(__file__.rstrip("c"))
UPLOADED_FILE_NAME = 'tests.py'
@@ -115,14 +117,14 @@ class WizardTests(object):
self.assertEqual(response.context['wizard']['steps'].current, 'form2')
post_data = self.wizard_step_data[1]
- with open(upath(__file__), 'rb') as post_file:
+ with open(upath(THIS_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)
self.assertEqual(response.context['wizard']['steps'].current, 'form3')
# Check that the file got uploaded properly.
- with open(upath(__file__), 'rb') as f, temp_storage.open(UPLOADED_FILE_NAME) as f2:
+ with open(THIS_FILE, 'rb') as f, temp_storage.open(UPLOADED_FILE_NAME) as f2:
self.assertEqual(f.read(), f2.read())
response = self.client.post(self.wizard_url, self.wizard_step_data[2])
@@ -152,7 +154,7 @@ class WizardTests(object):
self.assertEqual(response.status_code, 200)
post_data = self.wizard_step_data[1]
- with open(upath(__file__), 'rb') as post_file:
+ with open(THIS_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)
@@ -184,7 +186,7 @@ class WizardTests(object):
self.assertEqual(response.status_code, 200)
post_data = self.wizard_step_data[1]
- with open(upath(__file__), 'rb') as post_file:
+ with open(THIS_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)
@@ -212,7 +214,7 @@ class WizardTests(object):
self.assertEqual(response.context['wizard']['steps'].current, 'form2')
post_data = self.wizard_step_data[1]
- with open(upath(__file__), 'rb') as post_file:
+ with open(THIS_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)
@@ -333,7 +335,7 @@ class WizardTestKwargs(TestCase):
self.wizard_step_data[0]['form1-user'] = self.testuser.pk
def test_template(self):
- templates = os.path.join(os.path.dirname(upath(__file__)), 'templates')
+ templates = os.path.join(os.path.dirname(THIS_FILE), 'templates')
with self.settings(
TEMPLATE_DIRS=list(settings.TEMPLATE_DIRS) + [templates]):
response = self.client.get(self.wizard_url)