Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix to handle odd Accept-Language headers

  • Loading branch information...
commit 4d3b93e166b56467fd613f87b38cc212d4237915 1 parent 37fba75
@jrconlin authored
View
1  campaign.ini
@@ -11,6 +11,7 @@ pyramid.debug_routematch = false
pyramid.debug_templates = true
pyramid.default_locale_name = en
+#db.backend = campaign.storage.sql.Storage
db.type = sqlite
db.db = /tmp/campaigns.sqlite
#db.type = mysql
View
3  campaign/storage/memcache_sql.py
@@ -38,7 +38,8 @@ def _memcache_key(self, data):
# significant set of characters.
maxLen = int(245 / len(fields)) - 1
for field in fields:
- key.append(data.get(field, 'NONE')[:maxLen])
+ val = data.get(field) or 'NONE'
+ key.append(val[:maxLen])
return 'ca_' + '-'.join(key)
def get_announce(self, data):
View
50 campaign/tests/test_views.py
@@ -57,7 +57,6 @@ class ViewTest(unittest2.TestCase):
def req(self, matchdict={}, user_id=None, headers=None, **kw):
-
class Reg(dict):
settings = {}
@@ -80,8 +79,8 @@ def __init__(self, settings=None, **kw):
def setUp(self):
self.config = testing.setUp()
tsettings = TConfig({'db.type': 'sqlite',
- 'db.db': '/tmp/test.db',
- 'logging.use_metlog': False})
+ 'db.db': '/tmp/test.db',
+ 'logging.use_metlog': False})
self.storage = Storage(config=tsettings)
self.logger = Logging(tsettings, None)
for diff in self.diffs:
@@ -95,36 +94,40 @@ def tearDown(self):
def test_get_announcements(self):
# normal number
response = views.get_announcements(self.req(matchdict={'channel': 'a',
- 'platform': 'a', 'version': 0}))
+ 'platform': 'a', 'version': 0}))
+ eq_(len(response['announcements']), 3)
+ response = views.get_announcements(self.req(matchdict={'channel': 'a',
+ 'platform': 'a', 'version': 0},
+ headers={'Accept-Language': 'en'}))
eq_(len(response['announcements']), 3)
# idle number
response = views.get_announcements(self.req(matchdict={'channel': 'a',
'platform': 'a', 'version': 0, 'idle_time': 6}))
eq_(len(response['announcements']), 4)
self.assertRaises(http.HTTPNotModified,
- views.get_announcements,
- self.req(matchdict={'channel': 'a',
- 'platform': 'a', 'version': 0},
- headers={'If-Modified-Since':
- time.strftime('%a %b %d %H:%M:%S %Y',
- datetime.datetime.fromtimestamp(
- time.time()+60).timetuple())}))
+ views.get_announcements,
+ self.req(matchdict={'channel': 'a',
+ 'platform': 'a', 'version': 0},
+ headers={'If-Modified-Since':
+ time.strftime('%a %b %d %H:%M:%S %Y',
+ datetime.datetime.fromtimestamp(
+ time.time() + 60).timetuple())}))
self.storage.purge()
self.assertRaises(http.HTTPNoContent,
- views.get_announcements,
- self.req(matchdict={'channel': 'z', 'platform':'z',
- 'version': 'z'}))
-
+ views.get_announcements,
+ self.req(matchdict={'channel': 'z', 'platform': 'z',
+ 'version': 'z'}))
def test_get_all(self):
self.assertRaises(http.HTTPUnauthorized,
- views.get_all_announcements,
- self.req())
+ views.get_all_announcements,
+ self.req())
# scan for include.js or 'test="login"' id?
# try with a 'valid' user id
self.assertRaises(http.HTTPUnauthorized,
- views.get_all_announcements,
- self.req(matchdict={}, user_id='invalid@example.com'))
+ views.get_all_announcements,
+ self.req(matchdict={},
+ user_id='invalid@example.com'))
# try successful json
req = self.req(matchdict={}, user_id='foo@mozilla.com')
req.accept_encoding = 'application/javascript'
@@ -137,9 +140,9 @@ def test_handle_redir(self):
record = response[0]
req = self.req(matchdict={'token': record['id']})
self.assertRaises(http.HTTPTemporaryRedirect,
- views.handle_redir, req)
+ views.handle_redir, req)
self.assertRaises(http.HTTPNotFound, views.handle_redir,
- self.req(matchdict={'token': 'Invalid Token'}))
+ self.req(matchdict={'token': 'Invalid Token'}))
def test_admin_page(self):
req = self.req()
@@ -154,7 +157,8 @@ def test_admin_page(self):
def test_manage_announce(self):
# test assertion post
req = self.req(matchdict={'channel': 'c', 'title': 'Goat',
- 'note': 'Ready for sacrifice'}, user_id='foo@mozilla.com')
+ 'note': 'Ready for sacrifice'},
+ user_id='foo@mozilla.com')
response = views.manage_announce(req)
# test create
time.sleep(2) # Give the db a second to write the record.
@@ -167,7 +171,7 @@ def test_manage_announce(self):
break
self.assertIsNotNone(goat)
req = self.req(params={'delete': goat['id']},
- user_id='foo@mozilla.com')
+ user_id='foo@mozilla.com')
self.assertRaises(http.HTTPOk, views.del_announce, req)
time.sleep(2) # Give the db a second to write the record.
req = self.req(matchdict={'token': goat['id']})
View
4 campaign/views.py
@@ -61,7 +61,9 @@ def get_lang_loc(request):
(lang, loc) = langloc.split('-')
else:
(lang, loc) = (langloc, None)
- return {'lang': lang.lower(), 'locale': loc.upper()}
+ if loc:
+ loc = loc.upper()
+ return {'lang': lang.lower(), 'locale': loc}
def get_last_accessed(request):
View
2  prod-reqs.txt
@@ -36,7 +36,7 @@ requests==0.14.1
simplejson==2.6.2
six==1.2.0
translationstring==1.1
-umemcache=1.6
+umemcache==1.6
unittest2==0.5.1
venusian==1.0a7
waitress==0.8.1
Please sign in to comment.
Something went wrong with that request. Please try again.