Exemple #1
0
 def test_escaped_validation_ignores_bad_json(self):
     upload = FileUpload(validation='wtf')
     assert not upload._escaped_validation
     upload.save()
     assert not upload._escaped_validation
     eq_(upload.task_error.strip().split('\n')[-1],
         'ValueError: No JSON object could be decoded')
Exemple #2
0
    def test_limit_validator_errors(self):
        data = {
            "errors":
            100,
            "success":
            True,
            "warnings":
            100,
            "notices":
            0,
            "message_tree": {},
            "messages": [{
                "context": ["<code>", None],
                "description":
                ["Something something, see "
                 "https://bugzilla.mozilla.org/"],
                "column":
                0,
                "line":
                1,
                "file":
                "chrome/content/down.html",
                "tier":
                2,
                "message":
                "Some warning",
                "type":
                "warning",
                "id": [],
                "uid":
                "bb9948b604b111e09dfdc42c0301fe38"
            }, {
                "context": ["<code>", None],
                "description":
                ["Something something, see "
                 "https://bugzilla.mozilla.org/"],
                "column":
                0,
                "line":
                1,
                "file":
                "chrome/content/down.html",
                "tier":
                2,
                "message":
                "Some error",
                "type":
                "error",
                "id": [],
                "uid":
                "bb9948b604b111e09dfdc42c0301fe38"
            }] * 50,
            "metadata": {}
        }
        upload = FileUpload(validation=json.dumps(data))
        validation = upload.processed_validation

        assert len(validation['messages']) == 11
        assert 'truncated' in validation['messages'][0]['message']
        assert validation['messages'][0]['type'] == 'error'
Exemple #3
0
 def test_escaped_validation_will_escape_validation(self):
     upload = FileUpload(validation='{"messages": [{"the": "validation"}]}')
     assert not upload._escaped_validation
     upload.escaped_validation()
     eq_(json.loads(upload._escaped_validation), {
         "ending_tier": 0,
         "messages": [{
             "the": "validation"
         }]
     })
Exemple #4
0
 def upload(self, addon, path):
     """Create FileUpload instance from local file."""
     self.info('Creating FileUpload...')
     package_file = open(path)
     package_size = os.stat(path).st_size
     upload = FileUpload()
     upload.user = addon.authors.all()[0]
     upload.add_file(package_file.read(), 'marketplace-package.zip',
                     package_size, is_webapp=True)
     self.info('Created FileUpload %s.' % upload)
     return upload
Exemple #5
0
    def test_limit_validator_compat_errors(self):
        data = {
            "errors": 0,
            "success": True,
            "warnings": 100,
            "notices": 0,
            "message_tree": {},
            "compatibility_summary": {"errors": 100,
                                      "warnings": 0,
                                      "notices": 0},
            "messages": [
                {
                    "context": ["<code>", None],
                    "description": ["Something something, see "
                                    "https://bugzilla.mozilla.org/"],
                    "column": 0,
                    "line": 1,
                    "file": "chrome/content/down.html",
                    "tier": 2,
                    "message": "Some warning",
                    "type": "warning",
                    "compatibility_type": "warning",
                    "id": [],
                    "uid": "bb9948b604b111e09dfdc42c0301fe38"
                },
                {
                    "context": ["<code>", None],
                    "description": ["Something something, see "
                                    "https://bugzilla.mozilla.org/"],
                    "column": 0,
                    "line": 1,
                    "file": "chrome/content/down.html",
                    "tier": 2,
                    "message": "Some error",
                    "type": "warning",
                    "compatibility_type": "warning",
                    "id": [],
                    "uid": "bb9948b604b111e09dfdc42c0301fe38"
                }
            ] * 50,
            "metadata": {}
        }
        upload = FileUpload(validation=json.dumps(data))
        validation = upload.escaped_validation()
        eq_(len(validation['messages']), 11)
        assert 'truncated' in validation['messages'][-1]['message']
        eq_(validation['messages'][-1]['type'], 'warning')

        validation = upload.escaped_validation(is_compatibility=True)
        eq_(len(validation['messages']), 11)
        assert 'truncated' in validation['messages'][-1]['message']
        eq_(validation['messages'][-1]['type'], 'error')
Exemple #6
0
            chunks = []
            size = 0
            for chunk in req.iter_content(settings.LANGPACK_MAX_SIZE):
                size += len(chunk)
                # `requests` doesn't respect the Content-Length header
                # so we need to check twice.
                if size > settings.LANGPACK_MAX_SIZE:
                    raise Exception('Response to big')
                chunks.append(chunk)
        except Exception, e:
            log.error('[@None] Error fetching "%s" language pack: %s' %
                      (xpi, e))
            continue

        upload = FileUpload()
        upload.add_file(chunks, xpi, size)

        # Activate the correct locale for the language pack so it
        # will be used as the add-on's default locale if available.
        translation.activate(lang)

        guid = '*****@*****.**' % lang

        try:
            addon = Addon.objects.get(guid=guid)
        except Addon.DoesNotExist:
            addon = None

        try:
            data = parse_addon(upload, addon)
Exemple #7
0
def test_file_upload_passed_all_validations_invalid():
    upload = FileUpload(valid=False,
                        validation=json.dumps(amo.VALIDATOR_SKELETON_RESULTS))
    assert not upload.passed_all_validations
Exemple #8
0
def test_file_upload_passed_all_validations_processing():
    upload = FileUpload(valid=False, validation='')
    assert not upload.passed_all_validations
Exemple #9
0
def test_file_upload_passed_auto_validation_failed():
    upload = FileUpload(validation=json.dumps({
        'passed_auto_validation': False,
    }))
    assert not upload.passed_auto_validation
Exemple #10
0
def test_file_upload_passed_auto_validation_passed():
    upload = FileUpload(validation=json.dumps({
        'passed_auto_validation': True,
    }))
    assert upload.passed_auto_validation