def test_delete_child__success(self, **kwargs):
        mock = kwargs['mock']
        start_session(mock)
        obj = ConfigObject(DOMAINTMPL_SPEC_TEST)
        test_id = "e5b683ed-5c24-4d43-bac9-181b6d4eb63b"

        assert obj.get_name() == "DomainTemplate"

        obj.id = test_id
        assert hasattr(obj, 'id') is True
        obj.name = "test_domain_template"
        assert hasattr(obj, 'name') is True
        resource_name = DOMAINTMPL_SPEC_TEST["model"]["resource_name"]

        mock.delete(build_standard_mock_url(resource_name + "/" + test_id +
                                            "?responseChoice=1"),
                    status_code=204)

        obj.delete()

        last_request = mock.last_request
        json_data = last_request.json()
        assert "ID" in json_data
        assert json_data["ID"] == test_id
        assert "name" in json_data
        assert json_data["name"] == "test_domain_template"
    def test_delete_parent__success(self, **kwargs):
        mock = kwargs['mock']
        start_session(mock)
        obj = ConfigObject(ENTERPRISE_SPEC_TEST)
        test_id = "741fc5d9-fce7-4f98-9172-e962be6ee3e2"

        assert obj.get_name() == "Enterprise"

        obj.id = test_id
        assert hasattr(obj, 'id') is True
        obj.name = "test_enterprise"
        assert hasattr(obj, 'name') is True
        resource_name = ENTERPRISE_SPEC_TEST["model"]["resource_name"]

        mock.delete(build_standard_mock_url(resource_name + "/" + test_id +
                                            "?responseChoice=1"),
                    status_code=204)

        obj.delete()

        last_request = mock.last_request
        json_data = last_request.json()
        assert "ID" in json_data
        assert json_data["ID"] == test_id
        assert "name" in json_data
        assert json_data["name"] == "test_enterprise"
    def test_create_parent__success(self, **kwargs):
        mock = kwargs['mock']
        session = start_session(mock)
        obj = ConfigObject(ENTERPRISE_SPEC_TEST)
        test_id = "741fc5d9-fce7-4f98-9172-e962be6ee3e2"

        assert obj.get_name() == "Enterprise"

        obj.name = "test_enterprise"
        resource_name = ENTERPRISE_SPEC_TEST["model"]["resource_name"]

        mock.post(build_standard_mock_url(resource_name),
                  status_code=201,
                  json=[{
                      "name": "test_enterprise",
                      "ID": test_id
                  }])

        session.root_object.current_child_name = resource_name
        session.root_object.create_child(obj)

        last_request = mock.last_request
        json_data = last_request.json()
        assert "ID" in json_data
        assert json_data["ID"] is None
        assert "name" in json_data
        assert json_data["name"] == "test_enterprise"

        assert obj.name == "test_enterprise"
        assert obj.id == test_id
    def test_create_child__conflict(self, **kwargs):
        mock = kwargs['mock']
        start_session(mock)
        parent_obj = ConfigObject(ENTERPRISE_SPEC_TEST)
        parent_test_id = "741fc5d9-fce7-4f98-9172-e962be6ee3e2"

        parent_obj.id = parent_test_id
        assert hasattr(parent_obj, 'id') is True

        child_obj = ConfigObject(DOMAINTMPL_SPEC_TEST)

        assert child_obj.get_name() == "DomainTemplate"

        child_obj.name = "test_domain_template"
        assert hasattr(child_obj, 'name') is True

        parent_resource_name = ENTERPRISE_SPEC_TEST["model"]["resource_name"]
        child_resource_name = DOMAINTMPL_SPEC_TEST["model"]["resource_name"]

        mock.post(build_standard_mock_url(parent_resource_name + "/" +
                                          parent_test_id + "/" +
                                          child_resource_name),
                  status_code=409,
                  json={
                      "errors": [{
                          "property":
                          "name",
                          "descriptions": [{
                              "title":
                              "Resource in use",
                              "description":
                              "name(test_domain_template) is in "
                              "use. Please retry with a different value."
                          }]
                      }],
                      "internalErrorCode":
                      2510
                  })

        parent_obj.current_child_name = child_resource_name
        with pytest.raises(BambouHTTPError) as e:
            parent_obj.create_child(child_obj)

        last_request = mock.last_request
        json_data = last_request.json()
        assert "ID" in json_data
        assert json_data["ID"] is None
        assert "name" in json_data
        assert json_data["name"] == "test_domain_template"

        assert '409' in str(e)
        assert 'in use' in str(e)
        assert 'test_domain_template' in str(e)
    def test_delete_child__not_found(self, **kwargs):
        mock = kwargs['mock']
        start_session(mock)
        obj = ConfigObject(DOMAINTMPL_SPEC_TEST)
        test_id = "e5b683ed-5c24-4d43-bac9-181b6d4eb63b"

        assert obj.get_name() == "DomainTemplate"

        obj.id = test_id
        assert hasattr(obj, 'id') is True
        obj.name = "test_domain_template"
        assert hasattr(obj, 'name') is True
        resource_name = DOMAINTMPL_SPEC_TEST["model"]["resource_name"]

        mock.delete(build_standard_mock_url(resource_name + "/" + test_id +
                                            "?responseChoice=1"),
                    status_code=404,
                    json={
                        "description":
                        "Cannot find domaintemplate with ID "
                        "e5b683ed-5c24-4d43-bac9-181b6d4eb63b",
                        "title":
                        "domaintemplate not found",
                        "errors": [{
                            "property":
                            "",
                            "descriptions": [{
                                "title":
                                "domaintemplate not found",
                                "description":
                                "Cannot find domaintemplate "
                                "with ID e5b683ed-5c24-4d43-bac9-"
                                "181b6d4eb63b"
                            }]
                        }]
                    })

        with pytest.raises(BambouHTTPError) as e:
            obj.delete()

        last_request = mock.last_request
        json_data = last_request.json()
        assert "ID" in json_data
        assert json_data["ID"] == test_id
        assert "name" in json_data
        assert json_data["name"] == "test_domain_template"

        assert '404' in str(e)
        assert 'domaintemplate not found' in str(e)
        assert test_id in str(e)
    def test_delete_parent__not_found(self, **kwargs):
        mock = kwargs['mock']
        start_session(mock)
        obj = ConfigObject(ENTERPRISE_SPEC_TEST)
        test_id = "741fc5d9-fce7-4f98-9172-e962be6ee3e2"

        assert obj.get_name() == "Enterprise"

        obj.id = test_id
        assert hasattr(obj, 'id') is True
        obj.name = "test_enterprise"
        assert hasattr(obj, 'name') is True
        resource_name = ENTERPRISE_SPEC_TEST["model"]["resource_name"]

        mock.delete(build_standard_mock_url(resource_name + "/" + test_id +
                                            "?responseChoice=1"),
                    status_code=404,
                    json={
                        "description":
                        "Cannot find enterprise with ID "
                        "741fc5d9-fce7-4f98-9172-e962be6ee3e2",
                        "title":
                        "enterprise not found",
                        "errors": [{
                            "property":
                            "",
                            "descriptions": [{
                                "title":
                                "enterprise not found",
                                "description":
                                "Cannot find enterprise "
                                "with ID 741fc5d9-fce7-4f98-9172-"
                                "e962be6ee3e2"
                            }]
                        }]
                    })

        with pytest.raises(BambouHTTPError) as e:
            obj.delete()

        last_request = mock.last_request
        json_data = last_request.json()
        assert "ID" in json_data
        assert json_data["ID"] == test_id
        assert "name" in json_data
        assert json_data["name"] == "test_enterprise"

        assert '404' in str(e)
        assert 'enterprise not found' in str(e)
        assert test_id in str(e)
    def test_create_parent__conflict(self, **kwargs):
        mock = kwargs['mock']
        session = start_session(mock)
        obj = ConfigObject(ENTERPRISE_SPEC_TEST)

        assert obj.get_name() == "Enterprise"

        obj.name = "test_enterprise"
        assert hasattr(obj, "name")

        resource_name = ENTERPRISE_SPEC_TEST["model"]["resource_name"]

        mock.post(build_standard_mock_url(resource_name),
                  status_code=409,
                  json={
                      "errors": [{
                          "property":
                          "name",
                          "descriptions": [{
                              "title":
                              "Cannot create duplicate entity.",
                              "description":
                              "Another Enterprise with the same"
                              " name = test_enterprise exists."
                          }]
                      }],
                      "internalErrorCode":
                      9501
                  })

        session.root_object.current_child_name = resource_name
        with pytest.raises(BambouHTTPError) as e:
            session.root_object.create_child(obj)

        last_request = mock.last_request
        json_data = last_request.json()
        assert "ID" in json_data
        assert json_data["ID"] is None
        assert "name" in json_data
        assert json_data["name"] == "test_enterprise"

        assert '409' in str(e)
        assert 'duplicate' in str(e)
        assert 'test_enterprise exists' in str(e)
    def test_create_child__success(self, **kwargs):
        mock = kwargs['mock']
        start_session(mock)
        parent_obj = ConfigObject(ENTERPRISE_SPEC_TEST)
        parent_test_id = "741fc5d9-fce7-4f98-9172-e962be6ee3e2"
        child_test_id = "e5b683ed-5c24-4d43-bac9-181b6d4eb63b"

        parent_obj.id = parent_test_id
        assert hasattr(parent_obj, 'id') is True

        child_obj = ConfigObject(DOMAINTMPL_SPEC_TEST)

        assert child_obj.get_name() == "DomainTemplate"

        child_obj.name = "test_domain_template"
        assert hasattr(child_obj, 'name') is True

        parent_resource_name = ENTERPRISE_SPEC_TEST["model"]["resource_name"]
        child_resource_name = DOMAINTMPL_SPEC_TEST["model"]["resource_name"]

        mock.post(build_standard_mock_url(parent_resource_name + "/" +
                                          parent_test_id + "/" +
                                          child_resource_name),
                  status_code=201,
                  json=[{
                      "name": "test_domain_template",
                      "ID": child_test_id
                  }])

        parent_obj.current_child_name = child_resource_name
        parent_obj.create_child(child_obj)

        last_request = mock.last_request
        json_data = last_request.json()
        assert "ID" in json_data
        assert json_data["ID"] is None
        assert "name" in json_data
        assert json_data["name"] == "test_domain_template"

        assert child_obj.name == "test_domain_template"
        assert child_obj.id == child_test_id
    def test_new_object__success(self, **kwargs):
        mock = kwargs['mock']
        start_session(mock)
        obj = ConfigObject(ENTERPRISE_SPEC_TEST)

        assert obj.get_name() == "Enterprise"