From a0f54c4ba097176d5b08633f4019f5ef599b3968 Mon Sep 17 00:00:00 2001 From: Lukas Hellebrandt Date: Wed, 21 Jun 2023 15:57:42 +0200 Subject: [PATCH] Coverage --- tests/test_entities.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/test_entities.py b/tests/test_entities.py index eeeb9b71..b3c1b20c 100644 --- a/tests/test_entities.py +++ b/tests/test_entities.py @@ -329,6 +329,7 @@ def test_id_and_which(self): (entities.Host, 'smart_class_parameters'), (entities.Host, 'ansible_roles'), (entities.Host, 'assign_ansible_roles'), + (entities.Host, 'play_roles'), (entities.HostGroup, 'ansible_roles'), (entities.HostGroup, 'assign_ansible_roles'), (entities.HostGroup, 'clone'), @@ -3163,6 +3164,22 @@ def test_disassociate(self): self.assertEqual(len(put.call_args[1]), 0) # post called with no keyword argument self.assertEqual(put.call_args[0][0], 'foo/api/v2/hosts/42/disassociate') + def test_play_ansible_roles(self): + """Play Ansible roles""" + cfg = config.ServerConfig(url='foo') + host = entities.Host(cfg, id=42) + exp_ret = mock.MagicMock() + exp_ret.status = ACCEPTED + exp_ret.content = {'bar': 'baz', 'task_id': 43} + with mock.patch.object(client, 'post', return_value=exp_ret) as post: + res = host.play_ansible_roles() + self.assertEqual(post.call_count, 1) + self.assertEqual(len(post.call_args), 2) + self.assertEqual(len(post.call_args[0]), 1) # post called with 1 positional argument + self.assertEqual(len(post.call_args[1]), 0) # post called with no keyword argument + self.assertEqual(post.call_args[0][0], 'foo/api/v2/hosts/42/play_roles') + self.assertEqual(res, 43) + class PuppetClassTestCase(TestCase): """Tests for :class:`nailgun.entities.PuppetClass`."""