Commit 6c0982b2 by Calen Pennington Committed by Clinton Blackburn

Force GitExportError messages to be unicode objects

parent 7ac58129
...@@ -30,6 +30,10 @@ class GitExportError(Exception): ...@@ -30,6 +30,10 @@ class GitExportError(Exception):
Convenience exception class for git export error conditions. 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, " NO_EXPORT_DIR = _("GIT_REPO_EXPORT_DIR not set or path {0} doesn't exist, "
"please create it, or configure a different path with " "please create it, or configure a different path with "
"GIT_REPO_EXPORT_DIR").format(GIT_REPO_EXPORT_DIR) "GIT_REPO_EXPORT_DIR").format(GIT_REPO_EXPORT_DIR)
......
...@@ -69,13 +69,13 @@ class TestGitExport(CourseTestCase): ...@@ -69,13 +69,13 @@ class TestGitExport(CourseTestCase):
# Send bad url to get course not exported # Send bad url to get course not exported
with self.assertRaises(SystemExit) as ex: 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', call_command('git_export', 'foo/bar/baz', 'silly',
stderr=StringIO.StringIO()) stderr=StringIO.StringIO())
self.assertEqual(ex.exception.code, 1) self.assertEqual(ex.exception.code, 1)
# Send bad course_id to get course not exported # Send bad course_id to get course not exported
with self.assertRaises(SystemExit) as ex: 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', call_command('git_export', 'foo/bar:baz', 'silly',
stderr=StringIO.StringIO()) stderr=StringIO.StringIO())
self.assertEqual(ex.exception.code, 1) self.assertEqual(ex.exception.code, 1)
...@@ -86,7 +86,7 @@ class TestGitExport(CourseTestCase): ...@@ -86,7 +86,7 @@ class TestGitExport(CourseTestCase):
""" """
output = StringIO.StringIO() output = StringIO.StringIO()
with self.assertRaises(SystemExit): with self.assertRaises(SystemExit):
with self.assertRaisesRegexp(CommandError, str(GitExportError.BAD_COURSE)): with self.assertRaisesRegexp(CommandError, unicode(GitExportError.BAD_COURSE)):
call_command( call_command(
'git_export', 'foo/bar:baz', 'silly', 'git_export', 'foo/bar:baz', 'silly',
stdout=output, stderr=output stdout=output, stderr=output
...@@ -96,7 +96,7 @@ class TestGitExport(CourseTestCase): ...@@ -96,7 +96,7 @@ class TestGitExport(CourseTestCase):
output = StringIO.StringIO() output = StringIO.StringIO()
with self.assertRaises(SystemExit): with self.assertRaises(SystemExit):
with self.assertRaisesRegexp(CommandError, str(GitExportError.URL_BAD)): with self.assertRaisesRegexp(CommandError, unicode(GitExportError.URL_BAD)):
call_command( call_command(
'git_export', 'foo/bar/baz', 'silly', 'git_export', 'foo/bar/baz', 'silly',
stdout=output, stderr=output stdout=output, stderr=output
...@@ -113,14 +113,14 @@ class TestGitExport(CourseTestCase): ...@@ -113,14 +113,14 @@ class TestGitExport(CourseTestCase):
Test several bad URLs for validation Test several bad URLs for validation
""" """
course_key = SlashSeparatedCourseKey('org', 'course', 'run') 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') 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') git_export_utils.export_to_git(course_key, 'example.com:edx/notreal')
with self.assertRaisesRegexp(GitExportError, with self.assertRaisesRegexp(GitExportError,
str(GitExportError.URL_NO_AUTH)): unicode(GitExportError.URL_NO_AUTH)):
git_export_utils.export_to_git(course_key, 'http://blah') git_export_utils.export_to_git(course_key, 'http://blah')
def test_bad_git_repos(self): def test_bad_git_repos(self):
...@@ -132,7 +132,7 @@ class TestGitExport(CourseTestCase): ...@@ -132,7 +132,7 @@ class TestGitExport(CourseTestCase):
course_key = SlashSeparatedCourseKey('foo', 'blah', '100-') course_key = SlashSeparatedCourseKey('foo', 'blah', '100-')
# Test bad clones # Test bad clones
with self.assertRaisesRegexp(GitExportError, with self.assertRaisesRegexp(GitExportError,
str(GitExportError.CANNOT_PULL)): unicode(GitExportError.CANNOT_PULL)):
git_export_utils.export_to_git( git_export_utils.export_to_git(
course_key, course_key,
'https://user:blah@example.com/test_repo.git') 'https://user:blah@example.com/test_repo.git')
...@@ -140,14 +140,14 @@ class TestGitExport(CourseTestCase): ...@@ -140,14 +140,14 @@ class TestGitExport(CourseTestCase):
# Setup good repo with bad course to test xml export # Setup good repo with bad course to test xml export
with self.assertRaisesRegexp(GitExportError, with self.assertRaisesRegexp(GitExportError,
str(GitExportError.XML_EXPORT_FAIL)): unicode(GitExportError.XML_EXPORT_FAIL)):
git_export_utils.export_to_git( git_export_utils.export_to_git(
course_key, course_key,
'file://{0}'.format(self.bare_repo_dir)) 'file://{0}'.format(self.bare_repo_dir))
# Test bad git remote after successful clone # Test bad git remote after successful clone
with self.assertRaisesRegexp(GitExportError, with self.assertRaisesRegexp(GitExportError,
str(GitExportError.CANNOT_PULL)): unicode(GitExportError.CANNOT_PULL)):
git_export_utils.export_to_git( git_export_utils.export_to_git(
course_key, course_key,
'https://user:blah@example.com/r.git') 'https://user:blah@example.com/r.git')
...@@ -204,6 +204,6 @@ class TestGitExport(CourseTestCase): ...@@ -204,6 +204,6 @@ class TestGitExport(CourseTestCase):
) )
with self.assertRaisesRegexp(GitExportError, with self.assertRaisesRegexp(GitExportError,
str(GitExportError.CANNOT_COMMIT)): unicode(GitExportError.CANNOT_COMMIT)):
git_export_utils.export_to_git( git_export_utils.export_to_git(
self.course.id, 'file://{0}'.format(self.bare_repo_dir)) self.course.id, 'file://{0}'.format(self.bare_repo_dir))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment