Beispiel #1
0
    def create_blocklisted_version(self):
        """
        Creates a new version who's file is the blocklisted app found in /media
        and sets status to STATUS_BLOCKLISTED.

        """
        blocklisted_path = os.path.join(settings.MEDIA_ROOT, 'packaged-apps',
                                        'blocklisted.zip')
        last_version = self.current_version.version
        v = Version.objects.create(
            addon=self, version='blocklisted-%s' % last_version)
        f = File(version=v, status=amo.STATUS_BLOCKED,
                 platform=Platform.objects.get(id=amo.PLATFORM_ALL.id))
        f.filename = f.generate_filename()
        copy_stored_file(blocklisted_path, f.file_path)
        log.info(u'[Webapp:%s] Copied blocklisted app from %s to %s' % (
            self.id, blocklisted_path, f.file_path))
        f.size = storage.size(f.file_path)
        f.hash = f.generate_hash(f.file_path)
        f.save()
        f.inject_ids()
        self.sign_if_packaged(v.pk)
        self.status = amo.STATUS_BLOCKED
        self._current_version = v
        self.save()
Beispiel #2
0
 def test_version_is_not_allowed_upload_full(self):
     version = Version.objects.get(pk=81551)
     version.files.all().delete()
     for platform in [amo.PLATFORM_LINUX.id, amo.PLATFORM_WIN.id, amo.PLATFORM_MAC.id]:
         file = File(platform_id=platform, version=version)
         file.save()
     assert not version.is_allowed_upload()
Beispiel #3
0
 def test_generate_webapp_fn_partial_non_ascii(self):
     f = File()
     f.version = Version(version='0.1.7')
     f.version.compatible_apps = (amo.FIREFOX,)
     f.version.addon = Addon(app_slug=u'myapp フォクすけ  といっしょ',
                             type=amo.ADDON_WEBAPP)
     eq_(f.generate_filename(), 'myapp-0.1.7.webapp')
Beispiel #4
0
    def from_upload(cls, upload, addon, platforms):
        data = utils.parse_addon(upload.path, addon)
        try:
            license = addon.versions.latest().license_id
        except Version.DoesNotExist:
            license = None
        v = cls.objects.create(addon=addon, version=data['version'],
                               license_id=license)
        log.info('New version: %r (%s) from %r' % (v, v.id, upload))
        # appversions
        AV = ApplicationsVersions
        for app in data.get('apps', []):
            AV(version=v, min=app.min, max=app.max,
               application_id=app.id).save()
        if addon.type == amo.ADDON_SEARCH:
            # Search extensions are always for all platforms.
            platforms = [Platform.objects.get(id=amo.PLATFORM_ALL.id)]
        else:
            platforms = cls._make_safe_platform_files(platforms)

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

        v.disable_old_files()
        # After the upload has been copied to all
        # platforms, remove the upload.
        upload.path.unlink()
        version_uploaded.send(sender=v)
        return v
Beispiel #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))

        AV = ApplicationsVersions
        for app in data.get('apps', []):
            AV(version=v, min=app.min, max=app.max,
               application_id=app.id).save()
        if addon.type == amo.ADDON_SEARCH:
            # Search extensions are always for all platforms.
            platforms = [Platform.objects.get(id=amo.PLATFORM_ALL.id)]
        else:
            platforms = cls._make_safe_platform_files(platforms)

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

        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)

        return v
Beispiel #6
0
 def test_generate_filename_ja(self):
     f = File()
     f.version = Version(version='0.1.7')
     f.version.compatible_apps = (amo.FIREFOX,)
     f.version.addon = Addon(name=u' フォクすけといっしょ')
     eq_(f.generate_filename(),
         u'\u30d5\u30a9\u30af\u3059\u3051\u3068\u3044\u3063\u3057\u3087'
         '-0.1.7-fx.xpi')
Beispiel #7
0
    def _extra_version_and_file(self, status):
        version = Version.objects.get(id=81551)

        version_two = Version(addon=self.addon, license=version.license, version="1.2.3")
        version_two.save()

        file_two = File(status=status, version=version_two)
        file_two.save()
        return version_two, file_two
Beispiel #8
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))

        AV = ApplicationsVersions
        for app in data.get('apps', []):
            AV(version=v, min=app.min, max=app.max,
               application_id=app.id).save()
        if addon.type in [amo.ADDON_SEARCH, amo.ADDON_WEBAPP]:
            # Search extensions and webapps are always for all platforms.
            platforms = [Platform.objects.get(id=amo.PLATFORM_ALL.id)]
        else:
            platforms = cls._make_safe_platform_files(platforms)

        if addon.is_webapp():
            from mkt.webapps.models import AppManifest

            # Create AppManifest if we're a Webapp.
            # 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)

        if addon.is_webapp():
            # 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_webapp() and addon.is_packaged and
            addon.status == amo.STATUS_BLOCKED):
            # To avoid circular import.
            from editors.models import EscalationQueue
            EscalationQueue.objects.create(addon=addon)

        return v
Beispiel #9
0
    def create_file(self, **kwargs):
        addon = Addon()
        addon.save()
        ver = Version(version='0.1')
        ver.addon = addon
        ver.save()

        f = File(**kwargs)
        f.version = ver
        f.save()

        return f
Beispiel #10
0
    def from_upload(cls, upload, addon, platforms, send_signal=True,
                    source=None, is_beta=False):
        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,
            source=source
        )
        log.info('New version: %r (%s) from %r' % (v, v.id, upload))

        AV = ApplicationsVersions
        for app in data.get('apps', []):
            AV(version=v, min=app.min, max=app.max,
               application=app.id).save()
        if addon.type == amo.ADDON_SEARCH:
            # Search extensions are always for all platforms.
            platforms = [amo.PLATFORM_ALL.id]
        else:
            platforms = cls._make_safe_platform_files(platforms)

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

        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)

        # Track the time it took from first upload through validation
        # (and whatever else) until a version was created.
        upload_start = utc_millesecs_from_epoch(upload.created)
        now = datetime.datetime.now()
        now_ts = utc_millesecs_from_epoch(now)
        upload_time = now_ts - upload_start

        log.info('Time for version {version} creation from upload: {delta}; '
                 'created={created}; now={now}'
                 .format(delta=upload_time, version=v,
                         created=upload.created, now=now))
        statsd.timing('devhub.version_created_from_upload', upload_time)

        return v
Beispiel #11
0
 def test_public_to_beta(self):
     upload = self.upload('beta-extension')
     data = parse_addon(upload.path)
     self.addon.update(status=amo.STATUS_PUBLIC)
     eq_(self.addon.status, amo.STATUS_PUBLIC)
     f = File.from_upload(upload, self.version, self.platform, data)
     eq_(f.status, amo.STATUS_BETA)
Beispiel #12
0
 def test_trusted_lite_to_lite(self):
     upload = self.upload('extension')
     data = parse_addon(upload.path)
     self.addon.update(status=amo.STATUS_LITE, trusted=True)
     eq_(self.addon.status, amo.STATUS_LITE)
     f = File.from_upload(upload, self.version, self.platform, data)
     eq_(f.status, amo.STATUS_LITE)
Beispiel #13
0
 def test_trusted_public_to_public(self):
     upload = self.upload('extension')
     d = parse_addon(upload.path)
     self.addon.update(status=amo.STATUS_PUBLIC, trusted=True)
     eq_(self.addon.status, amo.STATUS_PUBLIC)
     f = File.from_upload(upload, self.version, self.platform, parse_data=d)
     eq_(f.status, amo.STATUS_PUBLIC)
Beispiel #14
0
 def test_public_to_unreviewed(self):
     upload = self.upload('extension')
     d = parse_addon(upload.path)
     self.addon.update(status=amo.STATUS_PUBLIC)
     eq_(self.addon.status, amo.STATUS_PUBLIC)
     f = File.from_upload(upload, self.version, self.platform, parse_data=d)
     eq_(f.status, amo.STATUS_UNREVIEWED)
Beispiel #15
0
 def test_lite_to_unreviewed(self):
     upload = self.upload('extension')
     data = parse_addon(upload.path)
     self.addon.update(status=amo.STATUS_LITE)
     eq_(self.addon.status, amo.STATUS_LITE)
     f = File.from_upload(upload, self.version, self.platform, data)
     eq_(f.status, amo.STATUS_UNREVIEWED)
Beispiel #16
0
    def setUp(self):
        self.create_switch(name='allow-packaged-app-uploads')
        self.app = Webapp.objects.get(pk=337141)
        self.app.update(is_packaged=True, status=amo.WEBAPPS_UNREVIEWED_STATUS)
        self.dev = self.app.authors.all()[0]
        self.regular = UserProfile.objects.get(pk=999)
        self.version = self.app.versions.latest()
        self.file = self.version.all_files[0]

        self.file_two = File()
        self.file_two.version = self.version
        self.file_two.filename = 'webapp.zip'
        self.file_two.save()

        self.login_as_editor()

        for file_obj in [self.file, self.file_two]:
            src = os.path.join(settings.ROOT, packaged_app)
            try:
                os.makedirs(os.path.dirname(file_obj.file_path))
            except OSError:
                pass
            shutil.copyfile(src, file_obj.file_path)

        self.file_viewer = FileViewer(self.file, is_webapp=True)
        # Setting this to True, so we are delaying the extraction of files,
        # in the tests, the files won't be extracted.
        # Most of these tests extract as needed to.
        self.create_switch(name='delay-file-viewer')
Beispiel #17
0
def run_task(request):
    if request.method == 'GET':
        print(request.GET)
        if 'action' in request.GET:
            action = request.GET['action']
            file_id  = request.GET['file_id']

            file = File.get_object_or_404(pk=file_id)
            if action == "check":
                
                task_manifest = {}
                task_manifest['file'] = file.id
                task_manifest['action'] = action
                task = Task(user=request.user)
                
                task.manifest = task_manifest
                task.status = 'new'
                task.action = action
                task.user = request.user
                task.save()

                check_file.delay(task.id)

                file.status = 'scheduled'
                file.save()
            
    return redirect('files-index')
Beispiel #18
0
 def test_jetpack_with_invalid_json(self):
     upload = self.upload('jetpack_invalid')
     f = File.from_upload(upload, self.version, self.platform)
     file_ = File.objects.get(id=f.id)
     eq_(file_.jetpack_version, None)
     eq_(file_.builder_version, None)
     assert not self.addon.tags.exists()
Beispiel #19
0
 def test_beta_version_non_public(self):
     # Only public add-ons can get beta versions.
     upload = self.upload('beta-extension')
     data = parse_addon(upload.path)
     self.addon.update(status=amo.STATUS_LITE)
     f = File.from_upload(upload, self.version, self.platform, data)
     eq_(f.status, amo.STATUS_UNREVIEWED)
Beispiel #20
0
 def test_jetpack_version(self):
     upload = self.upload('jetpack')
     f = File.from_upload(upload, self.version, self.platform)
     file_ = File.objects.get(id=f.id)
     eq_(file_.jetpack_version, '1.0b4')
     eq_(file_.builder_version, None)
     eq_(['jetpack'], [t.tag_text for t in self.addon.tags.all()])
Beispiel #21
0
    def setUp(self):
        self.addon = Addon.objects.get(pk=3615)
        self.dev = self.addon.authors.all()[0]
        self.regular = UserProfile.objects.get(pk=999)
        self.version = self.addon.versions.latest()
        self.file = self.version.all_files[0]

        self.file_two = File()
        self.file_two.version = self.version
        self.file_two.filename = 'dictionary-test.xpi'
        self.file_two.save()

        self.login_as_editor()

        self.old_tmp = settings.TMP_PATH
        self.old_addon = settings.ADDONS_PATH
        settings.TMP_PATH = tempfile.mkdtemp()
        settings.ADDONS_PATH = tempfile.mkdtemp()

        for file_obj in [self.file, self.file_two]:
            src = os.path.join(settings.ROOT, dictionary)
            try:
                os.makedirs(os.path.dirname(file_obj.file_path))
            except OSError:
                pass
            shutil.copyfile(src, file_obj.file_path)

        self.file_viewer = FileViewer(self.file)
        # Setting this to True, so we are delaying the extraction of files,
        # in the tests, the files won't be extracted.
        # Most of these tests extract as needed to.
        Switch.objects.create(name='delay-file-viewer', active=True)
Beispiel #22
0
    def setUp(self):
        self.addon = Addon.objects.get(pk=3615)
        self.dev = self.addon.authors.all()[0]
        self.regular = UserProfile.objects.get(pk=999)
        self.version = self.addon.versions.latest()
        self.file = self.version.all_files[0]

        self.file_two = File()
        self.file_two.version = self.version
        self.file_two.filename = 'dictionary-test.xpi'
        self.file_two.save()

        self.login_as_editor()

        self.old_tmp = settings.TMP_PATH
        self.old_addon = settings.ADDONS_PATH
        settings.TMP_PATH = tempfile.mkdtemp()
        settings.ADDONS_PATH = tempfile.mkdtemp()

        dictionary = 'apps/files/fixtures/files/dictionary-test.xpi'
        for file_obj in [self.file, self.file_two]:
            src = os.path.join(settings.ROOT, dictionary)
            try:
                os.makedirs(os.path.dirname(file_obj.file_path))
            except OSError:
                pass
            shutil.copyfile(src, file_obj.file_path)

        self.file_viewer = FileViewer(self.file)
Beispiel #23
0
    def _save_file(self, version):
        data = self.cleaned_data
        xpi = data["xpi"]
        hash = hashlib.sha256()

        f = File(version=version, platform_id=amo.PLATFORM_DICT[data["platform"]].id, size=xpi.size)

        filename = f.generate_filename()
        path = os.path.join(user_media_path("addons"), str(version.addon.id))
        with storage.open(os.path.join(path, filename), "wb") as destination:
            for chunk in xpi.chunks():
                hash.update(chunk)
                destination.write(chunk)

        f.hash = "sha256:%s" % hash.hexdigest()
        f.save()
        return f
Beispiel #24
0
 def test_litenominated_to_unreviewed(self):
     upload = self.upload('extension')
     data = parse_addon(upload.path)
     with mock.patch('addons.models.Addon.update_status'):
         # mock update_status because it doesn't like Addons without files.
         self.addon.update(status=amo.STATUS_LITE_AND_NOMINATED)
     eq_(self.addon.status, amo.STATUS_LITE_AND_NOMINATED)
     f = File.from_upload(upload, self.version, self.platform, data)
     eq_(f.status, amo.STATUS_UNREVIEWED)
Beispiel #25
0
 def test_file_validation(self):
     upload = self.upload('jetpack')
     file = File.from_upload(upload, self.version, self.platform)
     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)
Beispiel #26
0
 def test_trusted_litenominated_to_litenominated(self):
     upload = self.upload("extension")
     data = parse_addon(upload.path)
     with mock.patch("addons.models.Addon.update_status"):
         # mock update_status because it doesn't like Addons without files.
         self.addon.update(status=amo.STATUS_LITE_AND_NOMINATED, trusted=True)
     eq_(self.addon.status, amo.STATUS_LITE_AND_NOMINATED)
     f = File.from_upload(upload, self.version, self.platform, data)
     eq_(f.status, amo.STATUS_LITE_AND_NOMINATED)
Beispiel #27
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
        v = cls.objects.create(addon=addon, version=data['version'],
                               license_id=license)
        log.info('New version: %r (%s) from %r' % (v, v.id, upload))
        # appversions
        AV = ApplicationsVersions
        for app in data.get('apps', []):
            AV(version=v, min=app.min, max=app.max,
               application_id=app.id).save()
        if addon.type in [amo.ADDON_SEARCH, amo.ADDON_WEBAPP]:
            # Search extensions and webapps are always for all platforms.
            platforms = [Platform.objects.get(id=amo.PLATFORM_ALL.id)]
        else:
            platforms = cls._make_safe_platform_files(platforms)

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

        if addon.type == amo.ADDON_WEBAPP:
            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_webapp() and addon.is_packaged and
            addon.status == amo.STATUS_BLOCKED):
            # To avoid circular import.
            from editors.models import EscalationQueue
            EscalationQueue.objects.create(addon=addon)

        return v
Beispiel #28
0
    def _save_file(self, version):
        data = self.cleaned_data
        xpi = data['xpi']
        hash = hashlib.sha256()

        f = File(version=version,
                 platform_id=amo.PLATFORM_DICT[data['platform']].id,
                 size=xpi.size)

        filename = f.generate_filename()
        path = os.path.join(settings.ADDONS_PATH, str(version.addon.id))
        with storage.open(os.path.join(path, filename), 'wb') as destination:
            for chunk in xpi.chunks():
                hash.update(chunk)
                destination.write(chunk)

        f.hash = 'sha256:%s' % hash.hexdigest()
        f.save()
        return f
Beispiel #29
0
    def test_trusted_litenominated_to_litenominated(self):
        upload = self.upload('extension')
        d = parse_addon(upload.path)
        with mock.patch('addons.models.Addon.update_status'):
            # mock update_status because it doesn't like Addons without files.
            self.addon.update(status=amo.STATUS_LITE_AND_NOMINATED,
                              trusted=True)

        assert self.addon.status == amo.STATUS_LITE_AND_NOMINATED
        f = File.from_upload(upload, self.version, self.platform, parse_data=d)
        assert f.status == amo.STATUS_LITE
Beispiel #30
0
    def test_file_for_platform(self):
        """If client passes a platform, make sure we get the right file."""
        version = Version.objects.get(pk=self.version_1_2_2)
        file_one = version.files.all()[0]
        file_one.platform_id = amo.PLATFORM_LINUX.id
        file_one.save()

        file_two = File(version=version, filename='foo', hash='bar',
                        platform_id=amo.PLATFORM_WIN.id,
                        status=amo.STATUS_PUBLIC)
        file_two.save()
        version, file = self.get('1.2', self.version_int,
                                 self.app, amo.PLATFORM_LINUX)
        eq_(version, self.version_1_2_2)
        eq_(file, file_one.pk)

        version, file = self.get('1.2', self.version_int,
                                 self.app, amo.PLATFORM_WIN)
        eq_(version, self.version_1_2_2)
        eq_(file, file_two.pk)
Beispiel #31
0
 def test_filename(self):
     upload = self.upload('jetpack')
     f = File.from_upload(upload, self.version, self.platform)
     eq_(f.filename, 'xxx-0.1-mac.xpi')
Beispiel #32
0
 def test_file_hash_paranoia(self):
     upload = self.upload('mozball')
     f = File.from_upload(upload, self.version, self.platform)
     assert f.hash.startswith('sha256:ad85d6316166d46')
Beispiel #33
0
 def test_generate_filename_ja(self):
     f = File()
     f.version = Version(version='0.1.7')
     f.version.addon = Addon(name=u' フォクすけ  といっしょ')
     eq_(f.generate_filename(), 'none-0.1.7.webapp')
Beispiel #34
0
 def test_utf8(self):
     upload = self.upload(u'jétpack')
     self.version.addon.name = u'jéts!'
     f = File.from_upload(upload, self.version, self.platform)
     eq_(f.filename, u'jets-0.1-mac.xpi')
Beispiel #35
0
class TestUrls(TestCase):
    def setUp(self):
        # create user
        self.username = '******'
        self.email = '*****@*****.**'
        self.password = '******'
        self.user = User(username=self.username, email=self.email)
        self.user.set_password(self.password)
        self.user.save()
        login = self.client.login(username=self.username,
                                  password=self.password)
        self.assertEqual(login, True)

        # create category
        self.category = Course.objects.create(course_id='1', course_name='OOP')

        # create degree
        self.software_eng_degree = Degree.objects.create(
            degree_id='1', degree_name='Software Engineering')

        self.social_worker_degree = Degree.objects.create(
            degree_id='2', degree_name='Social Worker')

        # upload file
        f = SimpleUploadedFile('test.pdf', b'test context')

        # create file model object
        self.file1 = File(
            category=self.category,
            create_at=timezone.now,
            file_url=f,
            owner=self.user,
        )
        try:
            self.file1.save()
        except FileExistsError as e:
            print(e)
        self.file1.related_degrees.add(self.software_eng_degree)
        self.file1.related_degrees.add(self.social_worker_degree)

    def test_add_new_file_view(self):
        response = self.client.post(reverse('files:add_file'))
        self.assertEqual(response.status_code, 200)

    def test_list_files_view(self):
        response = self.client.post(reverse('files:show_files'))
        self.assertEqual(response.status_code, 200)

    def test_category_flow_view(self):
        category_name = self.category
        self.assertTrue(category_name, self.file1.category)

    def test_download_file_view(self):
        file_id = self.file1.id
        response = self.client.post(
            reverse('files:download_file', args=(file_id, )))
        self.assertEqual(response.status_code, 200)

    def test_show_files_view(self):
        response = self.client.post(reverse('files:show_files'))
        self.assertEqual(response.status_code, 200)

    def test_fle_view(self):
        self.assertEqual(self.software_eng_degree.degree_name,
                         str(self.file1.related_degrees.all()[0]))
        self.assertEqual(self.social_worker_degree.degree_name,
                         str(self.file1.related_degrees.all()[1]))

    def test_show_files_after_delete_view(self):
        response = self.client.post(reverse('files:show_files'))
        self.assertEqual(response.status_code, 200)

    def tearDown(self):
        try:
            os.remove(self.file1.file_url.path)
        except FileNotFoundError as e:
            print(e)
Beispiel #36
0
 def test_strict_compat(self):
     upload = self.upload('strict-compat')
     data = parse_addon(upload.path)
     f = File.from_upload(upload, self.version, self.platform, data)
     eq_(f.strict_compatibility, True)
Beispiel #37
0
def upload_file(request):
    if request.method == 'POST':
        form = FlieForm(request.POST, request.FILES)
        if form.is_valid():
            obj = File()
            f = request.FILES['FileField']
            cover = request.FILES['cover']
            handle_uploaded_file(f)
            handle_uploaded_file_cover(cover)
            obj.title = form.cleaned_data['title']
            obj.category = form.cleaned_data['category']
            obj.introduction = form.cleaned_data['introduction']
            obj.developer = form.cleaned_data['developer']
            obj.tag = form.cleaned_data['tag']
            obj.support_system = form.cleaned_data['support_system']
            obj.language = form.cleaned_data['language']
            obj.version = form.cleaned_data['version']
            obj.author = request.user.username
            obj.FileField = f
            obj.cover = cover
            obj.size = f.size / (1024**2)
            obj.unique_name = f.name
            obj.save()
            predata = list(File.objects.all())
            data_processing(predata, obj)
            return HttpResponseRedirect('/upload/success/')
        else:
            form = FlieForm()
            return render_to_response(
                'upload.html',
                RequestContext(request, {
                    'errors': u'请正确填写',
                    'form': form
                }))

    else:
        form = FlieForm()
        return render(request, 'upload.html', locals())
Beispiel #38
0
 def test_search_extension(self):
     upload = self.upload('search.xml')
     f = File.from_upload(upload, self.version, self.platform)
     eq_(f.filename.endswith('.xml'), True)
Beispiel #39
0
 def test_extension_extension(self):
     upload = self.upload('extension.xpi')
     f = File.from_upload(upload, self.version, self.platform)
     eq_(f.filename.endswith('.xpi'), True)
     assert not self.addon.tags.exists()
Beispiel #40
0
 def test_jetpack_with_invalid_json(self):
     upload = self.upload('jetpack_invalid')
     f = File.from_upload(upload, self.version, self.platform)
     file_ = File.objects.get(id=f.id)
     eq_(file_.jetpack_version, None)
     eq_(file_.builder_version, None)
Beispiel #41
0
 def test_jetpack_builder_version(self):
     upload = self.upload('jetpack_builder')
     f = File.from_upload(upload, self.version, self.platform)
     file_ = File.objects.get(id=f.id)
     eq_(file_.builder_version, '1.1.1.1')
Beispiel #42
0
 def test_generate_hash(self):
     f = File()
     f.version = Version.objects.get(pk=81551)
     fn = self.xpi_path('delicious_bookmarks-2.1.106-fx')
     assert f.generate_hash(fn).startswith('sha256:fd277d45ab44f6240e')
Beispiel #43
0
 def test_generate_filename_ja(self):
     f = File()
     f.version = Version(version='0.1.7')
     f.version.compatible_apps = (amo.FIREFOX, )
     f.version.addon = Addon(name=u' フォクすけ  といっしょ')
     eq_(f.generate_filename(), 'addon-0.1.7-fx.xpi')
Beispiel #44
0
 def test_size(self):
     upload = self.upload('mozball')
     f = File.from_upload(upload, self.version, self.platform)
     eq_(f.size, 93594)
Beispiel #45
0
 def test_langpack_extension(self):
     upload = self.upload('langpack.xpi')
     f = File.from_upload(upload, self.version, self.platform)
     eq_(f.filename.endswith('.xpi'), True)
Beispiel #46
0
 def test_filename_no_extension(self):
     upload = self.upload('jetpack')
     # Remove the exension.
     upload.name = upload.name.rsplit('.', 1)[0]
     f = File.from_upload(upload, self.version, self.platform)
     eq_(f.filename, 'xxx-0.1-mac.xpi')
Beispiel #47
0
 def test_theme_extension(self):
     upload = self.upload('theme.jar')
     f = File.from_upload(upload, self.version, self.platform)
     eq_(f.filename.endswith('.xpi'), True)
Beispiel #48
0
 def test_file_hash_paranoia(self):
     upload = self.upload('extension')
     f = File.from_upload(upload, self.version, self.platform)
     assert f.hash.startswith('sha256:035ae07b4988711')
Beispiel #49
0
 def test_file_hash(self):
     upload = self.upload('jetpack')
     f = File.from_upload(upload, self.version, self.platform)
     eq_(f.hash, upload.hash)
Beispiel #50
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')
Beispiel #51
0
 def test_size_small(self):
     upload = self.upload('alt-rdf')
     f = File.from_upload(upload, self.version, self.platform)
     eq_(f.size, 675)
Beispiel #52
0
 def test_no_restart_true(self):
     upload = self.upload('jetpack')
     d = parse_addon(upload.path)
     f = File.from_upload(upload, self.version, self.platform, parse_data=d)
     assert f.no_restart
Beispiel #53
0
 def test_size(self):
     upload = self.upload('extension')
     f = File.from_upload(upload, self.version, self.platform)
     eq_(f.size, 2264)
Beispiel #54
0
 def test_utf8(self):
     upload = self.upload(u'mozball')
     self.version.addon.name = u'mözball'
     f = File.from_upload(upload, self.version, self.platform)
     eq_(f.filename, u'app-name-0.1.webapp')
Beispiel #55
0
 def test_no_restart_false(self):
     upload = self.upload('extension')
     d = parse_addon(upload.path)
     f = File.from_upload(upload, self.version, self.platform, parse_data=d)
     assert not f.no_restart
Beispiel #56
0
 def test_file_hash(self):
     upload = self.upload('mozball')
     f = File.from_upload(upload, self.version, self.platform)
     assert f.hash.startswith('sha256:')
     assert len(f.hash) == 64 + 7  # 64 for hash, 7 for 'sha256:'
Beispiel #57
0
 def test_no_restart_dictionary(self):
     upload = self.upload('dictionary-explicit-type-test')
     d = parse_addon(upload.path)
     f = File.from_upload(upload, self.version, self.platform, parse_data=d)
     assert f.no_restart
Beispiel #58
0
 def test_filename_packaged(self):
     self.addon.is_packaged = True
     upload = self.upload('mozball')
     f = File.from_upload(upload, self.version, self.platform)
     eq_(f.filename, 'app-name-0.1.zip')
Beispiel #59
0
 def test_filename_hosted(self):
     upload = self.upload('mozball')
     f = File.from_upload(upload, self.version, self.platform)
     eq_(f.filename, 'app-name-0.1.webapp')
Beispiel #60
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')