Skip to content

Commit

Permalink
Fix skipIf import to work under python 2.6
Browse files Browse the repository at this point in the history
  • Loading branch information
rlskoeser committed Jul 25, 2016
1 parent bc4941d commit 0937fd7
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 13 deletions.
7 changes: 6 additions & 1 deletion test/test_fedora/test_cryptutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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):
Expand Down
7 changes: 6 additions & 1 deletion test/test_fedora/test_templatetags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 = """
Expand Down
7 changes: 6 additions & 1 deletion test/test_fedora/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
5 changes: 4 additions & 1 deletion test/test_fedora/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 20 additions & 9 deletions test/test_indexdata/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0937fd7

Please sign in to comment.