示例#1
0
 def test_validation_signing_warning(self, _mock):
     """If we sign addons, warn on signed addon submission."""
     _mock.return_value = self.mock_sign_addon_warning
     tasks.validate(self.upload)
     validation = json.loads(self.get_upload().validation)
     assert validation["warnings"] == 1
     assert len(validation["messages"]) == 1
示例#2
0
 def test_validation_error(self, _mock):
     _mock.side_effect = Exception
     eq_(self.upload.task_error, None)
     with self.assertRaises(Exception):
         tasks.validate(self.upload)
     error = self.get_upload().task_error
     assert error.startswith('Traceback (most recent call last)'), error
示例#3
0
 def test_validation_no_signing_warning(self, _mock):
     """If we're not signing addon don't warn on signed addon submission."""
     _mock.return_value = self.mock_sign_addon_warning
     tasks.validate(self.upload)
     validation = json.loads(self.get_upload().validation)
     assert validation['warnings'] == 0
     assert len(validation['messages']) == 0
示例#4
0
 def test_validation_no_signing_warning(self, _mock):
     """If we're not signing addon don't warn on signed addon submission."""
     _mock.return_value = self.mock_sign_addon_warning
     tasks.validate(self.upload)
     validation = json.loads(self.get_upload().validation)
     assert validation['warnings'] == 0
     assert len(validation['messages']) == 0
示例#5
0
 def test_validation_error(self, _mock):
     _mock.side_effect = Exception
     eq_(self.upload.task_error, None)
     with self.assertRaises(Exception):
         tasks.validate(self.upload)
     error = self.get_upload().task_error
     assert error.startswith('Traceback (most recent call last)'), error
示例#6
0
 def test_annotate_passed_auto_validation_bogus_result(self, _mock):
     """Don't set passed_auto_validation, don't fail if results is bogus."""
     _mock.return_value = '{"errors": 0}'
     tasks.validate(self.upload)
     assert (json.loads(self.get_upload().validation) ==
             {"passed_auto_validation": True, "errors": 0,
              "signing_summary": {"high": 0, "medium": 0,
                                  "low": 0, "trivial": 0}})
示例#7
0
    def test_annotate_failed_auto_validation(self, _mock):
        """Set passed_auto_validation on reception of the results."""
        result = {"signing_summary": {"trivial": 0, "low": 1, "medium": 0, "high": 0}, "errors": 0}

        _mock.return_value = json.dumps(result)
        tasks.validate(self.upload)
        validation = json.loads(self.get_upload().validation)
        assert not validation["passed_auto_validation"]
示例#8
0
    def test_annotate_failed_auto_validation(self, _mock):
        """Set passed_auto_validation on reception of the results."""
        result = {'signing_summary': {'trivial': 0, 'low': 1, 'medium': 0,
                                      'high': 0},
                  'errors': 0}

        _mock.return_value = json.dumps(result)
        tasks.validate(self.upload)
        validation = json.loads(self.get_upload().validation)
        assert not validation['passed_auto_validation']
示例#9
0
    def test_run_once_file_upload(self, chain):
        """Tests that only a single validation task is run for a given file
        upload."""
        task = mock.Mock()
        chain.return_value = task
        task.delay.return_value = mock.Mock(task_id='42')

        assert isinstance(tasks.validate(self.file_upload), mock.Mock)
        assert task.delay.call_count == 1

        assert isinstance(tasks.validate(self.file_upload), AsyncResult)
        assert task.delay.call_count == 1
示例#10
0
    def test_run_once_file_upload(self, chain):
        """Tests that only a single validation task is run for a given file
        upload."""
        task = mock.Mock()
        chain.return_value = task
        task.delay.return_value = mock.Mock(task_id='42')

        assert isinstance(tasks.validate(self.file_upload), mock.Mock)
        assert task.delay.call_count == 1

        assert isinstance(tasks.validate(self.file_upload), AsyncResult)
        assert task.delay.call_count == 1
示例#11
0
    def test_validation_error(self, _mock):
        _mock.side_effect = Exception

        self.upload.update(path=os.path.join(settings.ROOT, "apps/devhub/tests/addons/desktop.xpi"))

        assert self.upload.validation is None

        tasks.validate(self.upload)
        self.upload.reload()
        validation = self.upload.processed_validation
        assert validation
        assert validation["errors"] == 1
        assert validation["messages"][0]["id"] == ["validator", "unexpected_exception"]
        assert not self.upload.valid
示例#12
0
 def test_annotate_passed_auto_validation_bogus_result(self, _mock):
     """Don't set passed_auto_validation, don't fail if results is bogus."""
     _mock.return_value = '{"errors": 0}'
     tasks.validate(self.upload)
     assert (json.loads(self.get_upload().validation) == {
         "passed_auto_validation": True,
         "errors": 0,
         "signing_summary": {
             "high": 0,
             "medium": 0,
             "low": 0,
             "trivial": 0
         }
     })
示例#13
0
    def test_annotate_failed_auto_validation(self, _mock):
        """Set passed_auto_validation on reception of the results."""
        result = {
            'signing_summary': {
                'trivial': 0,
                'low': 1,
                'medium': 0,
                'high': 0
            },
            'errors': 0
        }

        _mock.return_value = json.dumps(result)
        tasks.validate(self.upload)
        validation = json.loads(self.get_upload().validation)
        assert not validation['passed_auto_validation']
示例#14
0
    def test_annotation_error(self, run_validator, annotate):
        """Test that an error that occurs during annotation is saved as an
        error result."""
        annotate.side_effect = Exception
        run_validator.return_value = '{"errors": 0}'

        assert self.upload.validation is None

        tasks.validate(self.upload)
        self.upload.reload()

        validation = self.upload.processed_validation
        assert validation
        assert validation["errors"] == 1
        assert validation["messages"][0]["id"] == ["validator", "unexpected_exception"]
        assert not self.upload.valid
示例#15
0
    def test_validation_error(self, _mock):
        _mock.side_effect = Exception

        self.upload.update(
            path=os.path.join(ADDON_TEST_FILES, 'desktop.xpi'))

        assert self.upload.validation is None

        tasks.validate(self.upload)
        self.upload.reload()
        validation = self.upload.processed_validation
        assert validation
        assert validation['errors'] == 1
        assert validation['messages'][0]['id'] == ['validator',
                                                   'unexpected_exception']
        assert not self.upload.valid
示例#16
0
    def test_validation_error(self, _mock):
        _mock.side_effect = Exception

        self.upload.update(path=os.path.join(
            settings.ROOT, 'apps/devhub/tests/addons/desktop.xpi'))

        assert self.upload.validation is None

        tasks.validate(self.upload)
        self.upload.reload()
        validation = self.upload.processed_validation
        assert validation
        assert validation['errors'] == 1
        assert validation['messages'][0]['id'] == [
            'validator', 'unexpected_exception'
        ]
        assert not self.upload.valid
示例#17
0
    def test_validation_error(self, _mock):
        _mock.side_effect = Exception

        self.upload.update(
            path=os.path.join(settings.ROOT,
                              'apps/devhub/tests/addons/desktop.xpi'))

        assert self.upload.validation is None

        tasks.validate(self.upload)
        self.upload.reload()
        validation = self.upload.processed_validation
        assert validation
        assert validation['errors'] == 1
        assert validation['messages'][0]['id'] == ['validator',
                                                   'unexpected_exception']
        assert not self.upload.valid
示例#18
0
    def test_annotation_error(self, run_validator, annotate):
        """Test that an error that occurs during annotation is saved as an
        error result."""
        annotate.side_effect = Exception
        run_validator.return_value = '{"errors": 0}'

        assert self.upload.validation is None

        tasks.validate(self.upload)
        self.upload.reload()

        validation = self.upload.processed_validation
        assert validation
        assert validation['errors'] == 1
        assert validation['messages'][0]['id'] == [
            'validator', 'unexpected_exception'
        ]
        assert not self.upload.valid
示例#19
0
 def test_track_validation_stats(self, mock_track, mock_validate):
     mock_validate.return_value = '{"errors": 0}'
     tasks.validate(self.upload)
     mock_track.assert_called_with(mock_validate.return_value)
示例#20
0
 def test_track_validation_stats(self, mock_track, mock_validate):
     mock_validate.return_value = '{"errors": 0}'
     tasks.validate(self.upload)
     mock_track.assert_called_with(mock_validate.return_value)
示例#21
0
 def test_fail_validation(self, _mock):
     _mock.return_value = '{"errors": 2}'
     tasks.validate(self.upload)
     assert not self.get_upload().valid
示例#22
0
 def test_fail_validation(self, _mock):
     _mock.return_value = '{"errors": 2}'
     tasks.validate(self.upload)
     assert not self.get_upload().valid