Ejemplo n.º 1
0
 def test_generate_hash(self, storage_mock):
     f = File()
     f.version = Version()
     # Mock remote storage to use a local file instead of a remote one.
     storage_mock.open = open
     filename = self.packaged_app_path('mozball.zip')
     assert f.generate_hash(filename).startswith('sha256:ad85d6316166d4')
Ejemplo n.º 2
0
 def test_generate_hash(self, storage_mock):
     f = File()
     f.version = Version()
     # Mock remote storage to use a local file instead of a remote one.
     storage_mock.open = open
     filename = self.packaged_app_path('mozball.zip')
     assert f.generate_hash(filename).startswith('sha256:ad85d6316166d4')
Ejemplo n.º 3
0
    def test_file_hash(self):
        upload = self.upload('mozball')
        f = File.from_upload(upload, self.version)
        # Hash should have been stolen from the fileupload.
        eq_(f.hash, 'sha256:mozball.zip')

        upload = self.upload('mozball')
        f = File.from_upload(upload, self.version)
        # Hash should have been stolen from the fileupload again.
        eq_(f.hash, 'sha256:mozball.zip')
Ejemplo n.º 4
0
    def test_file_hash(self):
        upload = self.upload('mozball')
        f = File.from_upload(upload, self.version)
        # Hash should have been stolen from the fileupload.
        eq_(f.hash, 'sha256:mozball.zip')

        upload = self.upload('mozball')
        f = File.from_upload(upload, self.version)
        # Hash should have been stolen from the fileupload again.
        eq_(f.hash, 'sha256:mozball.zip')
Ejemplo n.º 5
0
    def from_upload(cls, upload, addon, platforms, send_signal=True):
        data = utils.parse_addon(upload, addon)
        try:
            license = addon.versions.latest().license_id
        except Version.DoesNotExist:
            license = None
        max_len = cls._meta.get_field_by_name('_developer_name')[0].max_length
        developer = data.get('developer_name', '')[:max_len]
        v = cls.objects.create(addon=addon, version=data['version'],
                               license_id=license, _developer_name=developer)
        log.info('New version: %r (%s) from %r' % (v, v.id, upload))

        platforms = [Platform.objects.get(id=amo.PLATFORM_ALL.id)]

        # To avoid circular import.
        from mkt.webapps.models import AppManifest

        # Note: This must happen before we call `File.from_upload`.
        manifest = utils.WebAppParser().get_json_data(upload)
        AppManifest.objects.create(
            version=v, manifest=json.dumps(manifest))

        for platform in platforms:
            File.from_upload(upload, v, platform, parse_data=data)

        # Update supported locales from manifest.
        # Note: This needs to happen after we call `File.from_upload`.
        update_supported_locales_single.apply_async(
            args=[addon.id], kwargs={'latest': True},
            eta=datetime.datetime.now() +
                datetime.timedelta(seconds=settings.NFS_LAG_DELAY))

        v.disable_old_files()
        # After the upload has been copied to all platforms, remove the upload.
        storage.delete(upload.path)
        if send_signal:
            version_uploaded.send(sender=v)

        # If packaged app and app is blocked, put in escalation queue.
        if addon.is_packaged and addon.status == amo.STATUS_BLOCKED:
            # To avoid circular import.
            from mkt.reviewers.models import EscalationQueue
            EscalationQueue.objects.create(addon=addon)

        return v
Ejemplo n.º 6
0
 def test_file_validation(self):
     upload = self.upload('mozball')
     file = File.from_upload(upload, self.version)
     fv = FileValidation.objects.get(file=file)
     eq_(fv.validation, upload.validation)
     eq_(fv.valid, True)
     eq_(fv.errors, 0)
     eq_(fv.warnings, 1)
     eq_(fv.notices, 2)
Ejemplo n.º 7
0
 def test_file_validation(self):
     upload = self.upload('mozball')
     file = File.from_upload(upload, self.version)
     fv = FileValidation.objects.get(file=file)
     eq_(fv.validation, upload.validation)
     eq_(fv.valid, True)
     eq_(fv.errors, 0)
     eq_(fv.warnings, 1)
     eq_(fv.notices, 2)
Ejemplo n.º 8
0
    def from_upload(cls, upload, webapp, send_signal=True):
        data = utils.parse_webapp(upload, webapp)
        max_len = cls._meta.get_field_by_name('_developer_name')[0].max_length
        developer = data.get('developer_name', '')[:max_len]
        v = cls.objects.create(webapp=webapp, version=data['version'],
                               _developer_name=developer)
        log.info('New version: %r (%s) from %r' % (v, v.id, upload))

        # To avoid circular import.
        from mkt.webapps.models import AppManifest

        # Note: This must happen before we call `File.from_upload`.
        manifest = utils.WebAppParser().get_json_data(upload)
        AppManifest.objects.create(
            version=v, manifest=json.dumps(manifest))

        File.from_upload(upload, v, parse_data=data)

        # Update supported locales from manifest.
        # Note: This needs to happen after we call `File.from_upload`.
        update_supported_locales_single.apply_async(
            args=[webapp.id], kwargs={'latest': True},
            eta=datetime.datetime.now() +
            datetime.timedelta(seconds=settings.NFS_LAG_DELAY)
        )

        v.disable_old_files()
        # After the upload has been copied, remove the upload.
        private_storage.delete(upload.path)
        if send_signal:
            version_uploaded.send(sender=v)

        # If packaged app and app is blocked, put in escalation queue.
        if webapp.is_packaged and webapp.status == mkt.STATUS_BLOCKED:
            # To avoid circular import.
            from mkt.reviewers.models import EscalationQueue
            EscalationQueue.objects.create(webapp=webapp)

        return v
Ejemplo n.º 9
0
    def from_upload(cls, upload, addon, send_signal=True):
        data = utils.parse_addon(upload, addon)
        max_len = cls._meta.get_field_by_name('_developer_name')[0].max_length
        developer = data.get('developer_name', '')[:max_len]
        v = cls.objects.create(addon=addon,
                               version=data['version'],
                               _developer_name=developer)
        log.info('New version: %r (%s) from %r' % (v, v.id, upload))

        # To avoid circular import.
        from mkt.webapps.models import AppManifest

        # Note: This must happen before we call `File.from_upload`.
        manifest = utils.WebAppParser().get_json_data(upload)
        AppManifest.objects.create(version=v, manifest=json.dumps(manifest))

        File.from_upload(upload, v, parse_data=data)

        # Update supported locales from manifest.
        # Note: This needs to happen after we call `File.from_upload`.
        update_supported_locales_single.apply_async(
            args=[addon.id],
            kwargs={'latest': True},
            eta=datetime.datetime.now() +
            datetime.timedelta(seconds=settings.NFS_LAG_DELAY))

        v.disable_old_files()
        # After the upload has been copied, remove the upload.
        storage.delete(upload.path)
        if send_signal:
            version_uploaded.send(sender=v)

        # If packaged app and app is blocked, put in escalation queue.
        if addon.is_packaged and addon.status == mkt.STATUS_BLOCKED:
            # To avoid circular import.
            from mkt.reviewers.models import EscalationQueue
            EscalationQueue.objects.create(addon=addon)

        return v
Ejemplo n.º 10
0
 def test_filename_packaged(self):
     self.addon.is_packaged = True
     upload = self.upload('mozball')
     f = File.from_upload(upload, self.version)
     eq_(f.filename, 'app-name-0.1.zip')
Ejemplo n.º 11
0
 def test_filename_hosted(self):
     upload = self.upload('mozball')
     f = File.from_upload(upload, self.version)
     eq_(f.filename, 'app-name-0.1.webapp')
Ejemplo n.º 12
0
 def test_generate_webapp_fn_partial_non_ascii(self):
     f = File()
     f.version = Version(version='0.1.7')
     f.version.addon = Addon(app_slug=u'myapp フォクすけ  といっしょ',
                             type=amo.ADDON_WEBAPP)
     eq_(f.generate_filename(), 'myapp-0.1.7.webapp')
Ejemplo n.º 13
0
 def test_generate_filename_ja(self):
     f = File()
     f.version = Version(version='0.1.7')
     f.version.addon = Webapp(name=u' フォクすけ  といっしょ')
     eq_(f.generate_filename(), 'none-0.1.7.webapp')
Ejemplo n.º 14
0
 def test_file_hash_paranoia(self):
     upload = self.upload('mozball')
     f = File.from_upload(upload, self.version)
     assert f.hash.startswith('sha256:ad85d6316166d46')
Ejemplo n.º 15
0
 def test_utf8(self):
     upload = self.upload(u'mozball')
     self.version.addon.name = u'mözball'
     f = File.from_upload(upload, self.version)
     eq_(f.filename, u'app-name-0.1.webapp')
Ejemplo n.º 16
0
 def test_filename_packaged(self):
     self.addon.is_packaged = True
     upload = self.upload('mozball')
     f = File.from_upload(upload, self.version)
     eq_(f.filename, 'app-name-0.1.zip')
Ejemplo n.º 17
0
 def test_filename_hosted(self):
     upload = self.upload('mozball')
     f = File.from_upload(upload, self.version)
     eq_(f.filename, 'app-name-0.1.webapp')
Ejemplo n.º 18
0
 def test_file_hash(self):
     upload = self.upload('mozball')
     f = File.from_upload(upload, self.version)
     assert f.hash.startswith('sha256:')
     assert len(f.hash) == 64 + 7  # 64 for hash, 7 for 'sha256:'
Ejemplo n.º 19
0
 def test_utf8(self):
     upload = self.upload(u'mozball')
     self.version.addon.name = u'mözball'
     f = File.from_upload(upload, self.version)
     eq_(f.filename, u'app-name-0.1.webapp')
Ejemplo n.º 20
0
 def test_size(self):
     upload = self.upload('mozball')
     f = File.from_upload(upload, self.version)
     eq_(f.size, 93594)
Ejemplo n.º 21
0
 def test_size(self):
     upload = self.upload('mozball')
     f = File.from_upload(upload, self.version)
     eq_(f.size, 93594)
Ejemplo n.º 22
0
 def test_generate_webapp_fn_partial_non_ascii(self):
     f = File()
     f.version = Version(version='0.1.7')
     f.version.addon = Webapp(app_slug=u'myapp フォクすけ  といっしょ')
     eq_(f.generate_filename(), 'myapp-0.1.7.webapp')
Ejemplo n.º 23
0
 def test_generate_webapp_fn_partial_non_ascii(self):
     f = File()
     f.version = Version(version='0.1.7')
     f.version.addon = Webapp(app_slug=u'myapp フォクすけ  といっしょ')
     eq_(f.generate_filename(), 'myapp-0.1.7.webapp')
Ejemplo n.º 24
0
 def test_generate_hash(self):
     f = File()
     f.version = Version.objects.get()
     fn = self.packaged_app_path('mozball.zip')
     assert f.generate_hash(fn).startswith('sha256:ad85d6316166d4')
Ejemplo n.º 25
0
 def test_generate_filename_ja(self):
     f = File()
     f.version = Version(version='0.1.7')
     f.version.addon = Webapp(name=u' フォクすけ  といっしょ')
     eq_(f.generate_filename(), 'none-0.1.7.webapp')