Skip to content

Commit

Permalink
Close #78. Lazy-load API client
Browse files Browse the repository at this point in the history
  • Loading branch information
fcurella committed Jun 28, 2018
1 parent 7c31603 commit 7553f0a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
17 changes: 12 additions & 5 deletions test_plus/compat.py
Expand Up @@ -4,11 +4,18 @@
from django.core.urlresolvers import reverse, NoReverseMatch # noqa

try:
from rest_framework.test import APIClient
import rest_framework # noqa
DRF = True
except ImportError:
from django.core.exceptions import ImproperlyConfigured

def APIClient(*args, **kwargs):
raise ImproperlyConfigured('django-rest-framework must be installed in order to use APITestCase.')
DRF = False


def get_api_client():
try:
from rest_framework.test import APIClient
except ImportError:
from django.core.exceptions import ImproperlyConfigured

def APIClient(*args, **kwargs):
raise ImproperlyConfigured('django-rest-framework must be installed in order to use APITestCase.')
return APIClient
6 changes: 4 additions & 2 deletions test_plus/test.py
Expand Up @@ -13,7 +13,7 @@
from django.test.utils import CaptureQueriesContext
from django.utils.functional import curry

from .compat import reverse, NoReverseMatch, APIClient
from .compat import reverse, NoReverseMatch, get_api_client


class NoPreviousResponse(Exception):
Expand Down Expand Up @@ -375,7 +375,9 @@ def __init__(self, *args, **kwargs):


class APITestCase(TestCase):
client_class = APIClient
def __init__(self, *args, **kwargs):
self.client_class = get_api_client()
super(APITestCase, self).__init__(*args, **kwargs)


# Note this class inherits from TestCase defined above.
Expand Down

0 comments on commit 7553f0a

Please sign in to comment.