예제 #1
0
 def fake_file_object(self, obj, data):
     file_ = File(id=data['id'],
                  created=self.handle_date(data['created']),
                  hash=data['hash'],
                  filename=data['filename'],
                  is_webextension=data.get('is_webextension'),
                  is_mozilla_signed_extension=data.get(
                      'is_mozilla_signed_extension'),
                  is_restart_required=data.get('is_restart_required',
                                               False),
                  platform=data['platform'],
                  size=data['size'],
                  status=data['status'],
                  strict_compatibility=data.get('strict_compatibility',
                                                False),
                  version=obj)
     file_.webext_permissions_list = data.get('webext_permissions_list', [])
     return file_
예제 #2
0
 def fake_file_object(self, obj, data):
     file_ = File(
         id=data['id'],
         created=self.handle_date(data['created']),
         hash=data['hash'],
         filename=data['filename'],
         is_webextension=True,
         is_mozilla_signed_extension=data.get('is_mozilla_signed_extension'),
         size=data['size'],
         status=data['status'],
         strict_compatibility=data.get('strict_compatibility', False),
         version=obj,
     )
     file_.permissions = data.get(
         'permissions', data.get('webext_permissions_list', [])
     )
     file_.optional_permissions = data.get('optional_permissions', [])
     return file_
예제 #3
0
    def test_is_ready_for_auto_approval_addon_status(self):
        addon = Addon.objects.get(id=3615)
        addon.status = amo.STATUS_NOMINATED
        version = addon.current_version
        version.all_files = [
            File(status=amo.STATUS_AWAITING_REVIEW, is_webextension=True)
        ]
        assert not version.is_ready_for_auto_approval

        with override_switch('post-review', active=True):
            # When the post-review switch is active, we also accept add-ons
            # with NOMINATED status.
            assert version.is_ready_for_auto_approval

            addon.status = amo.STATUS_NOMINATED
            assert version.is_ready_for_auto_approval

            addon.status = amo.STATUS_DISABLED
            assert not version.is_ready_for_auto_approval
예제 #4
0
    def _save_file(self, version):
        data = self.cleaned_data
        xpi = data['xpi']
        hash = hashlib.sha256()

        f = File(version=version,
                 platform=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
예제 #5
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 = amo.PLATFORM_LINUX.id
        file_one.save()

        file_two = File(version=version, filename='foo', hash='bar',
                        platform=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)
        assert version == self.version_1_2_2
        assert file == file_one.pk

        version, file = self.get('1.2', self.version_int,
                                 self.app, amo.PLATFORM_WIN)
        assert version == self.version_1_2_2
        assert file == file_two.pk
예제 #6
0
    def fake_object(self, data):
        """Create a fake instance of Addon and related models from ES data."""
        obj = Addon(id=data['id'], slug=data['slug'], is_listed=True)

        data_version = data.get('current_version')
        if data_version:
            obj._current_version = Version(addon=obj,
                                           id=data_version['id'],
                                           reviewed=self.handle_date(
                                               data_version['reviewed']),
                                           version=data_version['version'])
            data_files = data_version.get('files', [])
            obj._current_version.all_files = [
                File(id=file_['id'],
                     created=self.handle_date(file_['created']),
                     hash=file_['hash'],
                     filename=file_['filename'],
                     size=file_['size'],
                     status=file_['status'],
                     version=obj._current_version) for file_ in data_files
            ]

        # Attach base attributes that have the same name/format in ES and in
        # the model.
        self._attach_fields(
            obj, data,
            ('average_daily_users', 'bayesian_rating', 'created',
             'default_locale', 'guid', 'hotness', 'is_listed', 'last_updated',
             'public_stats', 'slug', 'status', 'type', 'weekly_downloads'))

        # Attach attributes that do not have the same name/format in ES.
        obj.tag_list = data['tags']
        obj.disabled_by_user = data['is_disabled']  # Not accurate, but enough.

        # Attach translations (they require special treatment).
        self._attach_translations(obj, data, self.translated_fields)

        return obj
예제 #7
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')
예제 #8
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' フォクすけ  といっしょ')
     assert f.generate_filename() == 'addon-0.1.7-fx.xpi'
예제 #9
0
 def test_has_been_validated_returns_true_when_validation_exists(self):
     file = File(validation=FileValidation())
     assert file.has_been_validated
예제 #10
0
 def test_has_been_validated_returns_false_when_no_validation(self):
     file = File()
     assert not file.has_been_validated
예제 #11
0
    def fake_object(self, data):
        """Create a fake instance of Addon and related models from ES data."""
        obj = Addon(id=data['id'], slug=data['slug'], is_listed=True)

        # Attach base attributes that have the same name/format in ES and in
        # the model.
        self._attach_fields(
            obj, data,
            ('average_daily_users', 'bayesian_rating', 'created',
             'default_locale', 'guid', 'hotness', 'icon_type', 'is_listed',
             'last_updated', 'modified', 'public_stats', 'slug', 'status',
             'type', 'weekly_downloads'))

        # Temporary hack to make sure all add-ons have a modified date when
        # serializing, to avoid errors when calling get_icon_url().
        # Remove once all add-ons have been reindexed at least once since the
        # addition of `modified` in the mapping.
        if obj.modified is None:
            obj.modified = obj.created

        # Attach attributes that do not have the same name/format in ES.
        obj.tag_list = data['tags']
        obj.disabled_by_user = data['is_disabled']  # Not accurate, but enough.

        # Categories are annoying, skip them for now. We probably need to start
        # declaring them in the code to properly handle translations etc if we
        # want to display them in search results.
        obj.all_categories = []

        # Attach translations (they require special treatment).
        self._attach_translations(obj, data, self.translated_fields)

        # Attach related models (also faking them).
        data_version = data.get('current_version')
        if data_version:
            obj._current_version = Version(addon=obj,
                                           id=data_version['id'],
                                           reviewed=self.handle_date(
                                               data_version['reviewed']),
                                           version=data_version['version'])
            data_files = data_version.get('files', [])
            obj._current_version.all_files = [
                File(id=file_['id'],
                     created=self.handle_date(file_['created']),
                     hash=file_['hash'],
                     filename=file_['filename'],
                     platform=file_['platform'],
                     size=file_['size'],
                     status=file_['status'],
                     version=obj._current_version) for file_ in data_files
            ]

            # In ES we store integers for the appversion info, we need to
            # convert it back to strings.
            compatible_apps = {}
            for app_id, compat_dict in data['appversion'].items():
                app_name = APPS_ALL[int(app_id)]
                compatible_apps[app_name] = ApplicationsVersions(
                    min=AppVersion(version=compat_dict.get('min_human', '')),
                    max=AppVersion(version=compat_dict.get('max_human', '')))

            obj._current_version.compatible_apps = compatible_apps

        if data['type'] == amo.ADDON_PERSONA:
            persona_data = data.get('persona')
            if persona_data:
                obj.persona = Persona(
                    addon=obj,
                    accentcolor=persona_data['accentcolor'],
                    display_username=persona_data['author'],
                    header=persona_data['header'],
                    footer=persona_data['footer'],
                    persona_id=1 if persona_data['is_new'] else None,
                    textcolor=persona_data['textcolor'])
            else:
                # Sadly, https://code.djangoproject.com/ticket/14368 prevents
                # us from setting obj.persona = None. This is fixed in
                # Django 1.9, but in the meantime, work around it by creating
                # a Persona instance with a custom attribute indicating that
                # it should not be used.
                obj.persona = Persona()
                obj.persona._broken = True

        return obj