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
def setUp(self): super(TestCategoriesFeed, self).setUp() self.feed = feeds.CategoriesRss() self.unicode_string = u'Ελληνικά' self.feed.request = mock.Mock() self.feed.request.APP.pretty = self.unicode_string self.addon = Addon(name=self.unicode_string, id=2, type=1, slug='xx') self.addon._current_version = Version(version=u'v%s' % self.unicode_string)
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
def test_version_status(): addon = Addon() version = Version() version.all_files = [ File(status=amo.STATUS_PUBLIC), File(status=amo.STATUS_UNREVIEWED) ] assert u'Fully Reviewed,Awaiting Review' == (helpers.version_status( addon, version)) version.all_files = [File(status=amo.STATUS_UNREVIEWED)] assert u'Awaiting Review' == helpers.version_status(addon, version)
def test_version_status(): addon = Addon() version = Version() version.all_files = [ File(status=amo.STATUS_PUBLIC), File(status=amo.STATUS_AWAITING_REVIEW) ] assert u'Approved,Awaiting Review' == (jinja_helpers.version_status( addon, version)) version.all_files = [File(status=amo.STATUS_AWAITING_REVIEW)] assert u'Awaiting Review' == jinja_helpers.version_status(addon, version)
def setUp(self): super(TestCategoriesFeed, self).setUp() self.feed = feeds.CategoriesRss() self.u = u'Ελληνικά' self.wut = Translation(localized_string=self.u, locale='el') self.feed.request = mock.Mock() self.feed.request.APP.pretty = self.u self.category = Category(db_name=self.u) self.addon = Addon(name=self.u, id=2, type=1, slug='xx') self.addon._current_version = Version(version='v%s' % self.u)
def test_major_minor(self): """Check that major/minor/alpha is getting set.""" v = Version(version='3.0.12b2') assert v.major == 3 assert v.minor1 == 0 assert v.minor2 == 12 assert v.minor3 is None assert v.alpha == 'b' assert v.alpha_ver == 2 v = Version(version='3.6.1apre2+') assert v.major == 3 assert v.minor1 == 6 assert v.minor2 == 1 assert v.alpha == 'a' assert v.pre == 'pre' assert v.pre_ver == 2 v = Version(version='') assert v.major is None assert v.minor1 is None assert v.minor2 is None assert v.minor3 is None
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'], 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 # 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
def fake_version_object(self, obj, data, channel): if data: version = Version( addon=obj, id=data['id'], reviewed=self.handle_date(data['reviewed']), version=data['version'], channel=channel, ) version.all_files = [ self.fake_file_object(version, file_data) for file_data in data.get('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.get('compatible_apps', {}).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', '')), ) version._compatible_apps = compatible_apps version_serializer = self.fields.get('current_version') or None if version_serializer: version_serializer._attach_translations( version, data, version_serializer.translated_fields ) if 'license' in data and version_serializer: license_serializer = version_serializer.fields['license'] version.license = License(id=data['license']['id']) license_serializer._attach_fields( version.license, data['license'], ('builtin', 'url') ) # Can't use license_serializer._attach_translations() directly # because 'name' is a SerializerMethodField, not an # ESTranslatedField. license_serializer.db_name.attach_translations( version.license, data['license'], 'name' ) else: version.license = None else: version = None return version
def test_version_log_transformer(self): addon = Addon.objects.get() version = addon.current_version ActivityLog.create(amo.LOG.REJECT_VERSION, addon, version, user=self.request.user) version_two = Version(addon=addon, license=version.license, version='1.2.3') version_two.save() ActivityLog.create(amo.LOG.REJECT_VERSION, addon, version_two, user=self.request.user) versions = (Version.objects.filter(addon=addon).order_by('-created') .transform(Version.transformer_activity)) assert len(versions[0].all_activity) == 1 assert len(versions[1].all_activity) == 1
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
def fake_version_object(self, obj, data, channel): if data: version = Version( addon=obj, id=data['id'], reviewed=self.handle_date(data['reviewed']), version=data['version'], channel=channel) version.all_files = [ self.fake_file_object(version, file_data) for file_data in data.get('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.get('compatible_apps', {}).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', ''))) version._compatible_apps = compatible_apps else: version = None return version
def _get_version(self, status): v = Version() v.all_files = [mock.Mock()] v.all_files[0].status = status return v
def get_url(self, obj): # Addon.get_url_path() wants current_version to exist, but that's just # a safeguard. We don't care and don't want to fetch the current # version field to improve perf, so give it a fake one. obj._current_version = Version() return absolutify(obj.get_url_path())
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'
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