mirror of
https://github.com/ansible/awx.git
synced 2026-05-08 01:47:35 -02:30
Broke out URI test helper from test base.py
This commit is contained in:
43
awx/main/tests/URI.py
Normal file
43
awx/main/tests/URI.py
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
# Helps with test cases.
|
||||||
|
# Save all components of a uri (i.e. scheme, username, password, etc.) so that
|
||||||
|
# when we construct a uri string and decompose it, we can verify the decomposition
|
||||||
|
class URI(object):
|
||||||
|
DEFAULTS = {
|
||||||
|
'scheme' : 'http',
|
||||||
|
'username' : 'MYUSERNAME',
|
||||||
|
'password' : 'MYPASSWORD',
|
||||||
|
'host' : 'host.com',
|
||||||
|
}
|
||||||
|
|
||||||
|
def __init__(self, description='N/A', scheme=DEFAULTS['scheme'], username=DEFAULTS['username'], password=DEFAULTS['password'], host=DEFAULTS['host']):
|
||||||
|
self.description = description
|
||||||
|
self.scheme = scheme
|
||||||
|
self.username = username
|
||||||
|
self.password = password
|
||||||
|
self.host = host
|
||||||
|
|
||||||
|
def get_uri(self):
|
||||||
|
uri = "%s://" % self.scheme
|
||||||
|
if self.username:
|
||||||
|
uri += "%s" % self.username
|
||||||
|
if self.password:
|
||||||
|
uri += ":%s" % self.password
|
||||||
|
if (self.username or self.password) and self.host is not None:
|
||||||
|
uri += "@%s" % self.host
|
||||||
|
elif self.host is not None:
|
||||||
|
uri += "%s" % self.host
|
||||||
|
return uri
|
||||||
|
|
||||||
|
def get_secret_count(self):
|
||||||
|
secret_count = 0
|
||||||
|
if self.username:
|
||||||
|
secret_count += 1
|
||||||
|
if self.password:
|
||||||
|
secret_count += 1
|
||||||
|
return secret_count
|
||||||
|
|
||||||
|
def __string__(self):
|
||||||
|
return self.get_uri()
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return self.get_uri()
|
||||||
@@ -35,6 +35,7 @@ from awx.main.management.commands.run_task_system import run_taskmanager
|
|||||||
from awx.main.utils import get_ansible_version
|
from awx.main.utils import get_ansible_version
|
||||||
from awx.main.task_engine import TaskEngager as LicenseWriter
|
from awx.main.task_engine import TaskEngager as LicenseWriter
|
||||||
from awx.sso.backends import LDAPSettings
|
from awx.sso.backends import LDAPSettings
|
||||||
|
from awx.main.tests.URI import URI # noqa
|
||||||
|
|
||||||
TEST_PLAYBOOK = '''- hosts: mygroup
|
TEST_PLAYBOOK = '''- hosts: mygroup
|
||||||
gather_facts: false
|
gather_facts: false
|
||||||
@@ -732,48 +733,3 @@ class BaseJobExecutionTest(QueueStartStopTestMixin, BaseLiveServerTest):
|
|||||||
'''
|
'''
|
||||||
Base class for celery task tests.
|
Base class for celery task tests.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
# Helps with test cases.
|
|
||||||
# Save all components of a uri (i.e. scheme, username, password, etc.) so that
|
|
||||||
# when we construct a uri string and decompose it, we can verify the decomposition
|
|
||||||
class URI(object):
|
|
||||||
DEFAULTS = {
|
|
||||||
'scheme' : 'http',
|
|
||||||
'username' : 'MYUSERNAME',
|
|
||||||
'password' : 'MYPASSWORD',
|
|
||||||
'host' : 'host.com',
|
|
||||||
}
|
|
||||||
|
|
||||||
def __init__(self, description='N/A', scheme=DEFAULTS['scheme'], username=DEFAULTS['username'], password=DEFAULTS['password'], host=DEFAULTS['host']):
|
|
||||||
self.description = description
|
|
||||||
self.scheme = scheme
|
|
||||||
self.username = username
|
|
||||||
self.password = password
|
|
||||||
self.host = host
|
|
||||||
|
|
||||||
def get_uri(self):
|
|
||||||
uri = "%s://" % self.scheme
|
|
||||||
if self.username:
|
|
||||||
uri += "%s" % self.username
|
|
||||||
if self.password:
|
|
||||||
uri += ":%s" % self.password
|
|
||||||
if (self.username or self.password) and self.host is not None:
|
|
||||||
uri += "@%s" % self.host
|
|
||||||
elif self.host is not None:
|
|
||||||
uri += "%s" % self.host
|
|
||||||
return uri
|
|
||||||
|
|
||||||
def get_secret_count(self):
|
|
||||||
secret_count = 0
|
|
||||||
if self.username:
|
|
||||||
secret_count += 1
|
|
||||||
if self.password:
|
|
||||||
secret_count += 1
|
|
||||||
return secret_count
|
|
||||||
|
|
||||||
def __string__(self):
|
|
||||||
return self.get_uri()
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return self.get_uri()
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user