def test_create_host_without_ansible_host_then_update(self): # Create a host without ansible_host field # then update those fields host_data = HostWrapper(test_data(facts=None)) del host_data.ansible_host # Create the host response = self.post(HOST_URL, [host_data.data()], 207) self._verify_host_status(response, 0, 201) created_host = self._pluck_host_from_response(response, 0) original_id = created_host["id"] ansible_hosts = ["ima_ansible_host_" + generate_uuid(), ""] # Update the ansible_host for ansible_host in ansible_hosts: with self.subTest(ansible_host=ansible_host): host_data.ansible_host = ansible_host # Update the hosts self.post(HOST_URL, [host_data.data()], 207) host_lookup_results = self.get(f"{HOST_URL}/{original_id}", 200) self._validate_host(host_lookup_results["results"][0], host_data, expected_id=original_id)
def test_create_host_with_invalid_ansible_host(self): host_data = HostWrapper(test_data(facts=None)) invalid_ansible_host = ["a" * 256] for ansible_host in invalid_ansible_host: with self.subTest(ansible_host=ansible_host): host_data.ansible_host = ansible_host response = self.post(HOST_URL, [host_data.data()], 207) error_host = response["data"][0] self.assertEqual(error_host["status"], 400) self.verify_error_response(error_host, expected_title="Bad Request")
def test_create_host_with_ansible_host(self): # Create a host with ansible_host field host_data = HostWrapper(test_data(facts=None)) host_data.ansible_host = "ansible_host_" + generate_uuid() # Create the host response = self.post(HOST_URL, [host_data.data()], 207) self._verify_host_status(response, 0, 201) created_host = self._pluck_host_from_response(response, 0) original_id = created_host["id"] host_lookup_results = self.get(f"{HOST_URL}/{original_id}", 200) self._validate_host(host_lookup_results["results"][0], host_data, expected_id=original_id)