Only run the Django bootstrapping once in the offline client

Change-Id: Idcf388a8dbeef418400546078a78d8d8620dc950
This commit is contained in:
David Moreau Simard 2018-06-25 10:37:18 -04:00
parent d54b3f8e59
commit b6b4818987
1 changed files with 9 additions and 14 deletions

View File

@ -26,23 +26,18 @@ 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()
class AraOfflineClient(object):
def __init__(self):
self.log = logging.getLogger('ara.clients.offline')
self.client = self._bootstrap_django_client()
def _bootstrap_django_client(self):
self.log.debug('Bootstrapping Django offline 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()
return Client()
self.log = logging.getLogger(__name__)
self.client = Client()
def _request(self, method, endpoint, **kwargs):
func = getattr(self.client, method)