def test_delete_host_no_changes(self): """Ensure that removing a host that doesn't exist works correctly.""" self._set_args({'state': 'absent'}) host = Host() with self.assertRaises(AnsibleExitJson) as result: # We expect a single call to the API: retrieve the defined hosts. with mock.patch(self.REQ_FUNC, return_value=(200, [])): host.apply() # We should not mark changed=True self.assertEquals(result.exception.args[0]['changed'], False)
def test_delete_host(self): """Validate removing a host object""" self._set_args({ 'state': 'absent' }) host = Host() with self.assertRaises(AnsibleExitJson) as result: # We expect 2 calls to the API, the first to retrieve the host objects defined, # the second to remove the host definition. with mock.patch(self.REQ_FUNC, side_effect=[(200, [self.HOST]), (204, {})]) as request: host.apply() self.assertEquals(request.call_count, 2) # We expect the module to make changes self.assertEquals(result.exception.args[0]['changed'], True)