diff --git a/cms/djangoapps/contentstore/git_export_utils.py b/cms/djangoapps/contentstore/git_export_utils.py index 42698db5a4..b4ae1dfe9e 100644 --- a/cms/djangoapps/contentstore/git_export_utils.py +++ b/cms/djangoapps/contentstore/git_export_utils.py @@ -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) diff --git a/cms/djangoapps/contentstore/management/commands/tests/test_git_export.py b/cms/djangoapps/contentstore/management/commands/tests/test_git_export.py index 0fa709ad0a..3b98c3db4a 100644 --- a/cms/djangoapps/contentstore/management/commands/tests/test_git_export.py +++ b/cms/djangoapps/contentstore/management/commands/tests/test_git_export.py @@ -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))