mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-16 17:01:30 +00:00
Reformat everything.
This commit is contained in:
parent
3f2213791a
commit
340ff8586d
1008 changed files with 61301 additions and 58309 deletions
|
|
@ -7,11 +7,15 @@ from __future__ import annotations
|
|||
import pytest
|
||||
from unittest.mock import patch
|
||||
from ansible_collections.community.general.plugins.modules import campfire
|
||||
from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args
|
||||
from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import (
|
||||
AnsibleExitJson,
|
||||
AnsibleFailJson,
|
||||
ModuleTestCase,
|
||||
set_module_args,
|
||||
)
|
||||
|
||||
|
||||
class TestCampfireModule(ModuleTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.module = campfire
|
||||
|
|
@ -21,7 +25,7 @@ class TestCampfireModule(ModuleTestCase):
|
|||
|
||||
@pytest.fixture
|
||||
def fetch_url_mock(self, mocker):
|
||||
return mocker.patch('ansible.module_utils.notification.campfire.fetch_url')
|
||||
return mocker.patch("ansible.module_utils.notification.campfire.fetch_url")
|
||||
|
||||
def test_without_required_parameters(self):
|
||||
"""Failure must occurs when all parameters are missing"""
|
||||
|
|
@ -31,12 +35,7 @@ class TestCampfireModule(ModuleTestCase):
|
|||
|
||||
def test_successful_message(self):
|
||||
"""Test failure message"""
|
||||
with set_module_args({
|
||||
'subscription': 'test',
|
||||
'token': 'abc',
|
||||
'room': 'test',
|
||||
'msg': 'test'
|
||||
}):
|
||||
with set_module_args({"subscription": "test", "token": "abc", "room": "test", "msg": "test"}):
|
||||
with patch.object(campfire, "fetch_url") as fetch_url_mock:
|
||||
fetch_url_mock.return_value = (None, {"status": 200})
|
||||
with self.assertRaises(AnsibleExitJson):
|
||||
|
|
@ -44,20 +43,14 @@ class TestCampfireModule(ModuleTestCase):
|
|||
|
||||
assert fetch_url_mock.call_count == 1
|
||||
url = fetch_url_mock.call_args[0][1]
|
||||
data = fetch_url_mock.call_args[1]['data']
|
||||
data = fetch_url_mock.call_args[1]["data"]
|
||||
|
||||
assert url == 'https://test.campfirenow.com/room/test/speak.xml'
|
||||
assert data == '<message><body>test</body></message>'
|
||||
assert url == "https://test.campfirenow.com/room/test/speak.xml"
|
||||
assert data == "<message><body>test</body></message>"
|
||||
|
||||
def test_successful_message_with_notify(self):
|
||||
"""Test failure message"""
|
||||
with set_module_args({
|
||||
'subscription': 'test',
|
||||
'token': 'abc',
|
||||
'room': 'test',
|
||||
'msg': 'test',
|
||||
'notify': 'bell'
|
||||
}):
|
||||
with set_module_args({"subscription": "test", "token": "abc", "room": "test", "msg": "test", "notify": "bell"}):
|
||||
with patch.object(campfire, "fetch_url") as fetch_url_mock:
|
||||
fetch_url_mock.return_value = (None, {"status": 200})
|
||||
with self.assertRaises(AnsibleExitJson):
|
||||
|
|
@ -66,26 +59,21 @@ class TestCampfireModule(ModuleTestCase):
|
|||
assert fetch_url_mock.call_count == 2
|
||||
notify_call = fetch_url_mock.mock_calls[0]
|
||||
url = notify_call[1][1]
|
||||
data = notify_call[2]['data']
|
||||
data = notify_call[2]["data"]
|
||||
|
||||
assert url == 'https://test.campfirenow.com/room/test/speak.xml'
|
||||
assert data == '<message><type>SoundMessage</type><body>bell</body></message>'
|
||||
assert url == "https://test.campfirenow.com/room/test/speak.xml"
|
||||
assert data == "<message><type>SoundMessage</type><body>bell</body></message>"
|
||||
|
||||
message_call = fetch_url_mock.mock_calls[1]
|
||||
url = message_call[1][1]
|
||||
data = message_call[2]['data']
|
||||
data = message_call[2]["data"]
|
||||
|
||||
assert url == 'https://test.campfirenow.com/room/test/speak.xml'
|
||||
assert data == '<message><body>test</body></message>'
|
||||
assert url == "https://test.campfirenow.com/room/test/speak.xml"
|
||||
assert data == "<message><body>test</body></message>"
|
||||
|
||||
def test_failure_message(self):
|
||||
"""Test failure message"""
|
||||
with set_module_args({
|
||||
'subscription': 'test',
|
||||
'token': 'abc',
|
||||
'room': 'test',
|
||||
'msg': 'test'
|
||||
}):
|
||||
with set_module_args({"subscription": "test", "token": "abc", "room": "test", "msg": "test"}):
|
||||
with patch.object(campfire, "fetch_url") as fetch_url_mock:
|
||||
fetch_url_mock.return_value = (None, {"status": 403})
|
||||
with self.assertRaises(AnsibleFailJson):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue