mirror of
https://github.com/ansible/awx.git
synced 2026-05-19 14:57:39 -02:30
Updating tests, changing 'method' to 'http_method'
This commit is contained in:
@@ -23,8 +23,8 @@ class WebhookBackend(AWXBaseEmailBackend):
|
|||||||
recipient_parameter = "url"
|
recipient_parameter = "url"
|
||||||
sender_parameter = None
|
sender_parameter = None
|
||||||
|
|
||||||
def __init__(self, headers, method, disable_ssl_verification=False, fail_silently=False, username=None, password=None, **kwargs):
|
def __init__(self, headers, http_method, disable_ssl_verification=False, fail_silently=False, username=None, password=None, **kwargs):
|
||||||
self.method = method
|
self.http_method = http_method
|
||||||
self.disable_ssl_verification = disable_ssl_verification
|
self.disable_ssl_verification = disable_ssl_verification
|
||||||
self.headers = headers
|
self.headers = headers
|
||||||
self.username = username
|
self.username = username
|
||||||
@@ -38,9 +38,9 @@ class WebhookBackend(AWXBaseEmailBackend):
|
|||||||
sent_messages = 0
|
sent_messages = 0
|
||||||
if 'User-Agent' not in self.headers:
|
if 'User-Agent' not in self.headers:
|
||||||
self.headers['User-Agent'] = "Tower {}".format(get_awx_version())
|
self.headers['User-Agent'] = "Tower {}".format(get_awx_version())
|
||||||
if self.method.lower() not in ('put', 'post'):
|
if self.http_method.lower() not in ('put', 'post'):
|
||||||
raise ValueError("Method must be either 'POST' or 'PUT'.")
|
raise ValueError("HTTP method must be either 'POST' or 'PUT'.")
|
||||||
chosen_method = getattr(requests, self.method.lower(), None)
|
chosen_method = getattr(requests, self.http_method.lower(), None)
|
||||||
for m in messages:
|
for m in messages:
|
||||||
if chosen_method is not None:
|
if chosen_method is not None:
|
||||||
r = chosen_method("{}".format(m.recipients()[0]),
|
r = chosen_method("{}".format(m.recipients()[0]),
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ def mk_credential(name, credential_type='ssh', persisted=True):
|
|||||||
def mk_notification_template(name, notification_type='webhook', configuration=None, organization=None, persisted=True):
|
def mk_notification_template(name, notification_type='webhook', configuration=None, organization=None, persisted=True):
|
||||||
nt = NotificationTemplate(name=name)
|
nt = NotificationTemplate(name=name)
|
||||||
nt.notification_type = notification_type
|
nt.notification_type = notification_type
|
||||||
nt.notification_configuration = configuration or dict(url="http://localhost", headers={"Test": "Header"})
|
nt.notification_configuration = configuration or dict(url="http://localhost", username="", password="", headers={"Test": "Header"})
|
||||||
|
|
||||||
if organization is not None:
|
if organization is not None:
|
||||||
nt.organization = organization
|
nt.organization = organization
|
||||||
@@ -216,7 +216,7 @@ def mk_workflow_job_template(name, extra_vars='', spec=None, organization=None,
|
|||||||
|
|
||||||
|
|
||||||
def mk_workflow_job_template_node(workflow_job_template=None,
|
def mk_workflow_job_template_node(workflow_job_template=None,
|
||||||
unified_job_template=None,
|
unified_job_template=None,
|
||||||
success_nodes=None,
|
success_nodes=None,
|
||||||
failure_nodes=None,
|
failure_nodes=None,
|
||||||
always_nodes=None,
|
always_nodes=None,
|
||||||
@@ -231,11 +231,11 @@ def mk_workflow_job_template_node(workflow_job_template=None,
|
|||||||
return workflow_node
|
return workflow_node
|
||||||
|
|
||||||
|
|
||||||
def mk_workflow_job_node(unified_job_template=None,
|
def mk_workflow_job_node(unified_job_template=None,
|
||||||
success_nodes=None,
|
success_nodes=None,
|
||||||
failure_nodes=None,
|
failure_nodes=None,
|
||||||
always_nodes=None,
|
always_nodes=None,
|
||||||
workflow_job=None,
|
workflow_job=None,
|
||||||
job=None,
|
job=None,
|
||||||
persisted=True):
|
persisted=True):
|
||||||
workflow_node = WorkflowJobNode(unified_job_template=unified_job_template,
|
workflow_node = WorkflowJobNode(unified_job_template=unified_job_template,
|
||||||
@@ -247,4 +247,3 @@ def mk_workflow_job_node(unified_job_template=None,
|
|||||||
if persisted:
|
if persisted:
|
||||||
workflow_node.save()
|
workflow_node.save()
|
||||||
return workflow_node
|
return workflow_node
|
||||||
|
|
||||||
|
|||||||
@@ -385,7 +385,9 @@ def notification_template(organization):
|
|||||||
organization=organization,
|
organization=organization,
|
||||||
notification_type="webhook",
|
notification_type="webhook",
|
||||||
notification_configuration=dict(url="http://localhost",
|
notification_configuration=dict(url="http://localhost",
|
||||||
headers={"Test": "Header"}))
|
username="",
|
||||||
|
password="",
|
||||||
|
headers={"Test": "Header",}))
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ def test_inherited_notification_templates(get, post, user, organization, project
|
|||||||
isrc.save()
|
isrc.save()
|
||||||
jt = JobTemplate.objects.create(name='test', inventory=i, project=project, playbook='debug.yml')
|
jt = JobTemplate.objects.create(name='test', inventory=i, project=project, playbook='debug.yml')
|
||||||
jt.save()
|
jt.save()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_notification_template_simple_patch(patch, notification_template, admin):
|
def test_notification_template_simple_patch(patch, notification_template, admin):
|
||||||
@@ -124,7 +124,7 @@ def test_custom_environment_injection(post, user, organization):
|
|||||||
organization=organization.id,
|
organization=organization.id,
|
||||||
notification_type="webhook",
|
notification_type="webhook",
|
||||||
notification_configuration=dict(url="https://example.org", disable_ssl_verification=False,
|
notification_configuration=dict(url="https://example.org", disable_ssl_verification=False,
|
||||||
headers={"Test": "Header"})),
|
http_method="POST", headers={"Test": "Header"})),
|
||||||
u)
|
u)
|
||||||
assert response.status_code == 201
|
assert response.status_code == 201
|
||||||
template = NotificationTemplate.objects.get(pk=response.data['id'])
|
template = NotificationTemplate.objects.get(pk=response.data['id'])
|
||||||
|
|||||||
Reference in New Issue
Block a user