def setUp(self): self.request = mock.Mock() self.app = app_factory(publish_type=mkt.PUBLISH_IMMEDIATE, version_kw={'version': '1.0', 'created': self.days_ago(5)}) version_factory(addon=self.app, version='2.0', file_kw=dict(status=mkt.STATUS_PENDING)) self.app.reload()
def test_already_rated_version(self): self.app.update(is_packaged=True) Review.objects.create(addon=self.app, user=self.user, body='yes') version_factory(addon=self.app, version='3.0') self.app.update_version() res, data = self._get_url(self.list_url, app=self.app.app_slug) data = json.loads(res.content) assert data['user']['can_rate'] assert not data['user']['has_rated']
def test_already_rated_version(self): self.app.update(is_packaged=True) Review.objects.create(addon=self.app, user=self.user, body="yes") version_factory(addon=self.app, version="3.0") self.app.update_version() res, data = self._get_url(self.list_url, app=self.app.app_slug) data = json.loads(res.content) assert data["user"]["can_rate"] assert not data["user"]["has_rated"]
def test_create(self): version_factory(addon=self.addon, version='1.1') data = { 'app': self.addon.app_slug, 'version': '1.1', 'note_type': '0', 'body': 'flylikebee' } self.addon.addonuser_set.create(user=self.user) res = self.client.post(self.list_url, data=json.dumps(data)) eq_(res.status_code, 201) assert self.addon.threads.count()
def test_packaged_app(self): self.public_app.update(is_packaged=True) version = version_factory( addon=self.public_app, file_kw={'status': mkt.STATUS_PENDING}) self.public_app.reload() eq_(self.public_app.latest_version, version) self._test_position(self.public_app)
def test_get(self, client=None): first_version = self.app.current_version rev = Review.objects.create( addon=self.app, user=self.user, version=first_version, body=u"I lôve this app", rating=5 ) rev.update(created=self.days_ago(2)) rev2 = Review.objects.create( addon=self.app, user=self.user2, version=first_version, body=u"I also lôve this app", rating=4 ) # Extra review for another app, should be ignored. extra_app = app_factory() Review.objects.create( addon=extra_app, user=self.user, version=extra_app.current_version, body=u"I häte this extra app", rating=1 ) self.app.total_reviews = 2 ver = version_factory(addon=self.app, version="2.0", file_kw=dict(status=mkt.STATUS_PUBLIC)) self.app.update_version() reset_queries() res, data = self._get_url(self.list_url, app=self.app.pk, client=client) eq_(len(data["objects"]), 2) self._compare_review_data(client, data["objects"][0], rev2) self._compare_review_data(client, data["objects"][1], rev) eq_(data["info"]["average"], self.app.average_rating) eq_(data["info"]["slug"], self.app.app_slug) eq_(data["info"]["current_version"], ver.version) if client != self.anon: eq_(data["user"]["can_rate"], True) eq_(data["user"]["has_rated"], True) return res
def test_delete_version_app_private(self, update_name_mock, update_manifest_mock, index_mock): """Test deletion of current_version when app is APPROVED.""" self.app.update(status=mkt.STATUS_APPROVED) ver1 = self.app.latest_version ver2 = version_factory( addon=self.app, version='2.0', file_kw=dict(status=mkt.STATUS_PUBLIC)) eq_(self.app.latest_version, ver2) eq_(self.app.current_version, ver2) update_manifest_mock.reset_mock() index_mock.reset_mock() self.client.post(self.delete_url, {'version_id': ver2.pk}) self.app.reload() eq_(self.app.status, mkt.STATUS_APPROVED) eq_(self.app.latest_version, ver1) eq_(self.app.current_version, ver1) eq_(self.app.versions.count(), 1) eq_(Version.with_deleted.get(pk=ver2.pk).all_files[0].status, mkt.STATUS_DISABLED) eq_(update_name_mock.call_count, 1) eq_(update_manifest_mock.delay.call_count, 1) eq_(index_mock.delay.call_count, 1)
def test_app_threads(self): version1 = version_factory(addon=self.addon, version='7.12') thread1 = CommunicationThread.objects.create( _addon=self.addon, _version=version1, read_permission_public=True) version2 = version_factory(addon=self.addon, version='1.16') thread2 = CommunicationThread.objects.create( _addon=self.addon, _version=version2, read_permission_public=True) for thread in (thread1, thread2): res = self.client.get(reverse('comm-thread-detail', args=[thread.pk])) eq_(res.status_code, 200) eq_(json.loads(res.content)['app_threads'], [{"id": thread2.id, "version__version": version2.version}, {"id": thread1.id, "version__version": version1.version}])
def test_extract_latest_version(self): created_date = self.days_ago(5).replace(microsecond=0) nomination_date = self.days_ago(3).replace(microsecond=0) version_factory( addon=self.app, version='43.0', has_editor_comment=True, has_info_request=True, created=created_date, nomination=nomination_date, file_kw=dict(status=mkt.STATUS_REJECTED)) obj, doc = self._get_doc() eq_(doc['latest_version']['status'], mkt.STATUS_REJECTED) eq_(doc['latest_version']['has_editor_comment'], True) eq_(doc['latest_version']['has_info_request'], True) eq_(doc['latest_version']['created_date'], created_date) eq_(doc['latest_version']['nomination_date'], nomination_date)
def test_app_threads(self): version1 = version_factory(addon=self.addon, version='7.12') thread1 = CommunicationThread.objects.create( _addon=self.addon, _version=version1, read_permission_public=True) CommunicationThreadCC.objects.create(user=self.profile, thread=thread1) version2 = version_factory(addon=self.addon, version='1.16') thread2 = CommunicationThread.objects.create( _addon=self.addon, _version=version2, read_permission_public=True) CommunicationThreadCC.objects.create(user=self.profile, thread=thread2) self.grant_permission(self.user, 'Apps:Review') res = self.client.get(self.list_url, {'app': self.addon.app_slug}) eq_(res.status_code, 200) eq_(res.json['app_threads'], [{'id': thread2.id, 'version__version': version2.version}, {'id': thread1.id, 'version__version': version1.version}])
def setUp(self): self.app = app_factory(status=mkt.STATUS_PUBLIC, is_packaged=True) self.ver1 = self.app.current_version self.ver1.update(created=self.days_ago(1)) self.ver2 = version_factory(addon=self.app, version='2.0', file_kw=dict(status=mkt.STATUS_APPROVED)) self.app.update(_latest_version=self.ver2) self.form = forms.PublishForm
def test_new_rating_for_new_version(self): self.app.update(is_packaged=True) self._create() version = version_factory(addon=self.app, version="3.0") self.app.update_version() eq_(self.app.reload().current_version, version) res, data = self._create() eq_(201, res.status_code) eq_(data["version"]["version"], "3.0")
def test_new_rating_for_new_version(self): self.app.update(is_packaged=True) self._create() version = version_factory(webapp=self.app, version='3.0') self.app.update_version() eq_(self.app.reload().current_version, version) res, data = self._create() eq_(201, res.status_code) eq_(data['version']['version'], '3.0')
def test_extract_latest_version(self): created_date = self.days_ago(5).replace(microsecond=0) nomination_date = self.days_ago(3).replace(microsecond=0) version_factory( addon=self.app, version="43.0", has_editor_comment=True, has_info_request=True, created=created_date, nomination=nomination_date, file_kw=dict(status=mkt.STATUS_REJECTED), ) obj, doc = self._get_doc() eq_(doc["latest_version"]["status"], mkt.STATUS_REJECTED) eq_(doc["latest_version"]["has_editor_comment"], True) eq_(doc["latest_version"]["has_info_request"], True) eq_(doc["latest_version"]["created_date"], created_date) eq_(doc["latest_version"]["nomination_date"], nomination_date)
def test_get_anonymous_queries(self): first_version = self.app.current_version Review.objects.create(webapp=self.app, user=self.user, version=first_version, body=u'I lôve this app', rating=5) Review.objects.create(webapp=self.app, user=self.user2, version=first_version, body=u'I also lôve this app', rating=4) self.app.total_reviews = 2 version_factory(webapp=self.app, version='2.0', file_kw=dict(status=mkt.STATUS_PUBLIC)) self.app.update_version() reset_queries() with self.assertNumQueries(7): # 7 queries: # - 1 SAVEPOINT # - 2 for the Reviews queryset and the translations # - 2 for the Version associated to the reviews (qs + translations) # - 1 for the File attached to the Version # - 1 RELEASE SAVEPOINT # # Notes: # - In prod, we actually do COMMIT/ROLLBACK and not # SAVEPOINT/RELEASE SAVEPOINT. It would be nice to avoid those for # all GET requests in the API, but it's not trivial to do for # ViewSets which implement multiple actions through the same view # function (non_atomic_requests() really want to be applied to the # view function). # # - The query count is slightly higher in prod. In tests, we patch # get_app() to avoid the app queries to pollute the queries count. # # Once we are on django 1.7, we'll be able to play with Prefetch # to reduce the number of queries further by customizing the # queryset used for the complex related objects like versions and # webapp. with patch('mkt.ratings.views.RatingViewSet.get_app') as get_app: get_app.return_value = self.app res, data = self._get_url(self.list_url, client=self.anon, app=self.app.pk)
def generate_packaged_app(namedict, apptype, categories, developer_name, privacy_policy=None, device_types=(), permissions=(), versions=(), default_locale='en-US', package_file=None, status=4, uses_flash=False, **kw): now = datetime.datetime.now() app = app_factory(categories=categories, name=namedict[default_locale], complete=False, rated=True, is_packaged=True, privacy_policy=privacy_policy, version_kw={ 'version': '1.0', 'reviewed': now if status >= 4 else None, '_developer_name': developer_name}, file_kw={'status': status, 'uses_flash': uses_flash}) if device_types: for dt in device_types: app.addondevicetype_set.create(device_type=DEVICE_CHOICES_IDS[dt]) else: app.addondevicetype_set.create(device_type=1) f = app.latest_version.all_files[0] f.update(filename=f.generate_filename()) fp = os.path.join(app.latest_version.path_prefix, f.filename) try: os.makedirs(os.path.dirname(fp)) except OSError: pass if package_file: return app with storage.open(fp, 'w') as out: generate_app_package(app, out, apptype, permissions, namedict, version=app.latest_version) for i, vspec in enumerate(versions, 1): st = STATUS_CHOICES_API_LOOKUP[vspec.get("status", "public")] rtime = (now + datetime.timedelta(i)) v = version_factory(version="1." + str(i), addon=app, reviewed=rtime if st >= 4 else None, nomination=rtime if st > 0 else None, created=rtime, file_kw={'status': st}, _developer_name=developer_name) f = v.files.all()[0] f.update(filename=f.generate_filename()) fp = os.path.join(app.latest_version.path_prefix, f.filename) try: os.makedirs(os.path.dirname(fp)) except OSError: pass with open(fp, 'w') as out: generate_app_package(app, out, vspec.get("type", apptype), vspec.get("permissions", permissions), namedict, version=v) app.update_version() return app
def generate_packaged_app(namedict, apptype, categories, developer_name, privacy_policy=None, device_types=(), permissions=(), versions=(), default_locale='en-US', package_file=None, status=4, **kw): now = datetime.datetime.now() app = app_factory(categories=categories, name=namedict[default_locale], complete=False, rated=True, is_packaged=True, privacy_policy=privacy_policy, version_kw={ 'version': '1.0', 'reviewed': now if status >= 4 else None, '_developer_name': developer_name}, file_kw={'status': status}) if device_types: for dt in device_types: app.addondevicetype_set.create(device_type=DEVICE_CHOICES_IDS[dt]) else: app.addondevicetype_set.create(device_type=1) f = app.latest_version.all_files[0] f.update(filename=f.generate_filename()) fp = os.path.join(app.latest_version.path_prefix, f.filename) if package_file: package_file_file = open(package_file) manifest = WebAppParser().get_json_data(package_file_file) AppManifest.objects.create( version=app.latest_version, manifest=json.dumps(manifest)) # copy package_file to storage like a normal app. private_storage.save(fp, package_file_file) app.update_version() return app with private_storage.open(fp, 'w') as out: generate_app_package(app, out, apptype, permissions, namedict, version=app.latest_version) for i, vspec in enumerate(versions, 1): st = STATUS_CHOICES_API_LOOKUP[vspec.get("status", "public")] rtime = (now + datetime.timedelta(i)) v = version_factory(version="1." + str(i), addon=app, reviewed=rtime if st >= 4 else None, nomination=rtime if st > 0 else None, created=rtime, file_kw={'status': st}, _developer_name=developer_name) f = v.files.all()[0] f.update(filename=f.generate_filename()) fp = os.path.join(app.latest_version.path_prefix, f.filename) with private_storage.open(fp, 'w') as out: generate_app_package(app, out, vspec.get("type", apptype), vspec.get("permissions", permissions), namedict, version=v) app.update_version() return app
def test_version_list_packaged(self): self.app.update(is_packaged=True) version_factory(addon=self.app, version='2.0', file_kw=dict(status=mkt.STATUS_PENDING)) self.app = self.get_app() doc = pq(self.client.get(self.url).content) eq_(doc('#version-status').length, 1) eq_(doc('#version-list tbody tr').length, 2) # 1 pending and 1 public. eq_(doc('#version-list span.status-pending').length, 1) eq_(doc('#version-list span.status-public').length, 1) # Check version strings and order of versions. eq_(map(lambda x: x.text, doc('#version-list h4 a')), ['2.0', '1.0']) # There should be 2 delete buttons. eq_(doc('#version-list a.delete-version.button').length, 2) # Check download url. eq_(doc('#version-list a.download').eq(0).attr('href'), self.app.versions.all()[0].all_files[0].get_url_path('')) eq_(doc('#version-list a.download').eq(1).attr('href'), self.app.versions.all()[1].all_files[0].get_url_path(''))
def test_app_threads(self): version1 = version_factory(addon=self.addon, version='7.12') thread1 = CommunicationThread.objects.create( _addon=self.addon, _version=version1, read_permission_public=True) version2 = version_factory(addon=self.addon, version='1.16') thread2 = CommunicationThread.objects.create( _addon=self.addon, _version=version2, read_permission_public=True) for thread in (thread1, thread2): res = self.client.get( reverse('comm-thread-detail', args=[thread.pk])) eq_(res.status_code, 200) eq_( json.loads(res.content)['app_threads'], [{ "id": thread2.id, "version__version": version2.version }, { "id": thread1.id, "version__version": version1.version }])
def test_version_number(self): version = version_factory(addon=self.addon, version='7.12') thread = CommunicationThread.objects.create( _addon=self.addon, _version=version, read_permission_public=True) res = self.client.get(reverse('comm-thread-detail', args=[thread.pk])) eq_(json.loads(res.content)['version_number'], '7.12') eq_(json.loads(res.content)['version_is_obsolete'], False) version.delete() res = self.client.get(reverse('comm-thread-detail', args=[thread.pk])) eq_(json.loads(res.content)['version_number'], '7.12') eq_(json.loads(res.content)['version_is_obsolete'], True)
def test_version_list_packaged(self): self.app.update(is_packaged=True) version_factory(addon=self.app, version='2.0', file_kw=dict(status=mkt.STATUS_PENDING)) self.app = self.get_app() doc = pq(self.client.get(self.url).content) eq_(doc('#version-status').length, 1) eq_(doc('#version-list tbody tr').length, 2) # 1 pending and 1 public. eq_(doc('#version-list span.status-pending').length, 1) eq_(doc('#version-list span.status-public').length, 1) # Check version strings and order of versions. eq_(map(lambda x: x.text, doc('#version-list h4 a')), ['2.0', '1.0']) # There should be 2 delete buttons. eq_(doc('#version-list a.delete-version.button').length, 2) # Check download url. eq_( doc('#version-list a.download').eq(0).attr('href'), self.app.versions.all()[0].all_files[0].get_url_path('')) eq_( doc('#version-list a.download').eq(1).attr('href'), self.app.versions.all()[1].all_files[0].get_url_path(''))
def test_response_deleted_version_app(self): self.addon.update(status=mkt.STATUS_DELETED) thread = self._thread_factory(note=True) version = version_factory(addon=self.addon) version.update(deleted=True) thread.update(_version=version) res = self.client.get( reverse('comm-thread-detail', kwargs={'pk': thread.pk})) eq_(res.status_code, 200) eq_(res.json['addon'], self.addon.id) eq_(res.json['addon_meta']['name'], self.addon.name) eq_(res.json['version'], version.id) eq_(res.json['version_number'], version.version) eq_(res.json['version_is_obsolete'], True)
def generate_packaged_app(name, apptype, categories, developer_name, privacy_policy=None, device_types=(), permissions=(), versions=None, num_locales=2, package_file=None, status=4, **kw): if versions is None: versions = [status] now = datetime.datetime.now() app = app_factory(categories=categories, name=name, complete=False, rated=True, is_packaged=True, privacy_policy=privacy_policy, version_kw={ 'version': '1.0', 'reviewed': now if status >= 4 else None, '_developer_name': developer_name}, file_kw={'status': status}) if device_types: for dt in device_types: app.addondevicetype_set.create(device_type=DEVICE_CHOICES_IDS[dt]) else: app.addondevicetype_set.create(device_type=1) f = app.latest_version.all_files[0] f.update(filename=f.generate_filename()) fp = os.path.join(app.latest_version.path_prefix, f.filename) try: os.makedirs(os.path.dirname(fp)) except OSError: pass if package_file: return app with open(fp, 'w') as out: generate_app_package(app, out, apptype, permissions=permissions, version=app.latest_version, num_locales=num_locales) for i, f_status in enumerate(versions[1:], 1): st = STATUS_CHOICES_API_LOOKUP[f_status] rtime = (now + datetime.timedelta(i)) if st >= 4 else None v = version_factory(version="1." + str(i), addon=app, reviewed=rtime, created=rtime, file_kw={'status': st}, _developer_name=developer_name) generate_app_package(app, out, apptype, permissions, v, num_locales=num_locales) app.update_version() return app
def test_delete_version_app_public(self): """Test deletion of current_version when app is PUBLIC.""" eq_(self.app.status, mkt.STATUS_PUBLIC) ver1 = self.app.latest_version ver2 = version_factory( addon=self.app, version='2.0', file_kw=dict(status=mkt.STATUS_PUBLIC)) eq_(self.app.latest_version, ver2) eq_(self.app.current_version, ver2) self.client.post(self.delete_url, {'version_id': ver2.pk}) self.app.reload() eq_(self.app.status, mkt.STATUS_PUBLIC) eq_(self.app.latest_version, ver1) eq_(self.app.current_version, ver1) eq_(self.app.versions.count(), 1) eq_(Version.with_deleted.get(pk=ver2.pk).all_files[0].status, mkt.STATUS_DISABLED)
def test_get(self, client=None): first_version = self.app.current_version rev = Review.objects.create(addon=self.app, user=self.user, version=first_version, body=u'I lôve this app', rating=5) rev.update(created=self.days_ago(2)) rev2 = Review.objects.create(addon=self.app, user=self.user2, version=first_version, body=u'I also lôve this app', rating=4) # Extra review for another app, should be ignored. extra_app = app_factory() Review.objects.create(addon=extra_app, user=self.user, version=extra_app.current_version, body=u'I häte this extra app', rating=1) self.app.total_reviews = 2 ver = version_factory(addon=self.app, version='2.0', file_kw=dict(status=mkt.STATUS_PUBLIC)) self.app.update_version() reset_queries() res, data = self._get_url(self.list_url, app=self.app.pk, client=client) eq_(len(data['objects']), 2) self._compare_review_data(client, data['objects'][0], rev2) self._compare_review_data(client, data['objects'][1], rev) eq_(data['info']['average'], self.app.average_rating) eq_(data['info']['slug'], self.app.app_slug) eq_(data['info']['current_version'], ver.version) if client != self.anon: eq_(data['user']['can_rate'], True) eq_(data['user']['has_rated'], True) return res
def test_version_is_public(self): addon = Webapp.objects.get(id=337141) version = version_factory(addon=addon) # Base test. Everything is in order, the version should be public. eq_(version.is_public(), True) # Non-public file. self._reset_version(version) version.all_files[0].status = mkt.STATUS_DISABLED eq_(version.is_public(), False) # Deleted version. self._reset_version(version) version.deleted = True eq_(version.is_public(), False) # Non-public addon. self._reset_version(version) with mock.patch("mkt.webapps.models.Webapp.is_public") as is_addon_public: is_addon_public.return_value = False eq_(version.is_public(), False)
def test_delete_last_public_version(self): """ Test that deleting the last PUBLIC version but there is an APPROVED version marks the app as APPROVED. Similar to the above test but ensures APPROVED versions don't get confused with PUBLIC versions. """ eq_(self.app.versions.count(), 1) ver1 = self.app.latest_version ver1.all_files[0].update(status=mkt.STATUS_APPROVED) ver2 = version_factory( addon=self.app, version='2.0', file_kw=dict(status=mkt.STATUS_PUBLIC)) self.client.post(self.delete_url, {'version_id': ver2.pk}) self.app.reload() eq_(self.app.status, mkt.STATUS_APPROVED) eq_(self.app.latest_version, ver1) eq_(self.app.current_version, None) eq_(self.app.versions.count(), 1) eq_(Version.with_deleted.get(pk=ver2.pk).all_files[0].status, mkt.STATUS_DISABLED)
def test_version_is_public(self): addon = Webapp.objects.get(id=337141) version = version_factory(addon=addon) # Base test. Everything is in order, the version should be public. eq_(version.is_public(), True) # Non-public file. self._reset_version(version) version.all_files[0].status = mkt.STATUS_DISABLED eq_(version.is_public(), False) # Deleted version. self._reset_version(version) version.deleted = True eq_(version.is_public(), False) # Non-public addon. self._reset_version(version) with mock.patch('mkt.webapps.models.Webapp.is_public') \ as is_addon_public: is_addon_public.return_value = False eq_(version.is_public(), False)
def test_get(self, client=None): first_version = self.app.current_version rev = Review.objects.create(webapp=self.app, user=self.user, version=first_version, body=u'I lôve this app', rating=5) rev.update(created=self.days_ago(2)) rev2 = Review.objects.create(webapp=self.app, user=self.user2, version=first_version, body=u'I also lôve this app', rating=4) # Extra review for another app, should be ignored. extra_app = app_factory() Review.objects.create(webapp=extra_app, user=self.user, version=extra_app.current_version, body=u'I häte this extra app', rating=1) self.app.total_reviews = 2 ver = version_factory(webapp=self.app, version='2.0', file_kw=dict(status=mkt.STATUS_PUBLIC)) self.app.update_version() reset_queries() res, data = self._get_url(self.list_url, app=self.app.pk, client=client) eq_(len(data['objects']), 2) self._compare_review_data(client, data['objects'][0], rev2) self._compare_review_data(client, data['objects'][1], rev) eq_(data['info']['average'], self.app.average_rating) eq_(data['info']['slug'], self.app.app_slug) eq_(data['info']['current_version'], ver.version) if client != self.anon: eq_(data['user']['can_rate'], True) eq_(data['user']['has_rated'], True) return res
def generate_packaged_app(namedict, apptype, categories, developer_name, privacy_policy=None, device_types=(), permissions=(), versions=(), default_locale='en-US', package_file=None, status=4, uses_flash=False, **kw): now = datetime.datetime.now() app = app_factory(categories=categories, name=namedict[default_locale], complete=False, rated=True, is_packaged=True, privacy_policy=privacy_policy, version_kw={ 'version': '1.0', 'reviewed': now if status >= 4 else None, '_developer_name': developer_name }, file_kw={ 'status': status, 'uses_flash': uses_flash }) if device_types: for dt in device_types: app.addondevicetype_set.create(device_type=DEVICE_CHOICES_IDS[dt]) else: app.addondevicetype_set.create(device_type=1) f = app.latest_version.all_files[0] f.update(filename=f.generate_filename()) fp = os.path.join(app.latest_version.path_prefix, f.filename) try: os.makedirs(os.path.dirname(fp)) except OSError: pass if package_file: return app with storage.open(fp, 'w') as out: generate_app_package(app, out, apptype, permissions, namedict, version=app.latest_version) for i, vspec in enumerate(versions, 1): st = STATUS_CHOICES_API_LOOKUP[vspec.get("status", "public")] rtime = (now + datetime.timedelta(i)) v = version_factory(version="1." + str(i), addon=app, reviewed=rtime if st >= 4 else None, nomination=rtime if st > 0 else None, created=rtime, file_kw={'status': st}, _developer_name=developer_name) f = v.files.all()[0] f.update(filename=f.generate_filename()) fp = os.path.join(app.latest_version.path_prefix, f.filename) try: os.makedirs(os.path.dirname(fp)) except OSError: pass with open(fp, 'w') as out: generate_app_package(app, out, vspec.get("type", apptype), vspec.get("permissions", permissions), namedict, version=v) app.update_version() return app
def generate_packaged_app(namedict, apptype, categories, developer_name, privacy_policy=None, device_types=(), permissions=(), versions=(), default_locale='en-US', package_file=None, status=4, **kw): now = datetime.datetime.now() app = app_factory(categories=categories, name=namedict[default_locale], complete=False, rated=True, is_packaged=True, privacy_policy=privacy_policy, version_kw={ 'version': '1.0', 'reviewed': now if status >= 4 else None, '_developer_name': developer_name }, file_kw={'status': status}) if device_types: for dt in device_types: app.addondevicetype_set.create(device_type=DEVICE_CHOICES_IDS[dt]) else: app.addondevicetype_set.create(device_type=1) f = app.latest_version.all_files[0] f.update(filename=f.generate_filename()) fp = os.path.join(app.latest_version.path_prefix, f.filename) if package_file: package_file_file = open(package_file) manifest = WebAppParser().get_json_data(package_file_file) AppManifest.objects.create(version=app.latest_version, manifest=json.dumps(manifest)) # copy package_file to storage like a normal app. private_storage.save(fp, package_file_file) app.update_version() return app with private_storage.open(fp, 'w') as out: generate_app_package(app, out, apptype, permissions, namedict, version=app.latest_version) for i, vspec in enumerate(versions, 1): st = STATUS_CHOICES_API_LOOKUP[vspec.get("status", "public")] rtime = (now + datetime.timedelta(i)) v = version_factory(version="1." + str(i), addon=app, reviewed=rtime if st >= 4 else None, nomination=rtime if st > 0 else None, created=rtime, file_kw={'status': st}, _developer_name=developer_name) f = v.files.all()[0] f.update(filename=f.generate_filename()) fp = os.path.join(app.latest_version.path_prefix, f.filename) with private_storage.open(fp, 'w') as out: generate_app_package(app, out, vspec.get("type", apptype), vspec.get("permissions", permissions), namedict, version=v) app.update_version() return app
def test_packaged_app_deleted(self): self.app.update(is_packaged=True) ver = version_factory(addon=self.app) file_factory(version=ver) self.app.delete() self.summary()