From 58124e427d840a5e9b1060b314b1c9ca147654c6 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Sat, 8 Dec 2012 11:13:52 +0100 Subject: [PATCH] Fixed #19357 -- Allow non-ASCII chars in filesystem paths Thanks kujiu for the report and Aymeric Augustin for the review. --- formtools/tests/__init__.py | 5 +++-- formtools/tests/wizard/wizardtests/tests.py | 15 ++++++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/formtools/tests/__init__.py b/formtools/tests/__init__.py index a21ffde..aa7d5ff 100644 --- a/formtools/tests/__init__.py +++ b/formtools/tests/__init__.py @@ -14,6 +14,7 @@ from django.contrib.formtools.wizard import FormWizard from django.test import TestCase from django.test.html import parse_html from django.test.utils import override_settings +from django.utils._os import upath from django.utils import unittest from django.contrib.formtools.tests.wizard import * @@ -36,7 +37,7 @@ class TestFormPreview(preview.FormPreview): @override_settings( TEMPLATE_DIRS=( - os.path.join(os.path.dirname(__file__), 'templates'), + os.path.join(os.path.dirname(upath(__file__)), 'templates'), ), ) class PreviewTests(TestCase): @@ -214,7 +215,7 @@ class DummyRequest(http.HttpRequest): @override_settings( SECRET_KEY="123", TEMPLATE_DIRS=( - os.path.join(os.path.dirname(__file__), 'templates'), + os.path.join(os.path.dirname(upath(__file__)), 'templates'), ), ) class WizardTests(TestCase): diff --git a/formtools/tests/wizard/wizardtests/tests.py b/formtools/tests/wizard/wizardtests/tests.py index 6403a55..4aaea7d 100644 --- a/formtools/tests/wizard/wizardtests/tests.py +++ b/formtools/tests/wizard/wizardtests/tests.py @@ -9,6 +9,7 @@ from django.conf import settings from django.contrib.auth.models import User from django.contrib.formtools.wizard.views import CookieWizardView from django.contrib.formtools.tests.wizard.forms import UserForm, UserFormSet +from django.utils._os import upath class WizardTests(object): @@ -86,7 +87,7 @@ class WizardTests(object): self.assertEqual(response.context['wizard']['steps'].current, 'form2') post_data = self.wizard_step_data[1] - post_data['form2-file1'] = open(__file__, 'rb') + post_data['form2-file1'] = open(upath(__file__), 'rb') response = self.client.post(self.wizard_url, post_data) self.assertEqual(response.status_code, 200) self.assertEqual(response.context['wizard']['steps'].current, 'form3') @@ -99,7 +100,7 @@ class WizardTests(object): self.assertEqual(response.status_code, 200) all_data = response.context['form_list'] - with open(__file__, 'rb') as f: + with open(upath(__file__), 'rb') as f: self.assertEqual(all_data[1]['file1'].read(), f.read()) all_data[1]['file1'].close() del all_data[1]['file1'] @@ -118,7 +119,7 @@ class WizardTests(object): self.assertEqual(response.status_code, 200) post_data = self.wizard_step_data[1] - with open(__file__, 'rb') as post_file: + with open(upath(__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) @@ -130,7 +131,7 @@ class WizardTests(object): self.assertEqual(response.status_code, 200) all_data = response.context['all_cleaned_data'] - with open(__file__, 'rb') as f: + with open(upath(__file__), 'rb') as f: self.assertEqual(all_data['file1'].read(), f.read()) all_data['file1'].close() del all_data['file1'] @@ -150,7 +151,7 @@ class WizardTests(object): post_data = self.wizard_step_data[1] post_data['form2-file1'].close() - post_data['form2-file1'] = open(__file__, 'rb') + post_data['form2-file1'] = open(upath(__file__), 'rb') response = self.client.post(self.wizard_url, post_data) self.assertEqual(response.status_code, 200) @@ -178,7 +179,7 @@ class WizardTests(object): post_data = self.wizard_step_data[1] post_data['form2-file1'].close() - post_data['form2-file1'] = open(__file__, 'rb') + post_data['form2-file1'] = open(upath(__file__), 'rb') response = self.client.post(self.wizard_url, post_data) self.assertEqual(response.status_code, 200) self.assertEqual(response.context['wizard']['steps'].current, 'form3') @@ -291,7 +292,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(__file__), 'templates') + templates = os.path.join(os.path.dirname(upath(__file__)), 'templates') with self.settings( TEMPLATE_DIRS=list(settings.TEMPLATE_DIRS) + [templates]): response = self.client.get(self.wizard_url)