Clear cache between tests or when license is updated.

This commit is contained in:
Chris Church
2016-03-06 18:00:49 -05:00
parent 0687168e5e
commit 3bb14e2f72
2 changed files with 9 additions and 0 deletions

View File

@@ -18,6 +18,7 @@ from collections import OrderedDict
# Django # Django
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core.cache import cache
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.core.exceptions import FieldError from django.core.exceptions import FieldError
from django.db.models import Q, Count from django.db.models import Q, Count
@@ -263,6 +264,8 @@ class ApiV1ConfigView(APIView):
if license_data['valid_key']: if license_data['valid_key']:
tower_settings.LICENSE = data_actual tower_settings.LICENSE = data_actual
tower_settings.TOWER_URL_BASE = "{}://{}".format(request.scheme, request.get_host()) tower_settings.TOWER_URL_BASE = "{}://{}".format(request.scheme, request.get_host())
# Clear cache when license is updated.
cache.clear()
return Response(license_data) return Response(license_data)
return Response({"error": "Invalid license"}, status=status.HTTP_400_BAD_REQUEST) return Response({"error": "Invalid license"}, status=status.HTTP_400_BAD_REQUEST)
@@ -282,6 +285,8 @@ class ApiV1ConfigView(APIView):
break break
TowerSettings.objects.filter(key="LICENSE").delete() TowerSettings.objects.filter(key="LICENSE").delete()
# Clear cache when license is updated.
cache.clear()
# Only stop mongod if license removal succeeded # Only stop mongod if license removal succeeded
if has_error is None: if has_error is None:

View File

@@ -24,6 +24,7 @@ import yaml
import django.test import django.test
from django.conf import settings, UserSettingsHolder from django.conf import settings, UserSettingsHolder
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core.cache import cache
from django.test.client import Client from django.test.client import Client
from django.test.utils import override_settings from django.test.utils import override_settings
from django.utils.encoding import force_text from django.utils.encoding import force_text
@@ -152,6 +153,7 @@ class BaseTestMixin(QueueTestMixin, MockCommonlySlowTestMixin):
'LOCATION': 'unittests' 'LOCATION': 'unittests'
} }
} }
cache.clear()
self._start_time = time.time() self._start_time = time.time()
def tearDown(self): def tearDown(self):
@@ -195,6 +197,7 @@ class BaseTestMixin(QueueTestMixin, MockCommonlySlowTestMixin):
writer.write_file(license_path) writer.write_file(license_path)
self._temp_paths.append(license_path) self._temp_paths.append(license_path)
os.environ['AWX_LICENSE_FILE'] = license_path os.environ['AWX_LICENSE_FILE'] = license_path
cache.clear()
def create_basic_license_file(self, instance_count=100, license_date=int(time.time() + 3600)): def create_basic_license_file(self, instance_count=100, license_date=int(time.time() + 3600)):
writer = LicenseWriter( writer = LicenseWriter(
@@ -209,6 +212,7 @@ class BaseTestMixin(QueueTestMixin, MockCommonlySlowTestMixin):
writer.write_file(license_path) writer.write_file(license_path)
self._temp_paths.append(license_path) self._temp_paths.append(license_path)
os.environ['AWX_LICENSE_FILE'] = license_path os.environ['AWX_LICENSE_FILE'] = license_path
cache.clear()
def create_expired_license_file(self, instance_count=1000, grace_period=False): def create_expired_license_file(self, instance_count=1000, grace_period=False):
license_date = time.time() - 1 license_date = time.time() - 1