Test with short and long username
authorJonathan Sandoval <jsandoval@utp.edu.co>
Thu, 7 Apr 2016 16:55:45 +0000 (11:55 -0500)
committerJonathan Sandoval <jsandoval@utp.edu.co>
Thu, 7 Apr 2016 16:55:45 +0000 (11:55 -0500)
mediagoblin/tests/test_auth.py

index cb971fdbb8783cc9aebdb3ccd238b018638fc87e..544cf4e09c1fc1c91ffc9e3101e284d17b10114c 100644 (file)
@@ -1,4 +1,3 @@
-
 # GNU MediaGoblin -- federated, autonomous media hosting
 # Copyright (C) 2011, 2012 MediaGoblin contributors.  See AUTHORS.
 #
@@ -373,6 +372,51 @@ def test_authentication_views(test_app):
     assert not form.username.data == u'ANDREW'
     assert form.username.data == u'andrew'
 
+    # Successful login with short user
+    # ----------------
+    short_user = fixture_add_user(username=u'me', password=u'sho')
+    template.clear_test_template_context()
+    response = test_app.post(
+        '/auth/login/', {
+            'username': u'me',
+            'password': 'sho'})
+
+    context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/login.html']
+    form = context['login_form']
+    # User should be redirected
+    print('errors are', form.username.errors)
+    response.follow()
+    assert urlparse.urlsplit(response.location)[2] == '/'
+    assert 'mediagoblin/root.html' in template.TEMPLATE_TEST_CONTEXT
+
+    # Make sure user is in the session
+    context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/root.html']
+    session = context['request'].session
+    assert session['user_id'] == six.text_type(short_user.id)
+
+    # Successful login with long user
+    # ----------------
+    long_user = fixture_add_user(
+        username=u'realllylonguser@reallylongdomain.com.co', password=u'sho')
+    template.clear_test_template_context()
+    response = test_app.post(
+        '/auth/login/', {
+            'username': u'me',
+            'password': 'sho'})
+
+    context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/auth/login.html']
+    form = context['login_form']
+    # User should be redirected
+    print('errors are', form.username.errors)
+    response.follow()
+    assert urlparse.urlsplit(response.location)[2] == '/'
+    assert 'mediagoblin/root.html' in template.TEMPLATE_TEST_CONTEXT
+
+    # Make sure user is in the session
+    context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/root.html']
+    session = context['request'].session
+    assert session['user_id'] == six.text_type(short_user.id)
+
 @pytest.fixture()
 def authentication_disabled_app(request):
     return get_app(