def test_course_larger_than_datastore_max_can_be_exported_and_loaded(self): unit = self.course.add_unit() num_lessons = vfs._MAX_VFS_SHARD_SIZE / len(LOREM_IPSUM) for unused in range(num_lessons): lesson = self.course.add_lesson(unit) lesson.objectives = LOREM_IPSUM self.course.save() other_course_name = 'other_course' other_course_context = actions.simple_add_course( other_course_name, self.ADMIN_EMAIL, 'Other') # Verify that a large course can be ETL'd out and recovered. fp, archive_file = tempfile.mkstemp(suffix='.zip') os.close(fp) try: parser = etl.create_args_parser() etl.main(parser.parse_args([ 'download', 'course', '/' + self.COURSE_NAME, 'localhost', '--archive_path', archive_file, '--force_overwrite', '--internal', '--disable_remote'])) etl.main(parser.parse_args([ 'upload', 'course', '/' + other_course_name, 'localhost', '--archive_path', archive_file, '--force_overwrite', '--internal', '--disable_remote'])) finally: os.unlink(archive_file) # Verify contents of course. course = courses.Course(handler=None, app_context=other_course_context) lessons = course.get_lessons(unit.unit_id) self.assertEquals(num_lessons, len(lessons)) for lesson in lessons: self.assertEquals(lesson.objectives, LOREM_IPSUM)
def test_dies_if_path_does_not_exist(self): args = [ 'run', 'modules.i18n_dashboard.jobs.UploadTranslations', self.url_prefix, 'localhost', '--job_args=%s' % self.zipfile_name] with self.assertRaises(IOError): etl.main(etl.create_args_parser().parse_args(args), testing=True)
def run_job(self, name, job_args=None): # Requires course at /first; use self._import_course(). args = ['run', name, '/first', 'localhost'] if job_args: args.append(job_args) etl.main(etl.create_args_parser().parse_args(args), testing=True)
def test_dies_if_path_has_bad_file_extension(self): args = [ 'run', 'modules.i18n_dashboard.jobs.UploadTranslations', self.url_prefix, 'localhost', '--job_args=%s' % self.zipfile_name + '.bad' ] with self.assertRaises(IOError): etl.main(etl.create_args_parser().parse_args(args), testing=True)
def run_job(self, name, job_args=None): # Requires course at /first; use self._import_course(). args = ['run', name, '/first', 'myapp', 'localhost:8080'] if job_args: args.append(job_args) etl.main(etl.PARSER.parse_args(args), environment_class=testing.FakeEnvironment)
def test_dies_if_path_already_exists(self): self.create_file('contents') args = [ 'run', 'modules.i18n_dashboard.jobs.DownloadTranslations', self.url_prefix, 'localhost', '--job_args=%s' % self.filename] with self.assertRaises(SystemExit): etl.main(etl.create_args_parser().parse_args(args), testing=True) self.assertIn('File already exists', self.get_log())
def run_job(self, name, job_args=None): # Requires course at /first; use self._import_course(). args = ['run', name, '/first', 'myapp', 'localhost:8080'] if job_args: args.append(job_args) etl.main( etl.PARSER.parse_args(args), environment_class=testing.FakeEnvironment)
def test_dies_if_path_has_bad_file_extension(self): args = [ 'run', 'modules.i18n_dashboard.jobs.UploadTranslations', self.url_prefix, 'localhost', '--job_args=%s' % self.zipfile_name + '.bad'] with self.assertRaises(SystemExit): etl.main(etl.create_args_parser().parse_args(args), testing=True) self.assertIn('Invalid file extension: ".bad"', self.get_log())
def test_download_of_course_with_no_translations_dies(self): args = [ 'run', 'modules.i18n_dashboard.jobs.DownloadTranslations', self.url_prefix, 'localhost', '--job_args=%s' % self.zipfile_name] with self.assertRaises(SystemExit): etl.main(etl.create_args_parser().parse_args(args), testing=True) self.assertIn( 'No translations found for course at %s; exiting' % self.url_prefix, self.get_log())
def assert_dies_if_cannot_get_app_context_for_course_url_prefix(self, job_name, job_args=None): bad_course_url_prefix = "/bad" + self.url_prefix args = ["run", "modules.i18n_dashboard.jobs." + job_name, bad_course_url_prefix, "localhost"] if job_args: args.append(job_args) with self.assertRaises(SystemExit): etl.main(etl.create_args_parser().parse_args(args), testing=True) self.assertIn("Unable to find course with url prefix " + bad_course_url_prefix, self.get_log())
def test_dies_if_path_has_bad_file_extension(self): args = [ "run", "modules.i18n_dashboard.jobs.UploadTranslations", self.url_prefix, "localhost", "--job_args=%s" % self.zipfile_name + ".bad", ] with self.assertRaises(IOError): etl.main(etl.create_args_parser().parse_args(args), testing=True)
def test_dies_if_path_does_not_exist(self): args = [ 'run', 'modules.i18n_dashboard.jobs.UploadTranslations', self.url_prefix, 'localhost', '--job_args=%s' % self.zipfile_name ] with self.assertRaises(SystemExit): etl.main(etl.create_args_parser().parse_args(args), testing=True) self.assertIn('File does not exist', self.get_log())
def test_dies_if_path_has_bad_file_extension(self): args = [ 'run', 'modules.i18n_dashboard.jobs.UploadTranslations', self.url_prefix, 'myapp', 'localhost:8080', '--job_args=%s' % self.zipfile_name + '.bad'] with self.assertRaises(SystemExit): etl.main( etl.PARSER.parse_args(args), environment_class=testing.FakeEnvironment) self.assertIn('Invalid file extension: ".bad"', self.get_log())
def test_dies_if_path_does_not_exist(self): args = [ 'run', 'modules.i18n_dashboard.jobs.UploadTranslations', self.url_prefix, 'myapp', 'localhost:8080', '--job_args=%s' % self.zipfile_name] with self.assertRaises(SystemExit): etl.main( etl.PARSER.parse_args(args), environment_class=testing.FakeEnvironment) self.assertIn('File does not exist', self.get_log())
def test_dies_if_cannot_get_app_context_for_course_url_prefix(self): self.create_zip_file('contents') args = [ 'run', 'modules.i18n_dashboard.jobs.UploadTranslations', '/bad' + self.url_prefix, 'localhost', '--job_args=%s' % self.zipfile_name] with self.assertRaises(SystemExit): etl.main(etl.create_args_parser().parse_args(args), testing=True) self.assertIn( 'Unable to find course with url prefix', self.get_log())
def test_dies_if_path_has_bad_file_extension(self): args = [ 'run', 'modules.i18n_dashboard.jobs.UploadTranslations', self.url_prefix, 'myapp', 'localhost:8080', '--job_args=%s' % self.zipfile_name + '.bad' ] with self.assertRaises(SystemExit): etl.main(etl.PARSER.parse_args(args), environment_class=testing.FakeEnvironment) self.assertIn('Invalid file extension: ".bad"', self.get_log())
def test_dies_if_cannot_get_app_context_for_course_url_prefix(self): self.create_zip_file('contents') args = [ 'run', 'modules.i18n_dashboard.jobs.UploadTranslations', '/bad' + self.url_prefix, 'localhost', '--job_args=%s' % self.zipfile_name ] with self.assertRaises(SystemExit): etl.main(etl.create_args_parser().parse_args(args), testing=True) self.assertIn('Unable to find course with url prefix', self.get_log())
def test_dies_if_path_does_not_exist(self): args = [ 'run', 'modules.i18n_dashboard.jobs.UploadTranslations', self.url_prefix, 'myapp', 'localhost:8080', '--job_args=%s' % self.zipfile_name ] with self.assertRaises(SystemExit): etl.main(etl.PARSER.parse_args(args), environment_class=testing.FakeEnvironment) self.assertIn('File does not exist', self.get_log())
def test_dies_if_path_already_exists(self): self.create_file('contents') args = [ 'run', 'modules.i18n_dashboard.jobs.DownloadTranslations', self.url_prefix, 'localhost', '--job_args=%s' % self.filename ] with self.assertRaises(SystemExit): etl.main(etl.create_args_parser().parse_args(args), testing=True) self.assertIn('File already exists', self.get_log())
def test_dies_if_path_already_exists(self): self.create_file('contents') args = [ 'run', 'modules.i18n_dashboard.jobs.DownloadTranslations', self.url_prefix, 'myapp', 'localhost:8080', '--job_args=%s' % self.filename ] with self.assertRaises(SystemExit): etl.main(etl.PARSER.parse_args(args), environment_class=testing.FakeEnvironment) self.assertIn('File already exists', self.get_log())
def test_dies_if_path_already_exists(self): self.create_file('contents') args = [ 'run', 'modules.i18n_dashboard.jobs.DownloadTranslations', self.url_prefix, 'myapp', 'localhost:8080', '--job_args=%s' % self.filename] with self.assertRaises(SystemExit): etl.main( etl.PARSER.parse_args(args), environment_class=testing.FakeEnvironment) self.assertIn('File already exists', self.get_log())
def test_download_of_course_with_no_translations_dies(self): args = [ 'run', 'modules.i18n_dashboard.jobs.DownloadTranslations', self.url_prefix, 'localhost', '--job_args=%s' % self.zipfile_name ] with self.assertRaises(SystemExit): etl.main(etl.create_args_parser().parse_args(args), testing=True) self.assertIn( 'No translations found for course at %s; exiting' % self.url_prefix, self.get_log())
def test_dies_if_path_already_exists(self): self.create_file("contents") args = [ "run", "modules.i18n_dashboard.jobs.DownloadTranslations", self.url_prefix, "localhost", "--job_args=%s" % self.filename, ] with self.assertRaises(SystemExit): etl.main(etl.create_args_parser().parse_args(args), testing=True) self.assertIn("File already exists", self.get_log())
def test_download_of_course_with_no_translations_dies(self): args = [ 'run', 'modules.i18n_dashboard.jobs.DownloadTranslations', self.url_prefix, 'myapp', 'localhost:8080', '--job_args=%s' % self.zipfile_name ] with self.assertRaises(SystemExit): etl.main(etl.PARSER.parse_args(args), environment_class=testing.FakeEnvironment) self.assertIn( 'No translations found for course at %s; exiting' % self.url_prefix, self.get_log())
def test_dies_if_cannot_get_app_context_for_course_url_prefix(self): self.create_zip_file("contents") args = [ "run", "modules.i18n_dashboard.jobs.UploadTranslations", "/bad" + self.url_prefix, "localhost", "--job_args=%s" % self.zipfile_name, ] with self.assertRaises(SystemExit): etl.main(etl.create_args_parser().parse_args(args), testing=True) self.assertIn("Unable to find course with url prefix", self.get_log())
def test_download_of_course_with_no_translations_dies(self): args = [ 'run', 'modules.i18n_dashboard.jobs.DownloadTranslations', self.url_prefix, 'myapp', 'localhost:8080', '--job_args=%s' % self.zipfile_name] with self.assertRaises(SystemExit): etl.main( etl.PARSER.parse_args(args), environment_class=testing.FakeEnvironment) self.assertIn( 'No translations found for course at %s; exiting' % self.url_prefix, self.get_log())
def assert_dies_if_cannot_get_app_context_for_course_url_prefix( self, job_name, job_args=None): bad_course_url_prefix = '/bad' + self.url_prefix args = [ 'run', 'modules.i18n_dashboard.jobs.' + job_name, bad_course_url_prefix, 'localhost' ] if job_args: args.append(job_args) with self.assertRaises(SystemExit): etl.main(etl.create_args_parser().parse_args(args), testing=True) self.assertIn( 'Unable to find course with url prefix ' + bad_course_url_prefix, self.get_log())
def assert_dies_if_cannot_get_app_context_for_course_url_prefix( self, job_name, job_args=None): bad_course_url_prefix = '/bad' + self.url_prefix args = [ 'run', 'modules.i18n_dashboard.jobs.' + job_name, bad_course_url_prefix, 'myapp', 'localhost:8080' ] if job_args: args.append(job_args) with self.assertRaises(SystemExit): etl.main(etl.PARSER.parse_args(args), environment_class=testing.FakeEnvironment) self.assertIn( 'Unable to find course with url prefix ' + bad_course_url_prefix, self.get_log())
def assert_dies_if_cannot_get_app_context_for_course_url_prefix( self, job_name, job_args=None): bad_course_url_prefix = '/bad' + self.url_prefix args = [ 'run', 'modules.i18n_dashboard.jobs.' + job_name, bad_course_url_prefix, 'myapp', 'localhost:8080'] if job_args: args.append(job_args) with self.assertRaises(SystemExit): etl.main( etl.PARSER.parse_args(args), environment_class=testing.FakeEnvironment) self.assertIn( 'Unable to find course with url prefix ' + bad_course_url_prefix, self.get_log())
def test_course_larger_than_datastore_max_can_be_exported_and_loaded(self): unit = self.course.add_unit() num_lessons = vfs._MAX_VFS_SHARD_SIZE / len(LOREM_IPSUM) for unused in range(num_lessons): lesson = self.course.add_lesson(unit) lesson.objectives = LOREM_IPSUM self.course.save() other_course_name = 'other_course' other_course_context = actions.simple_add_course( other_course_name, self.ADMIN_EMAIL, 'Other') # Verify that a large course can be ETL'd out and recovered. fp, archive_file = tempfile.mkstemp(suffix='.zip') os.close(fp) try: parser = etl.create_args_parser() etl.main( parser.parse_args([ 'download', 'course', '/' + self.COURSE_NAME, 'localhost', '--archive_path', archive_file, '--force_overwrite', '--internal', '--disable_remote' ])) etl.main( parser.parse_args([ 'upload', 'course', '/' + other_course_name, 'localhost', '--archive_path', archive_file, '--force_overwrite', '--internal', '--disable_remote' ])) finally: os.unlink(archive_file) # Verify contents of course. course = courses.Course(handler=None, app_context=other_course_context) lessons = course.get_lessons(unit.unit_id) self.assertEquals(num_lessons, len(lessons)) for lesson in lessons: self.assertEquals(lesson.objectives, LOREM_IPSUM)