Merge pull request #7124 from edx/django-upgrade/unicode-export-errors
Force GitExportError messages to be unicode objects
This commit is contained in:
@@ -30,6 +30,10 @@ class GitExportError(Exception):
|
||||
Convenience exception class for git export error conditions.
|
||||
"""
|
||||
|
||||
def __init__(self, message):
|
||||
# Force the lazy i18n values to turn into actual unicode objects
|
||||
super(GitExportError, self).__init__(unicode(message))
|
||||
|
||||
NO_EXPORT_DIR = _("GIT_REPO_EXPORT_DIR not set or path {0} doesn't exist, "
|
||||
"please create it, or configure a different path with "
|
||||
"GIT_REPO_EXPORT_DIR").format(GIT_REPO_EXPORT_DIR)
|
||||
|
||||
@@ -69,13 +69,13 @@ class TestGitExport(CourseTestCase):
|
||||
|
||||
# Send bad url to get course not exported
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
with self.assertRaisesRegexp(CommandError, str(GitExportError.URL_BAD)):
|
||||
with self.assertRaisesRegexp(CommandError, unicode(GitExportError.URL_BAD)):
|
||||
call_command('git_export', 'foo/bar/baz', 'silly',
|
||||
stderr=StringIO.StringIO())
|
||||
self.assertEqual(ex.exception.code, 1)
|
||||
# Send bad course_id to get course not exported
|
||||
with self.assertRaises(SystemExit) as ex:
|
||||
with self.assertRaisesRegexp(CommandError, str(GitExportError.BAD_COURSE)):
|
||||
with self.assertRaisesRegexp(CommandError, unicode(GitExportError.BAD_COURSE)):
|
||||
call_command('git_export', 'foo/bar:baz', 'silly',
|
||||
stderr=StringIO.StringIO())
|
||||
self.assertEqual(ex.exception.code, 1)
|
||||
@@ -86,7 +86,7 @@ class TestGitExport(CourseTestCase):
|
||||
"""
|
||||
output = StringIO.StringIO()
|
||||
with self.assertRaises(SystemExit):
|
||||
with self.assertRaisesRegexp(CommandError, str(GitExportError.BAD_COURSE)):
|
||||
with self.assertRaisesRegexp(CommandError, unicode(GitExportError.BAD_COURSE)):
|
||||
call_command(
|
||||
'git_export', 'foo/bar:baz', 'silly',
|
||||
stdout=output, stderr=output
|
||||
@@ -96,7 +96,7 @@ class TestGitExport(CourseTestCase):
|
||||
|
||||
output = StringIO.StringIO()
|
||||
with self.assertRaises(SystemExit):
|
||||
with self.assertRaisesRegexp(CommandError, str(GitExportError.URL_BAD)):
|
||||
with self.assertRaisesRegexp(CommandError, unicode(GitExportError.URL_BAD)):
|
||||
call_command(
|
||||
'git_export', 'foo/bar/baz', 'silly',
|
||||
stdout=output, stderr=output
|
||||
@@ -113,14 +113,14 @@ class TestGitExport(CourseTestCase):
|
||||
Test several bad URLs for validation
|
||||
"""
|
||||
course_key = SlashSeparatedCourseKey('org', 'course', 'run')
|
||||
with self.assertRaisesRegexp(GitExportError, str(GitExportError.URL_BAD)):
|
||||
with self.assertRaisesRegexp(GitExportError, unicode(GitExportError.URL_BAD)):
|
||||
git_export_utils.export_to_git(course_key, 'Sillyness')
|
||||
|
||||
with self.assertRaisesRegexp(GitExportError, str(GitExportError.URL_BAD)):
|
||||
with self.assertRaisesRegexp(GitExportError, unicode(GitExportError.URL_BAD)):
|
||||
git_export_utils.export_to_git(course_key, 'example.com:edx/notreal')
|
||||
|
||||
with self.assertRaisesRegexp(GitExportError,
|
||||
str(GitExportError.URL_NO_AUTH)):
|
||||
unicode(GitExportError.URL_NO_AUTH)):
|
||||
git_export_utils.export_to_git(course_key, 'http://blah')
|
||||
|
||||
def test_bad_git_repos(self):
|
||||
@@ -132,7 +132,7 @@ class TestGitExport(CourseTestCase):
|
||||
course_key = SlashSeparatedCourseKey('foo', 'blah', '100-')
|
||||
# Test bad clones
|
||||
with self.assertRaisesRegexp(GitExportError,
|
||||
str(GitExportError.CANNOT_PULL)):
|
||||
unicode(GitExportError.CANNOT_PULL)):
|
||||
git_export_utils.export_to_git(
|
||||
course_key,
|
||||
'https://user:blah@example.com/test_repo.git')
|
||||
@@ -140,14 +140,14 @@ class TestGitExport(CourseTestCase):
|
||||
|
||||
# Setup good repo with bad course to test xml export
|
||||
with self.assertRaisesRegexp(GitExportError,
|
||||
str(GitExportError.XML_EXPORT_FAIL)):
|
||||
unicode(GitExportError.XML_EXPORT_FAIL)):
|
||||
git_export_utils.export_to_git(
|
||||
course_key,
|
||||
'file://{0}'.format(self.bare_repo_dir))
|
||||
|
||||
# Test bad git remote after successful clone
|
||||
with self.assertRaisesRegexp(GitExportError,
|
||||
str(GitExportError.CANNOT_PULL)):
|
||||
unicode(GitExportError.CANNOT_PULL)):
|
||||
git_export_utils.export_to_git(
|
||||
course_key,
|
||||
'https://user:blah@example.com/r.git')
|
||||
@@ -204,6 +204,6 @@ class TestGitExport(CourseTestCase):
|
||||
)
|
||||
|
||||
with self.assertRaisesRegexp(GitExportError,
|
||||
str(GitExportError.CANNOT_COMMIT)):
|
||||
unicode(GitExportError.CANNOT_COMMIT)):
|
||||
git_export_utils.export_to_git(
|
||||
self.course.id, 'file://{0}'.format(self.bare_repo_dir))
|
||||
|
||||
Reference in New Issue
Block a user