Skip to content

Commit

Permalink
Merge pull request omab#7 from hachiyanagi-ks/develop/cypress/fix-uui…
Browse files Browse the repository at this point in the history
…d-slugify

Fix slugify for PY2 str omab#6
  • Loading branch information
hachiyanagi-ks committed Mar 30, 2016
2 parents b85720f + a1c0916 commit a0c7af8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
16 changes: 16 additions & 0 deletions social/tests/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,22 @@ def test_random_username(self):
})
self.do_login()

def test_no_username(self):
"""
Tests for backend that does not return email.
There is a case in which email can not be acquired(e.g Facebook).
"""
_user_data_body = json.loads(self.user_data_body)
del _user_data_body['email']
del _user_data_body['login']

self.strategy.set_settings({
'SOCIAL_AUTH_CLEAN_USERNAMES': False,
'SOCIAL_AUTH_SLUGIFY_USERNAMES': True
})
# Verify that exception does not occur
self.do_login(after_complete_checks=False, user_data_body=json.dumps(_user_data_body))


class RepeatedUsernameTest(BaseActionTest):
def test_random_username(self):
Expand Down
11 changes: 3 additions & 8 deletions social/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,9 @@ def is_active(self):

class SlugifyTest(unittest.TestCase):
def test_slugify_formats(self):
if PY3:
self.assertEqual(slugify('FooBar'), 'foobar')
self.assertEqual(slugify('Foo Bar'), 'foo-bar')
self.assertEqual(slugify('Foo (Bar)'), 'foo-bar')
else:
self.assertEqual(slugify('FooBar'.decode('utf-8')), 'foobar')
self.assertEqual(slugify('Foo Bar'.decode('utf-8')), 'foo-bar')
self.assertEqual(slugify('Foo (Bar)'.decode('utf-8')), 'foo-bar')
self.assertEqual(slugify('FooBar'), 'foobar')
self.assertEqual(slugify('Foo Bar'), 'foo-bar')
self.assertEqual(slugify('Foo (Bar)'), 'foo-bar')


class BuildAbsoluteURITest(unittest.TestCase):
Expand Down
3 changes: 3 additions & 0 deletions social/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ def slugify(value):
"""Converts to lowercase, removes non-word characters (alphanumerics
and underscores) and converts spaces to hyphens. Also strips leading
and trailing whitespace."""
# convert str of Python2 to unicode
if six.PY2 and not isinstance(value, six.text_type):
value = six.text_type(value)
value = unicodedata.normalize('NFKD', value) \
.encode('ascii', 'ignore') \
.decode('ascii')
Expand Down

0 comments on commit a0c7af8

Please sign in to comment.