Permalink
Browse files

Upgraded to pip (non-vendor) Playdoh layout

  • Loading branch information...
1 parent fcb876c commit 5b1b57722205dd40dfc6105c03ef56163449fb28 @kumar303 committed Jan 11, 2013
Showing with 223 additions and 636 deletions.
  1. +0 −6 .gitmodules
  2. +3 −3 README.md
  3. +81 −0 inapp_pay_test/base/middleware.py
  4. 0 {vendor-local/moz_inapp_pay-be659d9/moz_inapp_pay/djangoapp → inapp_pay_test/base/tests}/__init__.py
  5. +70 −0 inapp_pay_test/base/tests/test_middleware.py
  6. +30 −2 inapp_pay_test/settings/base.py
  7. +1 −3 requirements/compiled.txt
  8. +2 −3 requirements/dev.txt
  9. +36 −1 requirements/prod.txt
  10. +0 −10 vendor-local/moz_inapp_pay-be659d9/.gitignore
  11. +0 −112 vendor-local/moz_inapp_pay-be659d9/README.md
  12. +0 −2 vendor-local/moz_inapp_pay-be659d9/moz_inapp_pay/__init__.py
  13. +0 −2 vendor-local/moz_inapp_pay-be659d9/moz_inapp_pay/djangoapp/models.py
  14. +0 −6 vendor-local/moz_inapp_pay-be659d9/moz_inapp_pay/djangoapp/signals.py
  15. +0 −11 vendor-local/moz_inapp_pay-be659d9/moz_inapp_pay/djangoapp/urls.py
  16. +0 −42 vendor-local/moz_inapp_pay-be659d9/moz_inapp_pay/djangoapp/views.py
  17. +0 −15 vendor-local/moz_inapp_pay-be659d9/moz_inapp_pay/exc.py
  18. +0 −19 vendor-local/moz_inapp_pay-be659d9/moz_inapp_pay/processor.py
  19. +0 −126 vendor-local/moz_inapp_pay-be659d9/moz_inapp_pay/verify.py
  20. +0 −16 vendor-local/moz_inapp_pay-be659d9/setup.py
  21. +0 −70 vendor-local/moz_inapp_pay-be659d9/tests/__init__.py
  22. +0 −35 vendor-local/moz_inapp_pay-be659d9/tests/test_processor.py
  23. +0 −140 vendor-local/moz_inapp_pay-be659d9/tests/test_verify.py
  24. +0 −9 vendor-local/moz_inapp_pay-be659d9/tox.ini
  25. +0 −1 vendor-local/pyjwt
  26. +0 −2 vendor-local/vendor.pth
View
@@ -1,6 +0,0 @@
-[submodule "vendor"]
- path = vendor
- url = git://github.com/mozilla/playdoh-lib.git
-[submodule "vendor-local/pyjwt"]
- path = vendor-local/pyjwt
- url = git://github.com/kumar303/pyjwt.git
View
@@ -8,16 +8,16 @@ It is used for diagnostics / testing in the Marketplace development cycle.
Requirements:
-* Python 2.6 or greater
+* Python 2.7 or greater
* swig (to build m2crypto)
Installation:
- git clone --recursive git://github.com/kumar303/inapp-pay-test.git
+ git clone git://github.com/kumar303/inapp-pay-test.git
cd inapp-pay-test
virtualenv Env
source Env/bin/activate
- pip install -r requirements/compiled.txt
+ pip install --no-deps --exists-action=w -r requirements/dev.txt
cp inapp_pay_test/settings/local.py-dist inapp_pay_test/settings/local.py
python manage.py syncdb
python manage.py runserver
@@ -1,6 +1,12 @@
import logging
import sys
+from django.conf import settings
+from django.utils.cache import patch_vary_headers
+from django.utils.translation.trans_real import parse_accept_lang_header
+
+import tower
+
log = logging.getLogger('playdoh')
@@ -9,3 +15,78 @@ class LogExceptionsMiddleware:
def process_exception(self, request, exception):
log.error('in %s' % request.path, exc_info=sys.exc_info())
+
+
+class LocaleMiddleware(object):
+ """
+ 1. Search for the locale.
+ 2. Save it in the request.
+ """
+ def __init__(self):
+ self.locale_from_accept = False
+
+ def get_language(self, request):
+ """
+ Return a locale code we support on the site using the
+ user's Accept-Language header to determine which is best. This
+ mostly follows the RFCs but read bug 439568 for details.
+ """
+ if request.META.get('HTTP_ACCEPT_LANGUAGE'):
+ best = self.get_best_language(
+ request.META['HTTP_ACCEPT_LANGUAGE'])
+ if best:
+ return best
+ return settings.LANGUAGE_CODE
+
+ def get_best_language(self, accept_lang):
+ """
+ Given an Accept-Language header, return the best-matching language.
+ """
+ LUM = settings.LANGUAGE_URL_MAP
+ langs = LUM.copy()
+ langs.update((k.split('-')[0], v) for k, v in LUM.items() if
+ k.split('-')[0] not in langs)
+ ranked = parse_accept_lang_header(accept_lang)
+ for lang, _ in ranked:
+ lang = lang.lower()
+ if lang in langs:
+ return langs[lang]
+ pre = lang.split('-')[0]
+ if pre in langs:
+ return langs[pre]
+ # Could not find an acceptable language.
+ return False
+
+ def find_from_input(self, lang):
+ """
+ Return a supported locale given user input.
+
+ When not supported, returns the default locale.
+ """
+ if lang in settings.LANGUAGE_URL_MAP:
+ return settings.LANGUAGE_URL_MAP[lang]
+ else:
+ # en-xx -> en-US, en-GB, ...
+ supported = [settings.LANGUAGE_URL_MAP[x] for
+ x in settings.LANGUAGE_URL_MAP if
+ x.split('-', 1)[0] == lang.lower().split('-', 1)[0]]
+ if len(supported):
+ return supported[0]
+ return settings.LANGUAGE_CODE
+
+ def process_request(self, request):
+ self.locale_from_accept = False
+ if 'lang' in request.GET:
+ locale = self.find_from_input(request.GET['lang'])
+ else:
+ locale = self.get_language(request)
+ if locale:
+ self.locale_from_accept = True
+ # TODO(Kumar) set/check cookie?
+ request.locale = locale
+ tower.activate(locale)
+
+ def process_response(self, request, response):
+ if self.locale_from_accept:
+ patch_vary_headers(response, ['Accept-Language'])
+ return response
@@ -0,0 +1,70 @@
+from django import http
+from django.conf import settings
+from django.test import TestCase
+from django.test.client import RequestFactory
+
+import fudge
+from nose.tools import eq_
+
+from inapp_pay_test.base.middleware import LocaleMiddleware
+
+
+class TestLocaleMiddleware(TestCase):
+
+ def process(self, **request_kw):
+ loc = LocaleMiddleware()
+ req = RequestFactory().get('/', **request_kw)
+ loc.process_request(req)
+ resp = http.HttpResponse('output')
+ loc.process_response(req, resp)
+ return req.locale, resp
+
+ def test_accept_exact(self):
+ with self.settings(LANGUAGE_CODE='ja'):
+ eq_(self.process(HTTP_ACCEPT_LANGUAGE='en-us')[0], 'en-US')
+
+ @fudge.patch('tower.activate')
+ def test_activate_tower(self, fake_activate):
+ fake_activate.expects_call()
+ self.process(HTTP_ACCEPT_LANGUAGE='en-us')
+
+ def test_accept_prefix(self):
+ with self.settings(LANGUAGE_CODE='ja'):
+ eq_(self.process(HTTP_ACCEPT_LANGUAGE='en')[0], 'en-US')
+
+ def test_accept_first_prefix_wins(self):
+ # See bug 439568.
+ eq_(self.process(HTTP_ACCEPT_LANGUAGE='en,ja;q=0.9,fr;q=0.8,de;'
+ 'q=0.7,es;q=0.6,it;q=0.5,nl;'
+ 'q=0.4,sv;q=0.3,nb;q=0.2')[0],
+ 'en-US')
+
+ def test_accept_not_supported(self):
+ eq_(self.process(HTTP_ACCEPT_LANGUAGE='foo')[0],
+ settings.LANGUAGE_CODE)
+
+ def test_accept_varies_cache(self):
+ locale, resp = self.process(HTTP_ACCEPT_LANGUAGE='en-us')
+ eq_(resp['Vary'], 'Accept-Language')
+
+ def test_default_to_lang_code(self):
+ with self.settings(LANGUAGE_CODE='de'):
+ eq_(self.process(HTTP_ACCEPT_LANGUAGE='foo')[0], 'de')
+
+ def test_lang_exact(self):
+ with self.settings(LANGUAGE_CODE='ja'):
+ eq_(self.process(data=dict(lang='en-us'))[0], 'en-US')
+
+ def test_lang_wrong_suffix(self):
+ with self.settings(LANGUAGE_CODE='ja'):
+ eq_(self.process(data=dict(lang='en-xx'))[0], 'en-US')
+
+ def test_lang_prefix(self):
+ with self.settings(LANGUAGE_CODE='ja'):
+ eq_(self.process(data=dict(lang='en'))[0], 'en-US')
+
+ def test_lang_non_existant(self):
+ eq_(self.process(data=dict(lang='xx'))[0], settings.LANGUAGE_CODE)
+
+ def test_no_input(self):
+ eq_(self.process()[0], settings.LANGUAGE_CODE)
@@ -18,6 +18,11 @@
},
}
+# URL that handles the media served from MEDIA_ROOT. Make sure to use a
+# trailing slash if there is a path component (optional in other cases).
+# Examples: "http://media.lawrence.com", "http://example.com/media/"
+MEDIA_URL = '/media/'
+
# Bundles is a dictionary of two dictionaries, css and js, which list css files
# and js files that can be bundled together by the minify app.
MINIFY_BUNDLES = {
@@ -45,6 +50,19 @@
}
}
+# jingo-minify: Style sheet media attribute default
+CSS_MEDIA_DEFAULT = 'all'
+
+# Tell jingo-minify to use the media URL instead.
+JINGO_MINIFY_USE_STATIC = False
+
+# LESS CSS OPTIONS (Debug only)
+LESS_PREPROCESS = False # Compile LESS with Node, rather than client-side JS?
+LESS_LIVE_REFRESH = False # Refresh the CSS on save?
+LESS_BIN = 'lessc'
+UGLIFY_BIN = 'uglifyjs'
+CLEANCSS_BIN = 'cleancss'
+
# Defines the views served for root URLs.
ROOT_URLCONF = 'inapp_pay_test.urls'
@@ -57,9 +75,19 @@
'django.contrib.admin',
]
-MIDDLEWARE_CLASSES = list(MIDDLEWARE_CLASSES) + [
+MIDDLEWARE_CLASSES = (
+ 'inapp_pay_test.base.middleware.LocaleMiddleware',
+ 'multidb.middleware.PinningRouterMiddleware',
+ 'django.middleware.common.CommonMiddleware',
+ 'django.contrib.sessions.middleware.SessionMiddleware',
+ 'django.contrib.auth.middleware.AuthenticationMiddleware',
+ 'session_csrf.CsrfMiddleware', # Must be after auth middleware.
+ 'django.contrib.messages.middleware.MessageMiddleware',
+ 'commonware.middleware.FrameOptionsHeader',
+ 'mobility.middleware.DetectMobileMiddleware',
+ 'mobility.middleware.XMobileMiddleware',
'inapp_pay_test.base.middleware.LogExceptionsMiddleware'
-]
+)
# Because Jinja2 is the default template loader, add any non-Jinja templated
@@ -1,4 +1,2 @@
--r ../vendor/src/funfactory/funfactory/requirements/compiled.txt
-
-# For JWT
+Jinja2==2.6
M2Crypto>=0.20.0
View
@@ -1,6 +1,5 @@
# This file pulls in everything a developer needs. If it's a basic package
# needed to run the site, it belongs in requirements/prod.txt. If it's a
# package for developers (testing, docs, etc.), it goes in this file.
-
--r ../vendor/src/funfactory/funfactory/requirements/compiled.txt
--r ../vendor/src/funfactory/funfactory/requirements/dev.txt
+-r prod.txt
+-r compiled.txt
View
@@ -1 +1,36 @@
--r ../vendor/src/funfactory/funfactory/requirements/prod.txt
+amqplib==1.0.2
+anyjson==0.3.3
+Babel==0.9.6
+celery==2.5.1
+Django==1.4.3
+django-celery==2.2.4
+django-mobility==0.1
+django-multidb-router==0.5
+django-nose==1.1
+fudge==1.0.3
+funfactory==2.1.1
+GitPython==0.1.7
+jingo==0.4
+kombu==2.1.2
+moz_inapp_pay==1.0.2
+nose==1.2.1
+ordereddict==1.1
+django-picklefield==0.2.1
+python-dateutil==2.1
+python-memcached==1.48
+requests==0.14.2
+schematic==0.2
+six==1.2.0
+translate-toolkit==1.9.0
+
+-e git://github.com/clouserw/tower.git@7711557f55fefa9526402b2731879edf9b128381#egg=tower
+-e git://github.com/jbalogh/test-utils.git@3c2214d193d1b0c0d74c77b3731c8afb0173e669#egg=test-utils
+-e git://github.com/jsocol/commonware.git@1b2e7623782c7aaca5401714758845cf9fcee621#egg=commonware
+-e git://github.com/jsocol/django-cronjobs.git@cfda8176c5c3a50d1b58fcf57e87e23c467789bd#egg=django-cronjobs
+-e git://github.com/jsocol/jingo-minify.git@d2ffefbd31e5035873083107e86893be302ce452#egg=jingo-minify
+-e git://github.com/fwenzel/django-sha2.git@f4519bf0cc9b1dd7a7d78394fa4aec4504bc86e9#egg=django-sha2
+-e git://github.com/fwenzel/django-mozilla-product-details.git@36ef06539d6b34c4f345fd0d3e16937d0db9a752#egg=django-mozilla-product-details
+-e git://github.com/mozilla/django-browserid.git@72009f28f55c91c8ed1bb79930bc84f88dc00211#egg=django-browserid
+-e git://github.com/mozilla/django-session-csrf.git@94e2858a427a6b278e41c051643f3c226f096f21#egg=django-session-csrf
+-e git://github.com/mozilla/nuggets.git@96e80a64aa4bfcfef4f43fc3ab6966450ccd7325#egg=nuggets
+-e git://github.com/rtilder/pyjwt.git@aa3be513795c1a623dfc61c6c0a688198ea5d303#egg=PyJWT
@@ -1,10 +0,0 @@
-*.py[co]
-*.sw[po]
-.coverage
-.DS_Store
-.noseids
-.tox
-*~
-*.mo
-*.db
-dist
Oops, something went wrong.

0 comments on commit 5b1b577

Please sign in to comment.