From f5d97260a5146e1e01a7b3c079108354f0c9e5ef Mon Sep 17 00:00:00 2001 From: Ayub khan Date: Thu, 22 Aug 2019 18:42:58 +0500 Subject: [PATCH] Fixed all py3 tests with AssertionError: "Error: too few arguments" --- .../management/commands/tests/test_create_course.py | 5 ++++- .../management/commands/tests/test_delete_orphans.py | 6 +++++- .../management/commands/tests/test_export.py | 5 ++++- .../management/commands/tests/test_force_publish.py | 6 +++++- .../management/commands/tests/test_git_export.py | 11 +++++++++-- .../commands/tests/test_migrate_to_split.py | 7 ++++++- .../certificates/tests/test_create_fake_cert.py | 8 +++++++- .../management/commands/tests/test_git_add_course.py | 6 +++++- 8 files changed, 45 insertions(+), 9 deletions(-) diff --git a/cms/djangoapps/contentstore/management/commands/tests/test_create_course.py b/cms/djangoapps/contentstore/management/commands/tests/test_create_course.py index e388bfbd22..d9e90d57ee 100644 --- a/cms/djangoapps/contentstore/management/commands/tests/test_create_course.py +++ b/cms/djangoapps/contentstore/management/commands/tests/test_create_course.py @@ -23,7 +23,10 @@ class TestArgParsing(TestCase): super(TestArgParsing, self).setUp() def test_no_args(self): - errstring = "Error: too few arguments" + if six.PY2: + errstring = "Error: too few arguments" + else: + errstring = "Error: the following arguments are required: modulestore, user, org, number, run" with self.assertRaisesRegexp(CommandError, errstring): call_command('create_course') diff --git a/cms/djangoapps/contentstore/management/commands/tests/test_delete_orphans.py b/cms/djangoapps/contentstore/management/commands/tests/test_delete_orphans.py index ce46384f4a..8d4dbf720e 100644 --- a/cms/djangoapps/contentstore/management/commands/tests/test_delete_orphans.py +++ b/cms/djangoapps/contentstore/management/commands/tests/test_delete_orphans.py @@ -21,7 +21,11 @@ class TestDeleteOrphan(TestOrphanBase): """ Test delete_orphans command with no arguments """ - with self.assertRaisesRegexp(CommandError, 'Error: too few arguments'): + if six.PY2: + errstring = 'Error: too few arguments' + else: + errstring = 'Error: the following arguments are required: course_id' + with self.assertRaisesRegexp(CommandError, errstring): call_command('delete_orphans') @ddt.data(ModuleStoreEnum.Type.split, ModuleStoreEnum.Type.mongo) diff --git a/cms/djangoapps/contentstore/management/commands/tests/test_export.py b/cms/djangoapps/contentstore/management/commands/tests/test_export.py index 4f992c0783..4e02926125 100644 --- a/cms/djangoapps/contentstore/management/commands/tests/test_export.py +++ b/cms/djangoapps/contentstore/management/commands/tests/test_export.py @@ -25,7 +25,10 @@ class TestArgParsingCourseExport(unittest.TestCase): """ Test export command with no arguments """ - errstring = "Error: too few arguments" + if six.PY2: + errstring = "Error: too few arguments" + else: + errstring = "Error: the following arguments are required: course_id, output_path" with self.assertRaisesRegexp(CommandError, errstring): call_command('export') diff --git a/cms/djangoapps/contentstore/management/commands/tests/test_force_publish.py b/cms/djangoapps/contentstore/management/commands/tests/test_force_publish.py index 0057069bee..600deaba86 100644 --- a/cms/djangoapps/contentstore/management/commands/tests/test_force_publish.py +++ b/cms/djangoapps/contentstore/management/commands/tests/test_force_publish.py @@ -29,7 +29,11 @@ class TestForcePublish(SharedModuleStoreTestCase): """ Test 'force_publish' command with no arguments """ - errstring = "Error: too few arguments" + if six.PY2: + errstring = "Error: too few arguments" + else: + errstring = "Error: the following arguments are required: course_key" + with self.assertRaisesRegexp(CommandError, errstring): call_command('force_publish') 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 6d8d30433d..ae21e494c5 100644 --- a/cms/djangoapps/contentstore/management/commands/tests/test_git_export.py +++ b/cms/djangoapps/contentstore/management/commands/tests/test_git_export.py @@ -62,8 +62,15 @@ class TestGitExport(CourseTestCase): with self.assertRaisesRegexp(CommandError, 'Error: unrecognized arguments:*'): call_command('git_export', 'blah', 'blah', 'blah', stderr=StringIO()) - with self.assertRaisesMessage(CommandError, 'Error: too few arguments'): - call_command('git_export', stderr=StringIO()) + if six.PY2: + with self.assertRaisesMessage(CommandError, 'Error: too few arguments'): + call_command('git_export', stderr=StringIO()) + else: + with self.assertRaisesMessage( + CommandError, + 'Error: the following arguments are required: course_loc, git_url' + ): + call_command('git_export', stderr=StringIO()) # Send bad url to get course not exported with self.assertRaisesRegexp(CommandError, six.text_type(GitExportError.URL_BAD)): diff --git a/cms/djangoapps/contentstore/management/commands/tests/test_migrate_to_split.py b/cms/djangoapps/contentstore/management/commands/tests/test_migrate_to_split.py index e80dbda627..9ed7bf52e7 100644 --- a/cms/djangoapps/contentstore/management/commands/tests/test_migrate_to_split.py +++ b/cms/djangoapps/contentstore/management/commands/tests/test_migrate_to_split.py @@ -3,6 +3,8 @@ Unittests for migrating a course to split mongo """ from __future__ import absolute_import +import six + from django.core.management import CommandError, call_command from django.test import TestCase @@ -24,7 +26,10 @@ class TestArgParsing(TestCase): """ Test the arg length error """ - errstring = "Error: too few arguments" + if six.PY2: + errstring = "Error: too few arguments" + else: + errstring = "Error: the following arguments are required: course_key, email" with self.assertRaisesRegexp(CommandError, errstring): call_command("migrate_to_split") diff --git a/lms/djangoapps/certificates/tests/test_create_fake_cert.py b/lms/djangoapps/certificates/tests/test_create_fake_cert.py index 94cceca099..f854be9099 100644 --- a/lms/djangoapps/certificates/tests/test_create_fake_cert.py +++ b/lms/djangoapps/certificates/tests/test_create_fake_cert.py @@ -2,6 +2,8 @@ from __future__ import absolute_import +import six + from django.core.management import call_command from django.core.management.base import CommandError from django.test import TestCase @@ -46,7 +48,11 @@ class CreateFakeCertTest(TestCase): self.assertEqual(cert.mode, 'honor') def test_too_few_args(self): - with self.assertRaisesRegexp(CommandError, 'Error: too few arguments'): + if six.PY2: + errstring = 'Error: too few arguments' + else: + errstring = 'Error: the following arguments are required: COURSE_KEY' + with self.assertRaisesRegexp(CommandError, errstring): self._run_command(self.USERNAME) def _run_command(self, *args, **kwargs): diff --git a/lms/djangoapps/dashboard/management/commands/tests/test_git_add_course.py b/lms/djangoapps/dashboard/management/commands/tests/test_git_add_course.py index d1ccd26226..24b95bcf17 100644 --- a/lms/djangoapps/dashboard/management/commands/tests/test_git_add_course.py +++ b/lms/djangoapps/dashboard/management/commands/tests/test_git_add_course.py @@ -6,6 +6,7 @@ from __future__ import absolute_import import logging import os import shutil +import six from six import StringIO import subprocess import unittest @@ -73,7 +74,10 @@ class TestGitAddCourse(SharedModuleStoreTestCase): Validate argument checking """ # No argument given. - self.assertCommandFailureRegexp('Error: too few arguments') + if six.PY2: + self.assertCommandFailureRegexp('Error: too few arguments') + else: + self.assertCommandFailureRegexp('Error: the following arguments are required: repository_url') # Extra/Un-named arguments given. self.assertCommandFailureRegexp( 'Error: unrecognized arguments: blah blah blah',