1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-31 23:51:09 +03:00

Fix ad_hoc.py tests again

Credential fix
This commit is contained in:
Akita Noek 2016-03-23 12:09:04 -04:00
parent 7fa47c1b38
commit 8afa10466f

View File

@ -69,10 +69,10 @@ class QueueTestMixin(object):
if getattr(self, 'redis_process', None):
self.redis_process.kill()
self.redis_process = None
# The observed effect of not calling terminate_queue() if you call start_queue() are
# an hang on test cleanup database delete. Thus, to ensure terminate_queue() is called
# an hang on test cleanup database delete. Thus, to ensure terminate_queue() is called
# whenever start_queue() is called just inherit from this class when you want to use the queue.
class QueueStartStopTestMixin(QueueTestMixin):
def setUp(self):
@ -129,7 +129,7 @@ class BaseTestMixin(QueueTestMixin, MockCommonlySlowTestMixin):
settings.CELERY_UNIT_TEST = True
settings.SYSTEM_UUID='00000000-0000-0000-0000-000000000000'
settings.BROKER_URL='redis://localhost:16379/'
# Create unique random consumer and queue ports for zeromq callback.
if settings.CALLBACK_CONSUMER_PORT:
callback_port = random.randint(55700, 55799)
@ -181,7 +181,7 @@ class BaseTestMixin(QueueTestMixin, MockCommonlySlowTestMixin):
return __name__ + '-generated-' + string + rnd_str
def create_test_license_file(self, instance_count=10000, license_date=int(time.time() + 3600), features=None):
writer = LicenseWriter(
writer = LicenseWriter(
company_name='AWX',
contact_name='AWX Admin',
contact_email='awx@example.com',
@ -196,7 +196,7 @@ class BaseTestMixin(QueueTestMixin, MockCommonlySlowTestMixin):
os.environ['AWX_LICENSE_FILE'] = license_path
def create_basic_license_file(self, instance_count=100, license_date=int(time.time() + 3600)):
writer = LicenseWriter(
writer = LicenseWriter(
company_name='AWX',
contact_name='AWX Admin',
contact_email='awx@example.com',
@ -208,7 +208,7 @@ class BaseTestMixin(QueueTestMixin, MockCommonlySlowTestMixin):
writer.write_file(license_path)
self._temp_paths.append(license_path)
os.environ['AWX_LICENSE_FILE'] = license_path
def create_expired_license_file(self, instance_count=1000, grace_period=False):
license_date = time.time() - 1
if not grace_period:
@ -383,7 +383,11 @@ class BaseTestMixin(QueueTestMixin, MockCommonlySlowTestMixin):
'vault_password': '',
}
opts.update(kwargs)
return Credential.objects.create(**opts)
user = opts['user']
del opts['user']
cred = Credential.objects.create(**opts)
cred.owner_role.members.add(user)
return cred
def setup_instances(self):
instance = Instance(uuid=settings.SYSTEM_UUID, primary=True, hostname='127.0.0.1')
@ -422,7 +426,7 @@ class BaseTestMixin(QueueTestMixin, MockCommonlySlowTestMixin):
def get_invalid_credentials(self):
return ('random', 'combination')
def _generic_rest(self, url, data=None, expect=204, auth=None, method=None,
data_type=None, accept=None, remote_addr=None,
return_response_object=False, client_kwargs=None):
@ -517,7 +521,7 @@ class BaseTestMixin(QueueTestMixin, MockCommonlySlowTestMixin):
return self._generic_rest(url, data=None, expect=expect, auth=auth,
method='head', accept=accept,
remote_addr=remote_addr)
def get(self, url, expect=200, auth=None, accept=None, remote_addr=None, client_kwargs={}):
return self._generic_rest(url, data=None, expect=expect, auth=auth,
method='get', accept=accept,
@ -658,7 +662,7 @@ class BaseTestMixin(QueueTestMixin, MockCommonlySlowTestMixin):
else:
msg += 'Found %d occurances of "%s" instead of %d in: "%s"' % (count_actual, substr, count, string)
self.assertEqual(count_actual, count, msg)
def check_job_result(self, job, expected='successful', expect_stdout=True,
expect_traceback=False):
msg = u'job status is %s, expected %s' % (job.status, expected)