Example #1
0
class TestArgParsing(ModuleStoreTestCase):
    """
    Tests for parsing arguments of the `update_transcripts` command
    """
    def setUp(self):
        self.command = Command()

    def test_too_much_args(self):
        """
        Tests for the case when too much args are specified
        """
        errstring = "update_transcripts requires one or no arguments"
        with self.assertRaisesRegexp(CommandError, errstring):
            self.command.handle('arg1', 'arg2')

    def test_invalid_course_id(self):
        """
        Tests for the case when invalid course_id is specified
        """
        errstring = "The course_id is not of the right format."
        with self.assertRaisesRegexp(CommandError, errstring):
            self.command.handle('this_is_not_the_right_format')

    @patch(
        'contentstore.management.commands.update_transcripts.TranscriptS3Store'
    )
    def test_not_found_course_id(self, mock_store_class):
        """
        Tests for the case when non-existing course_id is specified
        """
        errstring = "The specified course does not exist."
        with self.assertRaisesRegexp(CommandError, errstring):
            self.command.handle('does/not/exist')

    @patch(
        'contentstore.management.commands.update_transcripts.TranscriptS3Store'
    )
    def test_when_store_failed_to_connect(self, mock_store_class):
        """
        Tests for the case when S3 connection error raises
        """
        mock_store_class.side_effect = Exception("Failed to connect to S3.")

        errstring = "Could not establish a connection to S3 for transcripts backup."
        with self.assertRaisesRegexp(CommandError, errstring):
            self.command.handle('org/course/name')

        mock_store_class.assert_called_once_with()
class TestArgParsing(ModuleStoreTestCase):
    """
    Tests for parsing arguments of the `update_transcripts` command
    """
    def setUp(self):
        self.command = Command()

    def test_too_much_args(self):
        """
        Tests for the case when too much args are specified
        """
        errstring = "update_transcripts requires one or no arguments"
        with self.assertRaisesRegexp(CommandError, errstring):
            self.command.handle('arg1', 'arg2')

    def test_invalid_course_id(self):
        """
        Tests for the case when invalid course_id is specified
        """
        errstring = "The course_id is not of the right format."
        with self.assertRaisesRegexp(CommandError, errstring):
            self.command.handle('this_is_not_the_right_format')

    @patch('contentstore.management.commands.update_transcripts.TranscriptS3Store')
    def test_not_found_course_id(self, mock_store_class):
        """
        Tests for the case when non-existing course_id is specified
        """
        errstring = "The specified course does not exist."
        with self.assertRaisesRegexp(CommandError, errstring):
            self.command.handle('does/not/exist')

    @patch('contentstore.management.commands.update_transcripts.TranscriptS3Store')
    def test_when_store_failed_to_connect(self, mock_store_class):
        """
        Tests for the case when S3 connection error raises
        """
        mock_store_class.side_effect = Exception("Failed to connect to S3.")

        errstring = "Could not establish a connection to S3 for transcripts backup."
        with self.assertRaisesRegexp(CommandError, errstring):
            self.command.handle('org/course/name')

        mock_store_class.assert_called_once_with()
 def setUp(self):
     self.command = Command()
Example #4
0
 def setUp(self):
     self.command = Command()