diff --git a/test/test_fedora/test_cryptutil.py b/test/test_fedora/test_cryptutil.py index df33052..a84cbd6 100644 --- a/test/test_fedora/test_cryptutil.py +++ b/test/test_fedora/test_cryptutil.py @@ -16,6 +16,11 @@ from __future__ import unicode_literals import unittest +try: + from unittest import skipIf +except ImportError: + from unittest2 import skipIf + try: import django except ImportError: @@ -28,7 +33,7 @@ # settings for configuration; probably ok, since this is likely # only used within django -@unittest.skipIf(django is None, 'Requires Django') +@skipIf(django is None, 'Requires Django') class CryptTest(unittest.TestCase): def test_to_blocksize(self): diff --git a/test/test_fedora/test_templatetags.py b/test/test_fedora/test_templatetags.py index 4721625..be33382 100644 --- a/test/test_fedora/test_templatetags.py +++ b/test/test_fedora/test_templatetags.py @@ -15,6 +15,11 @@ # limitations under the License. import unittest +try: + from unittest import skipIf +except ImportError: + from unittest2 import skipIf + from mock import Mock try: @@ -38,7 +43,7 @@ def value(self): return self._value -@unittest.skipIf(django is None, 'Requires Django') +@skipIf(django is None, 'Requires Django') class TemplateTagTest(unittest.TestCase): def test_parse_fedora_access(self): TEMPLATE_TEXT = """ diff --git a/test/test_fedora/test_util.py b/test/test_fedora/test_util.py index 5219b2e..67bee5b 100644 --- a/test/test_fedora/test_util.py +++ b/test/test_fedora/test_util.py @@ -22,7 +22,12 @@ except ImportError: django = None -from unittest import TestCase, skipIf +from unittest import TestCase +try: + from unittest import skipIf +except ImportError: + from unittest2 import skipIf + import requests diff --git a/test/test_fedora/test_views.py b/test/test_fedora/test_views.py index 81ce613..d5799c8 100644 --- a/test/test_fedora/test_views.py +++ b/test/test_fedora/test_views.py @@ -17,7 +17,10 @@ from mock import Mock, patch import os import unittest -from unittest import skipIf +try: + from unittest import skipIf +except ImportError: + from unittest2 import skipIf try: import django diff --git a/test/test_indexdata/test_views.py b/test/test_indexdata/test_views.py index 350e657..3f2eb9d 100644 --- a/test/test_indexdata/test_views.py +++ b/test/test_indexdata/test_views.py @@ -17,29 +17,40 @@ import base64 import json from mock import patch, Mock -from unittest import skipIf +try: + from unittest import skipIf +except ImportError: + from unittest2 import skipIf try: import django from django.conf import settings from django.http import Http404, HttpRequest from django.test import TestCase - from django.test.utils import override_settings from django.utils.encoding import force_bytes from eulfedora.indexdata.views import index_config, index_data except ImportError: + # no version of django available django = None + from unittest import TestCase +try: + # only available in 1.8 + + from django.test.utils import override_settings +except ImportError: # dummy do-nothing decator for override settings def override_settings(*args, **kwargs): def wrap(f): - def wrapped_f(*args, **kwargs): - f(*args, **kwargs) - return wrapped_f + with patch(settings) as mocksettings: + for key, val in kwargs.iteritems(): + setattr(mocksettings, key, val) + + def wrapped_f(*args, **kwargs): + f(*args, **kwargs) + return wrapped_f return wrap - from unittest import TestCase from eulfedora.models import DigitalObject, ContentModel @@ -89,7 +100,7 @@ def test_index_details(self): # self.assertRaises(AttributeError, index_config, self.request) # Test with this IP not allowed to hit the service. - #settings.EUL_INDEXER_ALLOWED_IPS = ['0.13.23.134'] + # settings.EUL_INDEXER_ALLOWED_IPS = ['0.13.23.134'] with override_settings(EUL_INDEXER_ALLOWED_IPS=['0.13.23.134']): response = index_config(self.request) expected, got = 403, response.status_code @@ -103,7 +114,7 @@ def test_index_details(self): # Test with this IP allowed to hit the view. with override_settings(EUL_INDEXER_ALLOWED_IPS=['0.13.23.134', - self.request_ip]): + self.request_ip]): response = index_config(self.request) expected, got = 200, response.status_code self.assertEqual(expected, got, @@ -131,7 +142,7 @@ def test_index_details(self): # Test with 'EUL_INDEXER_CONTENT_MODELS' setting configured to override autodetect. with override_settings(EUL_INDEXER_ALLOWED_IPS='ANY', - EUL_INDEXER_CONTENT_MODELS=[ + EUL_INDEXER_CONTENT_MODELS=[ ['content-model_1', 'content-model_2'], ['content-model_3']]): response = index_config(self.request) expected, got = 200, response.status_code