Mercurial > public > sg101
comparison wiki/tests/test_middleware.py @ 1174:ba3230aba90c
Fix unicode error with wiki cookie processing
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Thu, 07 Jun 2018 19:53:13 -0500 |
parents | 3782fa705821 |
children |
comparison
equal
deleted
inserted
replaced
1173:a1a223ab0c8f | 1174:ba3230aba90c |
---|---|
1 # coding=utf-8 | |
1 """ | 2 """ |
2 Tests for the wiki integration application. | 3 Tests for the wiki integration application. |
3 | 4 |
4 """ | 5 """ |
5 import hashlib | 6 import hashlib |
18 | 19 |
19 class MiddleWareTestCase(TestCase): | 20 class MiddleWareTestCase(TestCase): |
20 | 21 |
21 def setUp(self): | 22 def setUp(self): |
22 self.factory = RequestFactory() | 23 self.factory = RequestFactory() |
23 self.user = User.objects.create_user('test_user', 'test@example.com', | 24 self.user = User.objects.create_user(u'Sérgio', u'test@example.com', |
24 'password') | 25 u'password') |
25 self.conn = get_redis_connection() | 26 self.conn = get_redis_connection() |
26 self.mw = WikiMiddleware() | 27 self.mw = WikiMiddleware() |
27 | 28 |
28 def tearDown(self): | 29 def tearDown(self): |
29 self.conn.delete(settings.WIKI_REDIS_SET) | 30 self.conn.delete(settings.WIKI_REDIS_SET) |
50 self.assertEqual(cookie['path'], '/') | 51 self.assertEqual(cookie['path'], '/') |
51 self.assertEqual(cookie['max-age'], settings.WIKI_COOKIE_AGE) | 52 self.assertEqual(cookie['max-age'], settings.WIKI_COOKIE_AGE) |
52 | 53 |
53 cookie_val = cookie.value | 54 cookie_val = cookie.value |
54 try: | 55 try: |
55 user, email, key = cookie_val.split('#') | 56 user, email, key = cookie_val.decode('utf-8').split('#') |
56 except ValueError: | 57 except ValueError: |
57 self.fail('invalid cookie value') | 58 self.fail('invalid cookie value') |
58 else: | 59 else: |
59 self.assertEqual(user, self.user.username) | 60 self.assertEqual(user, self.user.username) |
60 self.assertEqual(email, self.user.email) | 61 self.assertEqual(email, self.user.email) |