Move django import and initialization inside the offline client class

This allows to import the class without triggering the import and
initialization of django and instead deferring it to when (and if) the
class is instanciated.

Change-Id: I79be90eb877f21b5254f116e51cc78b310c8674c
This commit is contained in:
David Moreau Simard 2018-09-12 09:14:38 -04:00
parent ee86bb5cfe
commit e4d2b27a0f
No known key found for this signature in database
GPG Key ID: 33A07694CBB71ECC
1 changed files with 17 additions and 16 deletions

View File

@ -22,26 +22,27 @@ import json
import logging
import os
try:
from django import setup as django_setup
from django.core.management import execute_from_command_line
from django.test import Client
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ara.server.settings')
# Automatically create the database and run migrations (is there a better way?)
execute_from_command_line(['django', 'migrate'])
# Set up the things Django needs
django_setup()
except ImportError as e:
print('ERROR: The offline client requires ara-server to be installed')
raise e
class AraOfflineClient(object):
def __init__(self):
self.log = logging.getLogger(__name__)
try:
from django import setup as django_setup
from django.core.management import execute_from_command_line
from django.test import Client
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ara.server.settings')
# Automatically create the database and run migrations (is there a better way?)
execute_from_command_line(['django', 'migrate'])
# Set up the things Django needs
django_setup()
except ImportError as e:
self.log.error('The offline client requires ara-server to be installed')
raise e
self.client = Client()
def _request(self, method, endpoint, **kwargs):