示例#1
0
    def test_args_from_database(self):
        """Test management command arguments injected from config model."""
        # Nothing in the database, should default to disabled

        # pylint: disable=deprecated-method, useless-suppression
        with self.assertRaisesRegex(CommandError,
                                    'SSPVerificationRetryConfig is disabled*'):
            call_command('retry_failed_photo_verifications',
                         '--args-from-database')

        # Add a config
        config = SSPVerificationRetryConfig.current()
        config.arguments = '--verification-ids 1 2 3'
        config.enabled = True
        config.save()

        with patch('lms.djangoapps.verify_student.models.requests.post',
                   new=mock_software_secure_post_error):
            self.create_and_submit("RetryRoger")

            with LogCapture(LOGGER_NAME) as log:
                call_command('retry_failed_photo_verifications')

                log.check_present((
                    LOGGER_NAME, 'INFO',
                    u"Attempting to retry {0} failed PhotoVerification submissions"
                    .format(1)), )

        with LogCapture(LOGGER_NAME) as log:
            call_command('retry_failed_photo_verifications',
                         '--args-from-database')

            log.check_present(
                (LOGGER_NAME, 'INFO',
                 u"Fetching retry verification ids from config model"), )
    def get_args_from_database(self):
        """ Returns an options dictionary from the current SSPVerificationRetryConfig model. """

        sspv_retry_config = SSPVerificationRetryConfig.current()
        if not sspv_retry_config.enabled:
            log.warning('SSPVerificationRetryConfig is disabled or empty, but --args-from-database was requested.')
            return {}

        # We don't need fancy shell-style whitespace/quote handling - none of our arguments are complicated
        argv = sspv_retry_config.arguments.split()

        parser = self.create_parser('manage.py', 'sspv_retry')
        return parser.parse_args(argv).__dict__  # we want a dictionary, not a non-iterable Namespace object
 def add_test_config_for_retry_verification(self):
     """Setups verification retry configuration."""
     config = SSPVerificationRetryConfig.current()
     config.arguments = '--verification-ids 1 2 3'
     config.enabled = True
     config.save()