Permalink
Browse files

pass the query params through update to watermarked (bug 691606)

  • Loading branch information...
andymckay committed Oct 5, 2011
1 parent b767629 commit cef3a75de1ca44c41d4c9ecd552b24323a512f25
Showing with 40 additions and 23 deletions.
  1. +18 −2 apps/addons/tests/test_update.py
  2. +1 −0 apps/constants/base.py
  3. +19 −16 services/update.py
  4. +2 −5 services/utils.py
@@ -1,7 +1,11 @@
+# -*- coding: utf8 -*-
from datetime import datetime, timedelta
from email import utils
+import urllib
+import urlparse
from django.db import connection
+from django.utils.encoding import smart_str
from nose.tools import eq_
@@ -541,8 +545,20 @@ def test_url_premium(self):
self.addon_one.update(premium_type=amo.ADDON_PREMIUM)
up = self.get(self.good_data.copy())
up.get_rdf()
- eq_(up.data['row']['url'],
- settings_local.SITE_URL + '/downloads/watermarked/67442')
+ target = settings_local.SITE_URL + '/downloads/watermarked/67442'
+ assert up.data['row']['url'].startswith(target)
+
+ def test_url_premium_gets(self):
+ self.addon_one.update(premium_type=amo.ADDON_PREMIUM)
+ data = self.good_data.copy()
+ data[amo.WATERMARK_KEY] = urllib.quote_plus(smart_str('ø@bar.com'))
+ data[amo.WATERMARK_KEY_HASH] = 'somehash'
+ up = self.get(data)
+ up.get_rdf()
+ query = urlparse.urlparse(up.data['row']['url']).query
+ params = dict(urlparse.parse_qsl(query, True))
+ eq_(params[amo.WATERMARK_KEY], data[amo.WATERMARK_KEY])
+ eq_(params[amo.WATERMARK_KEY_HASH], data[amo.WATERMARK_KEY_HASH])
def test_hash(self):
rdf = self.get(self.good_data).get_rdf()
View
@@ -324,3 +324,4 @@
# Used to watermark addons install.rdf and update.
WATERMARK_KEY = 'purchaser'
WATERMARK_KEY_HASH = '%s-hash' % WATERMARK_KEY
+WATERMARK_KEYS = (WATERMARK_KEY, WATERMARK_KEY_HASH)
View
@@ -11,6 +11,7 @@
import commonware.log
from django.core.management import setup_environ
+from django.utils.http import urlencode
import settings_local as settings
setup_environ(settings)
@@ -23,10 +24,8 @@
except ImportError:
from apps.versions.compare import version_int
-from utils import (get_mirror, ADDON_PREMIUM,
- APP_GUIDS, PLATFORMS, VERSION_BETA,
- STATUS_PUBLIC, STATUSES_PUBLIC, STATUS_BETA, STATUS_NULL,
- STATUS_LITE, STATUS_LITE_AND_NOMINATED, ADDON_SLUGS_UPDATE)
+from constants import base
+from utils import get_mirror, APP_GUIDS, PLATFORMS, STATUSES_PUBLIC
good_rdf = """<?xml version="1.0"?>
@@ -132,14 +131,15 @@ def is_valid(self):
else:
data['appOS'] = None
- self.is_beta_version = VERSION_BETA.search(data.get('version', ''))
+ self.is_beta_version = base.VERSION_BETA.search(data.get('version',
+ ''))
return True
def get_beta(self):
data = self.data
- data['status'] = STATUS_PUBLIC
+ data['status'] = base.STATUS_PUBLIC
- if data['addon_status'] == STATUS_PUBLIC:
+ if data['addon_status'] == base.STATUS_PUBLIC:
# Beta channel looks at the addon name to see if it's beta.
if self.is_beta_version:
# For beta look at the status of the existing files.
@@ -156,17 +156,18 @@ def get_beta(self):
status = result[1]
# If it's in Beta or Public, then we should be looking
# for similar. If not, find something public.
- if status in (STATUS_BETA, STATUS_PUBLIC):
+ if status in (base.STATUS_BETA, base.STATUS_PUBLIC):
data['status'] = status
else:
data.update(STATUSES_PUBLIC)
self.flags['multiple_status'] = True
- elif data['addon_status'] in (STATUS_LITE, STATUS_LITE_AND_NOMINATED):
- data['status'] = STATUS_LITE
+ elif data['addon_status'] in (base.STATUS_LITE,
+ base.STATUS_LITE_AND_NOMINATED):
+ data['status'] = base.STATUS_LITE
else:
# Otherwise then we'll keep the update within the current version.
- data['status'] = STATUS_NULL
+ data['status'] = base.STATUS_NULL
self.flags['use_version'] = True
def get_update(self):
@@ -229,10 +230,12 @@ def get_update(self):
'datestatuschanged', 'releasenotes', 'version',
'premium_type'],
list(result)))
- row['type'] = ADDON_SLUGS_UPDATE[row['type']]
- if row['premium_type'] == ADDON_PREMIUM:
- row['url'] = ('%s/downloads/watermarked/%s' %
- (settings.SITE_URL, row['file_id']))
+ row['type'] = base.ADDON_SLUGS_UPDATE[row['type']]
+ if row['premium_type'] == base.ADDON_PREMIUM:
+ qs = urlencode(dict((k, data.get(k, ''))
+ for k in base.WATERMARK_KEYS))
+ row['url'] = (u'%s/downloads/watermarked/%s?%s' %
+ (settings.SITE_URL, row['file_id'], qs))
else:
row['url'] = get_mirror(self.data['addon_status'],
self.data['id'], row)
@@ -258,7 +261,7 @@ def get_rdf(self):
return rdf
def get_no_updates_rdf(self):
- name = ADDON_SLUGS_UPDATE[self.data['type']]
+ name = base.ADDON_SLUGS_UPDATE[self.data['type']]
return no_updates_rdf % ({'guid': self.data['guid'], 'type': name})
def get_good_rdf(self):
View
@@ -9,11 +9,8 @@
from constants.applications import APPS_ALL
from constants.platforms import PLATFORMS
-from constants.base import (ADDON_PREMIUM, STATUS_NULL, STATUS_UNREVIEWED,
- STATUS_PENDING, STATUS_NOMINATED, STATUS_PUBLIC,
- STATUS_DISABLED, STATUS_LISTED, STATUS_BETA,
- STATUS_LITE, STATUS_LITE_AND_NOMINATED,
- STATUS_PURGATORY, VERSION_BETA)
+from constants.base import (STATUS_PUBLIC, STATUS_DISABLED, STATUS_BETA,
+ STATUS_LITE, STATUS_LITE_AND_NOMINATED)
APP_GUIDS = dict([(app.guid, app.id) for app in APPS_ALL.values()])
PLATFORMS = dict([(plat.api_name, plat.id) for plat in PLATFORMS.values()])

0 comments on commit cef3a75

Please sign in to comment.