From b6b4818987760933c3149403fe926abf434d6b48 Mon Sep 17 00:00:00 2001 From: David Moreau Simard Date: Mon, 25 Jun 2018 10:37:18 -0400 Subject: [PATCH] Only run the Django bootstrapping once in the offline client Change-Id: Idcf388a8dbeef418400546078a78d8d8620dc950 --- ara/clients/offline.py | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/ara/clients/offline.py b/ara/clients/offline.py index b9c4b64..b5709c6 100644 --- a/ara/clients/offline.py +++ b/ara/clients/offline.py @@ -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)