def test_valid_host_type_pass(self): """Validate the available host types.""" with mock.patch(self.REQ_FUNC, return_value=(200, self.HOST_TYPES)): self._set_args({'state': 'present', 'host_type': '0'}) host = Host() self.assertTrue(host.valid_host_type()) self._set_args({'state': 'present', 'host_type': '28'}) host = Host() self.assertTrue(host.valid_host_type()) self._set_args({'state': 'present', 'host_type': 'windows'}) host = Host() self.assertTrue(host.valid_host_type()) self._set_args({'state': 'present', 'host_type': 'linux dm-mp'}) host = Host() self.assertTrue(host.valid_host_type())
def test_valid_host_type_fail(self): """Validate the available host types.""" with self.assertRaisesRegexp( AnsibleFailJson, "host_type must be either a host type name or host type index found integer the documentation" ): self._set_args({'state': 'present', 'host_type': 'non-host-type'}) host = Host() with mock.patch(self.REQ_FUNC, return_value=(200, self.HOST_TYPES)): with self.assertRaisesRegexp(AnsibleFailJson, "There is no host type with index"): self._set_args({'state': 'present', 'host_type': '4'}) host = Host() host.valid_host_type() with mock.patch(self.REQ_FUNC, return_value=Exception()): with self.assertRaisesRegexp(AnsibleFailJson, "Failed to get host types."): self._set_args({'state': 'present', 'host_type': '4'}) host = Host() host.valid_host_type()