Skip to content
This repository was archived by the owner on Mar 15, 2018. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions apps/addons/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,6 @@ def __init__(self, *args, **kw):
cats = dict(self.addon.app_categories).get(app, [])
self.initial.append({'categories': [c.id for c in cats]})

# Reconstruct the forms according to the initial data.
self._construct_forms()

for app, form in zip(apps, self.forms):
key = app.id if app else None
form.request = self.request
Expand Down
6 changes: 3 additions & 3 deletions apps/addons/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ def compatible_version(self, app_id, app_version=None, platform=None,
version_id = 0

log.debug(u'Caching compat version %s => %s' % (cache_key, version_id))
cache.set(cache_key, version_id, 0)
cache.set(cache_key, version_id, None)

return version

Expand Down Expand Up @@ -1356,7 +1356,7 @@ def tags_partitioned_by_developer(self):
"""Returns a tuple of developer tags and user tags for this addon."""
tags = self.tags.not_blacklisted()
if self.is_persona:
return models.query.EmptyQuerySet(), tags
return [], tags
user_tags = tags.exclude(addon_tags__user__in=self.listed_authors)
dev_tags = tags.exclude(id__in=[t.id for t in user_tags])
return dev_tags, user_tags
Expand Down Expand Up @@ -1713,7 +1713,7 @@ def check_ownership(self, request, require_owner, require_author,


class AddonDeviceType(amo.models.ModelBase):
addon = models.ForeignKey(Addon)
addon = models.ForeignKey(Addon, db_constraint=False)
device_type = models.PositiveIntegerField(
default=amo.DEVICE_DESKTOP, choices=do_dictsort(amo.DEVICE_TYPES),
db_index=True)
Expand Down
29 changes: 21 additions & 8 deletions apps/addons/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,12 @@ def get_from_clause(self):
qn2 = self.connection.ops.quote_name
index_map = self.query.index_map
first = True
from_params = []
for alias in self.query.tables:
if not self.query.alias_refcount[alias]:
continue
try:
name, alias, join_type, lhs, lhs_col, col, nullable = self.query.alias_map[alias]
name, alias, join_type, lhs, join_cols, _, join_field = self.query.alias_map[alias]
except KeyError:
# Extra tables can end up in self.tables, but not in the
# alias_map if they aren't in a join. That's OK. We skip them.
Expand All @@ -93,13 +94,25 @@ def get_from_clause(self):
else:
use_index = ''
if join_type and not first:
# If you really need a LEFT OUTER JOIN, file a bug.
join_type = 'INNER JOIN'
result.append('%s %s%s %s ON (%s.%s = %s.%s)'
% (join_type, qn(name), alias_str, use_index, qn(lhs),
qn2(lhs_col), qn(alias), qn2(col)))
extra_cond = join_field.get_extra_restriction(
self.query.where_class, alias, lhs)
if extra_cond:
extra_sql, extra_params = extra_cond.as_sql(
qn, self.connection)
extra_sql = 'AND (%s)' % extra_sql
from_params.extend(extra_params)
else:
extra_sql = ""
result.append('%s %s%s %s ON ('
% (join_type, qn(name), alias_str, use_index))
for index, (lhs_col, rhs_col) in enumerate(join_cols):
if index != 0:
result.append(' AND ')
result.append('%s.%s = %s.%s' %
(qn(lhs), qn2(lhs_col), qn(alias), qn2(rhs_col)))
result.append('%s)' % extra_sql)
else:
connector = not first and ', ' or ''
connector = connector = '' if first else ', '
result.append('%s%s%s %s' % (connector, qn(name), alias_str, use_index))
### jbalogh out. ###
first = False
Expand All @@ -112,4 +125,4 @@ def get_from_clause(self):
connector = not first and ', ' or ''
result.append('%s%s' % (connector, qn(alias)))
first = False
return result, []
return result, from_params
19 changes: 11 additions & 8 deletions apps/addons/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2200,29 +2200,32 @@ def setUp(self):

def test_extract(self):
File.objects.create(platform=self.platform_mob, version=self.version,
filename=self.xpi_path('langpack-localepicker'))
assert self.addon.get_localepicker()
filename=self.xpi_path('langpack-localepicker'),
status=amo.STATUS_PUBLIC)
assert self.addon.reload().get_localepicker()
assert 'title=Select a language' in self.addon.get_localepicker()

def test_extract_no_file(self):
File.objects.create(platform=self.platform_mob, version=self.version,
filename=self.xpi_path('langpack'))
eq_(self.addon.get_localepicker(), '')
filename=self.xpi_path('langpack'), status=amo.STATUS_PUBLIC)
eq_(self.addon.reload().get_localepicker(), '')

def test_extract_no_files(self):
eq_(self.addon.get_localepicker(), '')

def test_extract_not_language_pack(self):
File.objects.create(platform=self.platform_mob, version=self.version,
filename=self.xpi_path('langpack-localepicker'))
assert self.addon.get_localepicker()
filename=self.xpi_path('langpack-localepicker'),
status=amo.STATUS_PUBLIC)
assert self.addon.reload().get_localepicker()
self.addon.update(type=amo.ADDON_EXTENSION)
eq_(self.addon.get_localepicker(), '')

def test_extract_not_platform_mobile(self):
File.objects.create(platform=self.platform_all, version=self.version,
filename=self.xpi_path('langpack-localepicker'))
eq_(self.addon.get_localepicker(), '')
filename=self.xpi_path('langpack-localepicker'),
status=amo.STATUS_PUBLIC)
eq_(self.addon.reload().get_localepicker(), '')


class TestMarketplace(amo.tests.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion apps/amo/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def _get_changed_data(self):
"""
Model = self._meta.model
if self._changed_data is None:
changed = copy(super(AMOModelForm, self)._get_changed_data())
changed = copy(forms.ModelForm.changed_data.__get__(self))
fieldnames = [f.name for f in Model._meta.fields]
fields = [(name, Model._meta.get_field(name))
for name in changed if name in fieldnames]
Expand Down
4 changes: 2 additions & 2 deletions apps/amo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ class ManagerBase(caching.base.CachingManager, UncachedManagerBase):
function.
"""

def get_query_set(self):
qs = super(ManagerBase, self).get_query_set()
def get_queryset(self):
qs = super(ManagerBase, self).get_queryset()
if getattr(_locals, 'skip_cache', False):
qs = qs.no_cache()
return self._with_translations(qs)
Expand Down
2 changes: 1 addition & 1 deletion apps/amo/templates/amo/robots.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{% for a in apps -%}

Disallow: /{{ l }}/{{ a.short }}{{ url('search.search', add_prefix=False) }}
Disallow: /{{ l }}/{{ a.short }}{{ url('users.pwreset', add_prefix=False) }}
Disallow: /{{ l }}/{{ a.short }}{{ url('password_reset_form', add_prefix=False) }}
{% endfor %}

{% endfor %}
2 changes: 1 addition & 1 deletion apps/amo/tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ def test_absolutify():

def test_timesince():
month_ago = datetime.now() - timedelta(days=30)
eq_(helpers.timesince(month_ago), u'1 month ago')
eq_(helpers.timesince(month_ago), u'1 month ago')
eq_(helpers.timesince(None), u'')


Expand Down
3 changes: 0 additions & 3 deletions apps/amo/tests/test_readonly.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from django.utils import importlib

import MySQLdb as mysql
from lib.misc import safe_signals
from nose.tools import assert_raises, eq_
from pyquery import PyQuery as pq

Expand All @@ -30,7 +29,6 @@ class ReadOnlyModeTest(amo.tests.TestCase):
extra = ('amo.middleware.ReadOnlyMiddleware',)

def setUp(self):
safe_signals.Signal.send = safe_signals.unsafe_send
models.signals.pre_save.connect(self.db_error)
models.signals.pre_delete.connect(self.db_error)
self.old_settings = dict((k, quickcopy(getattr(settings, k)))
Expand All @@ -52,7 +50,6 @@ def tearDown(self):
pass
models.signals.pre_save.disconnect(self.db_error)
models.signals.pre_delete.disconnect(self.db_error)
safe_signals.Signal.send = safe_signals.safe_send

def db_error(self, *args, **kwargs):
raise mysql.OperationalError("You can't do this in read-only mode.")
Expand Down
3 changes: 2 additions & 1 deletion apps/amo/tests/test_send_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def setUp(self):
self._email_blacklist = list(getattr(settings, 'EMAIL_BLACKLIST', []))

def tearDown(self):
translation.activate('en_US')
settings.EMAIL_BLACKLIST = self._email_blacklist

def test_send_string(self):
Expand Down Expand Up @@ -202,7 +203,7 @@ def test_send_html_mail_jinja(self):

def test_send_attachment(self):
path = os.path.join(ATTACHMENTS_DIR, 'bacon.txt')
attachments = [(os.path.basename(path), storage.open(path),
attachments = [(os.path.basename(path), storage.open(path).read(),
mimetypes.guess_type(path)[0])]
send_mail('test subject', 'test body', from_email='a@example.com',
recipient_list=['b@example.com'], attachments=attachments)
Expand Down
4 changes: 2 additions & 2 deletions apps/amo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,12 +671,12 @@ def cache_ns_key(namespace, increment=False):
except ValueError:
log.info('Cache increment failed for key: %s. Resetting.' % ns_key)
ns_val = epoch(datetime.datetime.now())
cache.set(ns_key, ns_val, 0)
cache.set(ns_key, ns_val, None)
else:
ns_val = cache.get(ns_key)
if ns_val is None:
ns_val = epoch(datetime.datetime.now())
cache.set(ns_key, ns_val, 0)
cache.set(ns_key, ns_val, None)
return '%s:%s' % (ns_val, ns_key)


Expand Down
15 changes: 15 additions & 0 deletions apps/api/tests/test_urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from mock import Mock
from nose.tools import eq_

from amo.tests import TestCase

from ..urls import SwitchToDRF


class TestDRFSwitch(TestCase):

def test_piston_view(self):
view = SwitchToDRF('LanguageView')
eq_(view(Mock(), 1).__module__, 'django.http.response')
self.create_switch('drf', db=True)
eq_(view(Mock()).__module__, 'rest_framework.response')
3 changes: 2 additions & 1 deletion apps/api/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,8 @@ def test_search_no_localepicker(self):
def setup_localepicker(self, platform):
self.addon.update(type=amo.ADDON_LPAPP, status=amo.STATUS_PUBLIC)
version = self.addon.versions.all()[0]
File.objects.create(version=version, platform_id=platform)
File.objects.create(version=version, platform_id=platform,
status=amo.STATUS_PUBLIC)

def test_search_wrong_platform(self):
self.setup_localepicker(amo.PLATFORM_MAC.id)
Expand Down
12 changes: 4 additions & 8 deletions apps/browse/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,17 +294,13 @@ class PersonasFilter(BaseFilter):
def _filter(self, field):
qs = Addon.objects
if field == 'created':
return (qs.order_by('-created')
.with_index(addons='created_type_idx'))
return qs.order_by('-created')
elif field == 'popular':
return (qs.order_by('-persona__popularity')
.with_index(personas='personas_popularity_idx'))
return qs.order_by('-persona__popularity')
elif field == 'rating':
return (qs.order_by('-bayesian_rating')
.with_index(addons='rating_type_idx'))
return qs.order_by('-bayesian_rating')
else:
return (qs.order_by('-persona__movers')
.with_index(personas='personas_movers_idx'))
return qs.order_by('-persona__movers')


def personas_listing(request, category_slug=None):
Expand Down
7 changes: 5 additions & 2 deletions apps/devhub/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,11 @@ def __init__(self, *args, **kw):
self.initial = ([{} for _ in qs] +
[{'application': a.id} for a in apps])
self.extra = len(amo.APP_GUIDS) - len(self.forms)
self._construct_forms()
# After these changes, the forms need to be rebuilt. `forms`
# is a cached property, so we delete the existing cache and
# ask for a new one to be built.
del self.forms
self.forms

def clean(self):
if any(self.errors):
Expand Down Expand Up @@ -898,7 +902,6 @@ class PackagerCompatBaseFormSet(BaseFormSet):
def __init__(self, *args, **kw):
super(PackagerCompatBaseFormSet, self).__init__(*args, **kw)
self.initial = [{'application': a} for a in amo.APP_USAGE]
self._construct_forms()

def clean(self):
if any(self.errors):
Expand Down
2 changes: 1 addition & 1 deletion apps/devhub/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class AppLog(amo.models.ModelBase):
"""
This table is for indexing the activity log by app.
"""
addon = models.ForeignKey(Webapp)
addon = models.ForeignKey(Webapp, db_constraint=False)
activity_log = models.ForeignKey('ActivityLog')

class Meta:
Expand Down
1 change: 1 addition & 0 deletions apps/devhub/tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ def test_localize_name_description(self):
def test_reupload(self, save_persona_image_mock,
create_persona_preview_images_mock,
make_checksum_mock):
make_checksum_mock.return_value = 'checksumbeforeyouwrecksome'
data = self.get_dict(header_hash='y0l0', footer_hash='abab')
self.form = EditThemeForm(data, request=self.request,
instance=self.instance)
Expand Down
3 changes: 2 additions & 1 deletion apps/discovery/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,8 @@ def test_eula_trickle(self):


class TestMonthlyPick(amo.tests.TestCase):
fixtures = ['base/apps', 'base/addon_3615', 'discovery/discoverymodules']
fixtures = ['base/users', 'base/apps', 'base/addon_3615',
'discovery/discoverymodules']

def setUp(self):
self.url = reverse('discovery.pane.promos', args=['Darwin', '10.0'])
Expand Down
2 changes: 1 addition & 1 deletion apps/editors/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ class ReviewAddon(ReviewBase):
def __init__(self, *args, **kwargs):
super(ReviewAddon, self).__init__(*args, **kwargs)

self.is_upgrade = (self.addon.status is amo.STATUS_LITE_AND_NOMINATED
self.is_upgrade = (self.addon.status == amo.STATUS_LITE_AND_NOMINATED
and self.review_type == 'nominated')

def set_data(self, data):
Expand Down
8 changes: 4 additions & 4 deletions apps/editors/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ def get_total(cls, user):
if val is None:
val = 0

cache.set(key, val, 0)
cache.set(key, val, None)
return val

@classmethod
Expand All @@ -469,7 +469,7 @@ def get_recent(cls, user, limit=5, addon_type=None):
val.filter(addon__type=addon_type)

val = list(val[:limit])
cache.set(key, val, 0)
cache.set(key, val, None)
return val

@classmethod
Expand All @@ -492,7 +492,7 @@ def get_breakdown(cls, user):
"""
with amo.models.skip_cache():
val = list(ReviewerScore.objects.raw(sql, [user.id]))
cache.set(key, val, 0)
cache.set(key, val, None)
return val

@classmethod
Expand Down Expand Up @@ -605,7 +605,7 @@ def get_leaderboards(cls, user, days=7, types=None, addon_type=None):
'leader_near': leader_near,
'user_rank': user_rank,
}
cache.set(key, val, 0)
cache.set(key, val, None)
return val

@classmethod
Expand Down
8 changes: 4 additions & 4 deletions apps/editors/tests/test_views_themes.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,10 @@ def test_commit(self, copy_mock, create_preview_mock,
eq_(themes[4].addon.reload().current_version.version,
str(float(old_version) + 1))
else:
eq_(themes[0].addon.status, amo.STATUS_REVIEW_PENDING)
eq_(themes[1].addon.status, amo.STATUS_REVIEW_PENDING)
eq_(themes[2].addon.status, amo.STATUS_REJECTED)
eq_(themes[3].addon.status, amo.STATUS_REJECTED)
eq_(themes[0].addon.reload().status, amo.STATUS_REVIEW_PENDING)
eq_(themes[1].addon.reload().status, amo.STATUS_REVIEW_PENDING)
eq_(themes[2].addon.reload().status, amo.STATUS_REJECTED)
eq_(themes[3].addon.reload().status, amo.STATUS_REJECTED)
eq_(themes[4].addon.reload().status, amo.STATUS_PUBLIC)
eq_(ActivityLog.objects.count(), 4 if self.rereview else 5)

Expand Down
2 changes: 1 addition & 1 deletion apps/files/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ def test_directory(self):
def test_unicode(self):
self.file_viewer.src = unicode_filenames
self.file_viewer.extract()
res = self.client.get(self.file_url(iri_to_uri(u'\u1109\u1161\u11a9')))
res = self.client.get(self.file_url(u'\u1109\u1161\u11a9'))
eq_(res.status_code, 200)

def test_serve_no_token(self):
Expand Down
Loading