From 6e9f74eb17b5e7b546001ad2642c2c6ded685e8c Mon Sep 17 00:00:00 2001 From: beeankha Date: Mon, 24 Jun 2019 12:13:22 -0400 Subject: [PATCH] Updating tests, changing 'method' to 'http_method' --- awx/main/notifications/webhook_backend.py | 10 +++++----- awx/main/tests/factories/fixtures.py | 9 ++++----- awx/main/tests/functional/conftest.py | 4 +++- awx/main/tests/functional/test_notifications.py | 4 ++-- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/awx/main/notifications/webhook_backend.py b/awx/main/notifications/webhook_backend.py index a10004ffc8..f13f96f235 100644 --- a/awx/main/notifications/webhook_backend.py +++ b/awx/main/notifications/webhook_backend.py @@ -23,8 +23,8 @@ class WebhookBackend(AWXBaseEmailBackend): recipient_parameter = "url" sender_parameter = None - def __init__(self, headers, method, disable_ssl_verification=False, fail_silently=False, username=None, password=None, **kwargs): - self.method = method + def __init__(self, headers, http_method, disable_ssl_verification=False, fail_silently=False, username=None, password=None, **kwargs): + self.http_method = http_method self.disable_ssl_verification = disable_ssl_verification self.headers = headers self.username = username @@ -38,9 +38,9 @@ class WebhookBackend(AWXBaseEmailBackend): sent_messages = 0 if 'User-Agent' not in self.headers: self.headers['User-Agent'] = "Tower {}".format(get_awx_version()) - if self.method.lower() not in ('put', 'post'): - raise ValueError("Method must be either 'POST' or 'PUT'.") - chosen_method = getattr(requests, self.method.lower(), None) + if self.http_method.lower() not in ('put', 'post'): + raise ValueError("HTTP method must be either 'POST' or 'PUT'.") + chosen_method = getattr(requests, self.http_method.lower(), None) for m in messages: if chosen_method is not None: r = chosen_method("{}".format(m.recipients()[0]), diff --git a/awx/main/tests/factories/fixtures.py b/awx/main/tests/factories/fixtures.py index d4ad255e4a..fe61410908 100644 --- a/awx/main/tests/factories/fixtures.py +++ b/awx/main/tests/factories/fixtures.py @@ -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): nt = NotificationTemplate(name=name) 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: 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, - unified_job_template=None, + unified_job_template=None, success_nodes=None, failure_nodes=None, always_nodes=None, @@ -231,11 +231,11 @@ def mk_workflow_job_template_node(workflow_job_template=None, return workflow_node -def mk_workflow_job_node(unified_job_template=None, +def mk_workflow_job_node(unified_job_template=None, success_nodes=None, failure_nodes=None, always_nodes=None, - workflow_job=None, + workflow_job=None, job=None, persisted=True): workflow_node = WorkflowJobNode(unified_job_template=unified_job_template, @@ -247,4 +247,3 @@ def mk_workflow_job_node(unified_job_template=None, if persisted: workflow_node.save() return workflow_node - diff --git a/awx/main/tests/functional/conftest.py b/awx/main/tests/functional/conftest.py index c924034bdd..314ef94713 100644 --- a/awx/main/tests/functional/conftest.py +++ b/awx/main/tests/functional/conftest.py @@ -385,7 +385,9 @@ def notification_template(organization): organization=organization, notification_type="webhook", notification_configuration=dict(url="http://localhost", - headers={"Test": "Header"})) + username="", + password="", + headers={"Test": "Header",})) @pytest.fixture diff --git a/awx/main/tests/functional/test_notifications.py b/awx/main/tests/functional/test_notifications.py index 576bc71a7a..308e52c2c7 100644 --- a/awx/main/tests/functional/test_notifications.py +++ b/awx/main/tests/functional/test_notifications.py @@ -92,7 +92,7 @@ def test_inherited_notification_templates(get, post, user, organization, project isrc.save() jt = JobTemplate.objects.create(name='test', inventory=i, project=project, playbook='debug.yml') jt.save() - + @pytest.mark.django_db 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, notification_type="webhook", notification_configuration=dict(url="https://example.org", disable_ssl_verification=False, - headers={"Test": "Header"})), + http_method="POST", headers={"Test": "Header"})), u) assert response.status_code == 201 template = NotificationTemplate.objects.get(pk=response.data['id'])