Skip to content

Commit

Permalink
- Fix test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
afabiani committed Mar 16, 2019
1 parent 85185f2 commit 70c31e3
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 49 deletions.
14 changes: 9 additions & 5 deletions geonode/security/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ class SessionControlMiddleware(object):
redirect_to = getattr(settings, 'LOGIN_URL', reverse('account_login'))

def process_request(self, request):
if request.user and request.user.is_authenticated:
if request and request.user:
if not request.user.is_active:
self.do_logout(request)
else:
elif check_ogc_backend(geoserver.BACKEND_PACKAGE):
try:
access_token = get_token_object_from_session(request.session)
except BaseException:
Expand All @@ -113,9 +113,13 @@ def do_logout(self, request):
except BaseException:
pass
finally:
from django.contrib import messages
from django.utils.translation import ugettext_noop as _
messages.warning(request, _("Session is Expired. Please login again!"))
try:
from django.contrib import messages
from django.utils.translation import ugettext_noop as _
messages.warning(request, _("Session is Expired. Please login again!"))
except BaseException:
pass

if not any(path.match(request.path) for path in white_list):
return HttpResponseRedirect(
'{login_path}?next={request_path}'.format(
Expand Down
92 changes: 48 additions & 44 deletions geonode/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,45 @@
},
}

#
# Test Settings
#

on_travis = ast.literal_eval(os.environ.get('ON_TRAVIS', 'False'))
core_tests = ast.literal_eval(os.environ.get('TEST_RUN_CORE', 'False'))
internal_apps_tests = ast.literal_eval(os.environ.get('TEST_RUN_INTERNAL_APPS', 'False'))
integration_tests = ast.literal_eval(os.environ.get('TEST_RUN_INTEGRATION', 'False'))
integration_csw_tests = ast.literal_eval(os.environ.get('TEST_RUN_INTEGRATION_CSW', 'False'))
integration_bdd_tests = ast.literal_eval(os.environ.get('TEST_RUN_INTEGRATION_BDD', 'False'))
selenium_tests = ast.literal_eval(os.environ.get('TEST_RUN_SELENIUM', 'False'))

# Setting a custom test runner to avoid running the tests for
# some problematic 3rd party apps
# Default Nose Test Suite
# TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'

# Django 1.11 ParallelTestSuite
TEST_RUNNER = 'geonode.tests.suite.runner.GeoNodeBaseSuiteDiscoverRunner'
TEST_RUNNER_KEEPDB = 0
TEST_RUNNER_PARALLEL = 1

# GeoNode test suite
# TEST_RUNNER = 'geonode.tests.suite.runner.DjangoParallelTestSuiteRunner'
# TEST_RUNNER_WORKER_MAX = 3
# TEST_RUNNER_WORKER_COUNT = 'auto'
# TEST_RUNNER_NOT_THREAD_SAFE = None
# TEST_RUNNER_PARENT_TIMEOUT = 10
# TEST_RUNNER_WORKER_TIMEOUT = 10

TEST = 'test' in sys.argv
INTEGRATION = 'geonode.tests.integration' in sys.argv

# Arguments for the test runner
NOSE_ARGS = [
'--nocapture',
'--detailed-errors',
]

#
# Customizations to built in Django settings required by GeoNode
#
Expand Down Expand Up @@ -538,20 +577,23 @@
# risks.
# 'geonode.middleware.PrintProxyMiddleware',

# This middleware checks for ACCESS_TOKEN validity and if expired forces
# user logout
'geonode.security.middleware.SessionControlMiddleware',

# If you use SessionAuthenticationMiddleware, be sure it appears before OAuth2TokenMiddleware.
# SessionAuthenticationMiddleware is NOT required for using
# django-oauth-toolkit.
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'oauth2_provider.middleware.OAuth2TokenMiddleware',
)

MESSAGE_STORAGE = 'django.contrib.messages.storage.session.SessionStorage'

# Security stuff
SESSION_EXPIRED_CONTROL_ENABLED = ast.literal_eval(os.environ.get('SESSION_EXPIRED_CONTROL_ENABLED', 'True'))

if SESSION_EXPIRED_CONTROL_ENABLED:
MESSAGE_STORAGE = 'django.contrib.messages.storage.session.SessionStorage'
# This middleware checks for ACCESS_TOKEN validity and if expired forces
# user logout
MIDDLEWARE_CLASSES += \
('geonode.security.middleware.SessionControlMiddleware',)

SESSION_COOKIE_SECURE = False
CSRF_COOKIE_SECURE = False
CSRF_COOKIE_HTTPONLY = False
Expand Down Expand Up @@ -664,44 +706,6 @@
'THEME_ACCOUNT_CONTACT_EMAIL', 'admin@example.com'
)

#
# Test Settings
#

on_travis = ast.literal_eval(os.environ.get('ON_TRAVIS', 'False'))
core_tests = ast.literal_eval(os.environ.get('TEST_RUN_CORE', 'False'))
internal_apps_tests = ast.literal_eval(os.environ.get('TEST_RUN_INTERNAL_APPS', 'False'))
integration_tests = ast.literal_eval(os.environ.get('TEST_RUN_INTEGRATION', 'False'))
integration_csw_tests = ast.literal_eval(os.environ.get('TEST_RUN_INTEGRATION_CSW', 'False'))
integration_bdd_tests = ast.literal_eval(os.environ.get('TEST_RUN_INTEGRATION_BDD', 'False'))

# Setting a custom test runner to avoid running the tests for
# some problematic 3rd party apps
# Default Nose Test Suite
# TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'

# Django 1.11 ParallelTestSuite
TEST_RUNNER = 'geonode.tests.suite.runner.GeoNodeBaseSuiteDiscoverRunner'
TEST_RUNNER_KEEPDB = 0
TEST_RUNNER_PARALLEL = 1

# GeoNode test suite
# TEST_RUNNER = 'geonode.tests.suite.runner.DjangoParallelTestSuiteRunner'
# TEST_RUNNER_WORKER_MAX = 3
# TEST_RUNNER_WORKER_COUNT = 'auto'
# TEST_RUNNER_NOT_THREAD_SAFE = None
# TEST_RUNNER_PARENT_TIMEOUT = 10
# TEST_RUNNER_WORKER_TIMEOUT = 10

TEST = 'test' in sys.argv
INTEGRATION = 'geonode.tests.integration' in sys.argv

# Arguments for the test runner
NOSE_ARGS = [
'--nocapture',
'--detailed-errors',
]

#
# GeoNode specific settings
#
Expand Down
3 changes: 3 additions & 0 deletions geonode/tests/smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ def setUp(self):
)
self.thread = first_message.thread

@on_ogc_backend(geoserver.BACKEND_PACKAGE)
def test_inbox_renders(self):
logged_in = self.client.login(
username=self.first_user.username, password=self.user_password)
Expand All @@ -353,6 +354,7 @@ def test_inbox_redirects_when_not_logged_in(self):
"{}{}?next=http%3A//testserver{}".format(settings.SITEURL[:-1], reverse("account_login"), target_url)
)

@on_ogc_backend(geoserver.BACKEND_PACKAGE)
def test_new_message_renders(self):
logged_in = self.client.login(
username=self.first_user.username, password=self.user_password)
Expand All @@ -373,6 +375,7 @@ def test_new_message_redirects_when_not_logged_in(self):
"{}{}?next=http%3A//testserver{}".format(settings.SITEURL[:-1], reverse("account_login"), target_url)
)

@on_ogc_backend(geoserver.BACKEND_PACKAGE)
def test_thread_detail_renders(self):
logged_in = self.client.login(
username=self.first_user.username, password=self.user_password)
Expand Down

0 comments on commit 70c31e3

Please sign in to comment.