mirror of
https://github.com/ansible/awx.git
synced 2026-03-02 17:28:51 -03:30
Support AWX_TASK_ENV injection in task and notification invocations.
This change _only_ injects `AWS_TASK_ENV` into `os.environ`; it's up to underlying libraries to be good citizens and actually respect things like `HTTPS_PROXY`. see: #3508
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
import mock
|
||||
import pytest
|
||||
|
||||
from requests.adapters import HTTPAdapter
|
||||
from requests.utils import select_proxy
|
||||
from requests.exceptions import ConnectionError
|
||||
|
||||
from awx.api.versioning import reverse
|
||||
from awx.main.models.notifications import NotificationTemplate, Notification
|
||||
from awx.main.models.inventory import Inventory, InventorySource
|
||||
@@ -129,3 +133,26 @@ def test_disallow_delete_when_notifications_pending(delete, user, notification_t
|
||||
response = delete(url, user=u)
|
||||
assert response.status_code == 405
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_custom_environment_injection(post, user, organization):
|
||||
u = user('admin-poster', True)
|
||||
url = reverse('api:notification_template_list')
|
||||
response = post(url,
|
||||
dict(name="test-webhook",
|
||||
description="test webhook",
|
||||
organization=organization.id,
|
||||
notification_type="webhook",
|
||||
notification_configuration=dict(url="https://example.org",
|
||||
headers={"Test": "Header"})),
|
||||
u)
|
||||
assert response.status_code == 201
|
||||
template = NotificationTemplate.objects.get(pk=response.data['id'])
|
||||
with pytest.raises(ConnectionError), \
|
||||
mock.patch('django.conf.settings.AWX_TASK_ENV', {'HTTPS_PROXY': '192.168.50.100:1234'}), \
|
||||
mock.patch.object(HTTPAdapter, 'send') as fake_send:
|
||||
def _send_side_effect(request, **kw):
|
||||
assert select_proxy(request.url, kw['proxies']) == '192.168.50.100:1234'
|
||||
raise ConnectionError()
|
||||
fake_send.side_effect = _send_side_effect
|
||||
template.send('subject', 'message')
|
||||
|
||||
Reference in New Issue
Block a user