added tests for no_auth feature
authorRodney Ewing <ewing.rj@gmail.com>
Fri, 17 May 2013 17:20:46 +0000 (10:20 -0700)
committerRodney Ewing <ewing.rj@gmail.com>
Fri, 24 May 2013 23:52:48 +0000 (16:52 -0700)
mediagoblin/tests/auth_configs/__init__.py [new file with mode: 0644]
mediagoblin/tests/auth_configs/basic_auth_appconfig.ini [new file with mode: 0644]
mediagoblin/tests/auth_configs/no_auth_false_no_auth_plugin_appconfig.ini [new file with mode: 0644]
mediagoblin/tests/auth_configs/no_auth_true_no_auth_plugin_appconfig.ini [new file with mode: 0644]
mediagoblin/tests/test_auth.py
mediagoblin/tests/test_basic_auth.py

diff --git a/mediagoblin/tests/auth_configs/__init__.py b/mediagoblin/tests/auth_configs/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/mediagoblin/tests/auth_configs/basic_auth_appconfig.ini b/mediagoblin/tests/auth_configs/basic_auth_appconfig.ini
new file mode 100644 (file)
index 0000000..b15ae1f
--- /dev/null
@@ -0,0 +1,28 @@
+[mediagoblin]
+direct_remote_path = /test_static/
+email_sender_address = "notice@mediagoblin.example.org"
+email_debug_mode = true
+no_auth = false
+
+# TODO: Switch to using an in-memory database
+sql_engine = "sqlite:///%(here)s/test_user_dev/mediagoblin.db"
+
+# Celery shouldn't be set up by the application as it's setup via
+# mediagoblin.init.celery.from_celery
+celery_setup_elsewhere = true
+
+[storage:publicstore]
+base_dir = %(here)s/test_user_dev/media/public
+base_url = /mgoblin_media/
+
+[storage:queuestore]
+base_dir = %(here)s/test_user_dev/media/queue
+
+[celery]
+CELERY_ALWAYS_EAGER = true
+CELERY_RESULT_DBURI = "sqlite:///%(here)s/test_user_dev/celery.db"
+BROKER_HOST = "sqlite:///%(here)s/test_user_dev/kombu.db"
+
+[plugins]
+[[mediagoblin.plugins.basic_auth]]
+
diff --git a/mediagoblin/tests/auth_configs/no_auth_false_no_auth_plugin_appconfig.ini b/mediagoblin/tests/auth_configs/no_auth_false_no_auth_plugin_appconfig.ini
new file mode 100644 (file)
index 0000000..719ff26
--- /dev/null
@@ -0,0 +1,27 @@
+[mediagoblin]
+direct_remote_path = /test_static/
+email_sender_address = "notice@mediagoblin.example.org"
+email_debug_mode = true
+no_auth = false
+
+# TODO: Switch to using an in-memory database
+sql_engine = "sqlite:///%(here)s/test_user_dev/mediagoblin.db"
+
+# Celery shouldn't be set up by the application as it's setup via
+# mediagoblin.init.celery.from_celery
+celery_setup_elsewhere = true
+
+[storage:publicstore]
+base_dir = %(here)s/test_user_dev/media/public
+base_url = /mgoblin_media/
+
+[storage:queuestore]
+base_dir = %(here)s/test_user_dev/media/queue
+
+[celery]
+CELERY_ALWAYS_EAGER = true
+CELERY_RESULT_DBURI = "sqlite:///%(here)s/test_user_dev/celery.db"
+BROKER_HOST = "sqlite:///%(here)s/test_user_dev/kombu.db"
+
+[plugins]
+
diff --git a/mediagoblin/tests/auth_configs/no_auth_true_no_auth_plugin_appconfig.ini b/mediagoblin/tests/auth_configs/no_auth_true_no_auth_plugin_appconfig.ini
new file mode 100644 (file)
index 0000000..6c0d524
--- /dev/null
@@ -0,0 +1,27 @@
+[mediagoblin]
+direct_remote_path = /test_static/
+email_sender_address = "notice@mediagoblin.example.org"
+email_debug_mode = true
+no_auth = true
+
+# TODO: Switch to using an in-memory database
+sql_engine = "sqlite:///%(here)s/test_user_dev/mediagoblin.db"
+
+# Celery shouldn't be set up by the application as it's setup via
+# mediagoblin.init.celery.from_celery
+celery_setup_elsewhere = true
+
+[storage:publicstore]
+base_dir = %(here)s/test_user_dev/media/public
+base_url = /mgoblin_media/
+
+[storage:queuestore]
+base_dir = %(here)s/test_user_dev/media/queue
+
+[celery]
+CELERY_ALWAYS_EAGER = true
+CELERY_RESULT_DBURI = "sqlite:///%(here)s/test_user_dev/celery.db"
+BROKER_HOST = "sqlite:///%(here)s/test_user_dev/kombu.db"
+
+[plugins]
+
index a916534065441546d699b82d0ef38459b18fd2b8..c67d523f163bd82abafe823a3975379c2101ae56 100644 (file)
 #
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
+import pkg_resources
+import pytest
 import urlparse
 
 from mediagoblin import mg_globals
 from mediagoblin.db.models import User
-from mediagoblin.tests.tools import fixture_add_user
+from mediagoblin.tests.tools import get_app, fixture_add_user
 from mediagoblin.tools import template, mail
+from mediagoblin.auth.tools import AuthError
+from mediagoblin import auth
 
 
 def test_register_views(test_app):
@@ -273,3 +276,52 @@ def test_authentication_views(test_app):
             'password': 'toast',
             'next' : '/u/chris/'})
     assert urlparse.urlsplit(response.location)[2] == '/u/chris/'
+
+
+# App with no_auth=false and no auth plugin enabled
+def no_auth_false_no_auth_plugin_app(request):
+    return get_app(
+        request,
+        mgoblin_config=pkg_resources.resource_filename(
+            'mediagoblin.tests.auth_configs',
+            'no_auth_false_no_auth_plugin_appconfig.ini'))
+
+
+def test_no_auth_false_no_auth_plugin_raises(request):
+    with pytest.raises(AuthError):
+        no_auth_false_no_auth_plugin_app(request)
+
+
+@pytest.fixture()
+def no_auth_true_no_auth_plugin_app(request):
+    return get_app(
+        request,
+        mgoblin_config=pkg_resources.resource_filename(
+            'mediagoblin.tests.auth_configs',
+            'no_auth_true_no_auth_plugin_appconfig.ini'))
+
+
+def test_no_auth_true_no_auth_plugin_app(no_auth_true_no_auth_plugin_app):
+    # app.auth should = false
+    assert mg_globals.app.auth is False
+
+    # Try to visit register page
+    template.clear_test_template_context()
+    response = no_auth_true_no_auth_plugin_app.get('/auth/register/')
+    response.follow()
+
+    # Correct redirect?
+    assert urlparse.urlsplit(response.location)[2] == '/'
+    assert 'mediagoblin/root.html' in template.TEMPLATE_TEST_CONTEXT
+
+    # Try to vist login page
+    template.clear_test_template_context()
+    response = no_auth_true_no_auth_plugin_app.get('/auth/login/')
+    response.follow()
+
+    # Correct redirect?
+    assert urlparse.urlsplit(response.location)[2] == '/'
+    assert 'mediagoblin/root.html' in template.TEMPLATE_TEST_CONTEXT
+
+    ## Test check_login should return False
+    assert auth.check_login('test', 'simple') is False
index 20098ab7eab40f5d6941c022021d6e164410266a..a985c3157f7fdc6bbe6c30b4772d078c73ae272d 100644 (file)
@@ -72,15 +72,15 @@ def context_modified_app(request):
     return get_app(
         request,
         mgoblin_config=pkg_resources.resource_filename(
-            'mediagoblin.tests', 'basic_auth_appconfig.ini'))
+            'mediagoblin.tests.auth_configs', 'basic_auth_appconfig.ini'))
 
 
 def test_fp_view(context_modified_app):
     ### Oops, forgot the password
-    # -------------------
     ## Register a user
     fixture_add_user(active_user=True)
 
+    # -------------------
     template.clear_test_template_context()
     response = context_modified_app.post(
         '/auth/forgot_password/',