Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

Commit

Permalink
Fixed mishandling of file status when app is publicized (bug 801678)
Browse files Browse the repository at this point in the history
  • Loading branch information
robhudson committed Oct 15, 2012
1 parent 555d140 commit 0c015fe
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 30 deletions.
33 changes: 19 additions & 14 deletions mkt/developers/tests/test_views.py
Expand Up @@ -106,13 +106,13 @@ def test_no_paypal_js(self):
self.create_switch('enabled-paypal', active=False)
resp = self.client.get(self.url)
assert not settings.PAYPAL_JS_URL in resp.content, (
'When paypal is disabled, its JS lib should not load')
'When paypal is disabled, its JS lib should not load')

def test_load_paypal_js(self):
self.create_switch('enabled-paypal')
resp = self.client.get(self.url)
assert settings.PAYPAL_JS_URL in resp.content, (
'When paypal is enabled, its JS lib should load')
'When paypal is enabled, its JS lib should load')


class TestAppBreadcrumbs(AppHubTest):
Expand Down Expand Up @@ -196,7 +196,7 @@ def test_pending_version(self, ucm):
app = self.get_app()
self.make_mine()
app.update(is_packaged=True)
next_version = Version.objects.create(addon=app, version='1.24')
Version.objects.create(addon=app, version='1.24')
doc = pq(self.client.get(self.url).content)
eq_(doc('.item[data-addonid=%s] .item-latest-version' % app.id
).text(),
Expand All @@ -216,7 +216,7 @@ def test_action_links(self):
]
amo.tests.check_links(expected, doc('a.action-link'))
amo.tests.check_links([('View Statistics', app.get_stats_url())],
doc('a.stats-link'), verify=False)
doc('a.stats-link'), verify=False)

def test_action_links_packaged(self):
self.create_switch('app-stats')
Expand All @@ -233,7 +233,7 @@ def test_action_links_packaged(self):
]
amo.tests.check_links(expected, doc('a.action-link'))
amo.tests.check_links([('View Statistics', app.get_stats_url())],
doc('a.stats-link'), verify=False)
doc('a.stats-link'), verify=False)

def test_disabled_payments_action_links(self):
self.create_switch('app-stats')
Expand Down Expand Up @@ -482,7 +482,7 @@ def setUp(self):

self.addon = Addon.objects.get(id=337141)
self.addon.update(status=amo.STATUS_NOMINATED,
highest_status=amo.STATUS_NOMINATED)
highest_status=amo.STATUS_NOMINATED)

self.url = self.addon.get_dev_url('payments')
assert self.client.login(username='steamcube@mozilla.com',
Expand Down Expand Up @@ -518,7 +518,7 @@ def setup_premium(self):
# that the account exists on paypal.
#
@mock.patch('mkt.developers.forms.PremiumForm.clean',
new=lambda x: x.cleaned_data)
new=lambda x: x.cleaned_data)
class TestMarketplace(MarketplaceMixin, amo.tests.TestCase):
fixtures = ['base/users', 'webapps/337141-steamcube', 'market/prices']

Expand Down Expand Up @@ -568,8 +568,8 @@ def test_set_currency_fail(self):
data=self.get_data(currencies=['EUR', 'LOL']))
eq_(res.status_code, 200)
self.assertFormError(res, 'form', 'currencies',
[u'Select a valid choice. '
'LOL is not one of the available choices.'])
[u'Select a valid choice. '
'LOL is not one of the available choices.'])

def test_set_upsell(self):
self.setup_premium()
Expand Down Expand Up @@ -636,7 +636,7 @@ def test_permissions_token(self):
eq_(self.addon.premium.paypal_permissions_token, '')
url = self.addon.get_dev_url('acquire_refund_permission')
self.client.get(urlparams(url, request_token='foo',
verification_code='bar'))
verification_code='bar'))
self.addon = Addon.objects.get(pk=self.addon.pk)
eq_(self.addon.premium.paypal_permissions_token.lower(), 'foo')

Expand All @@ -648,7 +648,7 @@ def test_permissions_token_different_email(self):
self.setup_premium()
url = self.addon.get_dev_url('acquire_refund_permission')
self.client.get(urlparams(url, request_token='foo',
verification_code='bar'))
verification_code='bar'))
self.addon = Addon.objects.get(pk=self.addon.pk)
eq_(self.addon.premium.paypal_permissions_token.lower(), 'foo')

Expand Down Expand Up @@ -922,8 +922,8 @@ def test_already_refunded_solitude(self, client):
everyone=True)

client.post_refund.return_value = {'response': [{
'refundStatus': 'ALREADY_REVERSED_OR_REFUNDED',
'receiver.email': self.user.email}]}
'refundStatus': 'ALREADY_REVERSED_OR_REFUNDED',
'receiver.email': self.user.email}]}
c = self.make_purchase()
r = self.client.post(self.url, {'transaction_id': c.transaction_id,
'issue': '1'})
Expand Down Expand Up @@ -983,7 +983,8 @@ def generate_refunds(self):
for status in amo.REFUND_STATUSES.keys():
for x in xrange(status + 2):
c = Contribution.objects.create(addon=self.webapp,
user=self.user, type=amo.CONTRIB_PURCHASE)
user=self.user,
type=amo.CONTRIB_PURCHASE)
r = Refund.objects.create(contribution=c, status=status,
requested=days_ago(x))
self.expected.setdefault(status, []).append(r)
Expand Down Expand Up @@ -1129,6 +1130,8 @@ class TestPublicise(amo.tests.TestCase):
def setUp(self):
self.webapp = self.get_webapp()
self.webapp.update(status=amo.STATUS_PUBLIC_WAITING)
self.file = self.webapp.versions.latest().all_files[0]
self.file.update(status=amo.STATUS_PUBLIC_WAITING)
self.publicise_url = self.webapp.get_dev_url('publicise')
self.status_url = self.webapp.get_dev_url('versions')
assert self.client.login(username='steamcube@mozilla.com',
Expand All @@ -1147,6 +1150,8 @@ def test_publicise(self):
res = self.client.post(self.publicise_url)
eq_(res.status_code, 302)
eq_(self.get_webapp().status, amo.STATUS_PUBLIC)
eq_(self.get_webapp().versions.latest().all_files[0].status,
amo.STATUS_PUBLIC)

def test_status(self):
res = self.client.get(self.status_url)
Expand Down
37 changes: 21 additions & 16 deletions mkt/developers/views.py
Expand Up @@ -133,14 +133,15 @@ def dashboard(request, webapp=False):
@dev_required(webapp=True)
def edit(request, addon_id, addon, webapp=False):
data = {
'page': 'edit',
'addon': addon,
'webapp': webapp,
'valid_slug': addon.app_slug,
'image_sizes': APP_IMAGE_SIZES,
'tags': addon.tags.not_blacklisted().values_list('tag_text', flat=True),
'previews': addon.get_previews(),
'device_type_form': DeviceTypeForm(request.POST or None, addon=addon),
'page': 'edit',
'addon': addon,
'webapp': webapp,
'valid_slug': addon.app_slug,
'image_sizes': APP_IMAGE_SIZES,
'tags': addon.tags.not_blacklisted().values_list('tag_text',
flat=True),
'previews': addon.get_previews(),
'device_type_form': DeviceTypeForm(request.POST or None, addon=addon),
}
if acl.action_allowed(request, 'Apps', 'Configure'):
data['admin_settings_form'] = forms.AdminSettingsForm(instance=addon)
Expand Down Expand Up @@ -191,6 +192,9 @@ def disable(request, addon_id, addon):
def publicise(request, addon_id, addon):
if addon.status == amo.STATUS_PUBLIC_WAITING:
addon.update(status=amo.STATUS_PUBLIC)
File.objects.filter(
version__addon=addon, status=amo.STATUS_PUBLIC_WAITING).update(
status=amo.STATUS_PUBLIC)
amo.log(amo.LOG.CHANGE_STATUS, addon.get_status_display(), addon)
# Call update_version, so various other bits of data update.
addon.update_version()
Expand Down Expand Up @@ -471,7 +475,7 @@ def paypal_setup_confirm(request, addon_id, addon, webapp, source='paypal'):
if waffle.flag_is_active(request, 'solitude-payments'):
obj = client.create_seller_paypal(addon)
client.patch_seller_paypal(pk=obj['resource_pk'],
data={'paypal_id': addon.paypal_id})
data={'paypal_id': addon.paypal_id})

if waffle.flag_is_active(request, 'solitude-payments'):
# TODO(solitude): when the migration of data is completed, we
Expand Down Expand Up @@ -564,7 +568,7 @@ def bluevia_callback(request, addon_id, addon, webapp):
status = request.POST.get('status')
if status in ['registered', 'loggedin']:
bluevia = BlueViaConfig.objects.create(user=request.amo_user,
developer_id=developer_id)
developer_id=developer_id)
try:
(AddonBlueViaConfig.objects.get(addon=addon)
.update(bluevia_config=bluevia))
Expand Down Expand Up @@ -718,8 +722,8 @@ def issue_refund(request, addon_id, addon, webapp=False):
if 'issue' in request.POST:
if waffle.flag_is_active(request, 'solitude-payments'):
try:
response = client.post_refund(data={'uuid':
contribution.transaction_id})
response = client.post_refund(
data={'uuid': contribution.transaction_id})
except client.Error, e:
contribution.record_failed_refund(e)
paypal_log.error('Refund failed for: %s' % txn_id,
Expand Down Expand Up @@ -756,8 +760,9 @@ def issue_refund(request, addon_id, addon, webapp=False):
contribution.paykey,
res['receiver.email']))
messages.error(request,
_("A refund can't be issued at this time. We've "
"notified an admin; please try again later."))
_("A refund can't be issued at this time. "
"We've notified an admin; please try "
"again later."))
return redirect(addon.get_dev_url('refunds'))

contribution.mail_approved()
Expand Down Expand Up @@ -972,7 +977,7 @@ def file_validation(request, addon_id, addon, file_id):
@dev_required(allow_editors=True)
def json_file_validation(request, addon_id, addon, file_id):
file = get_object_or_404(File, id=file_id)
if not file.has_been_validated == True:
if not file.has_been_validated:
if request.method != 'POST':
return http.HttpResponseNotAllowed(['POST'])

Expand Down Expand Up @@ -1013,7 +1018,7 @@ def json_upload_detail(request, upload, addon_slug=None):


def upload_validation_context(request, upload, addon_slug=None, addon=None,
url=None):
url=None):
if addon_slug and not addon:
addon = get_object_or_404(Addon, slug=addon_slug)
if not settings.VALIDATE_ADDONS:
Expand Down

0 comments on commit 0c015fe

Please sign in to comment.