func TestDPNWorkItemSave(t *testing.T) {
	testServer := httptest.NewServer(http.HandlerFunc(dpnWorkItemSaveHandler))
	defer testServer.Close()

	client, err := network.NewPharosClient(testServer.URL, "v2", "user", "key")
	if err != nil {
		t.Error(err)
		return
	}

	// ---------------------------------------------
	// First, test create...
	// ---------------------------------------------
	obj := testutil.MakeDPNWorkItem()
	obj.Id = 0
	response := client.DPNWorkItemSave(obj)

	// Check the request URL and method
	assert.Equal(t, "POST", response.Request.Method)
	assert.Equal(t, "/api/v2/dpn_item/", response.Request.URL.Opaque)

	// Basic sanity check on response values
	assert.Nil(t, response.Error)

	obj = response.DPNWorkItem()
	assert.EqualValues(t, "DPNWorkItem", response.ObjectType())
	if obj == nil {
		t.Errorf("DPNWorkItem should not be nil")
	}
	assert.NotEqual(t, "", obj.Task)
	assert.NotEqual(t, "", obj.Identifier)

	// Make sure the client returns the SAVED object,
	// not the unsaved one we sent.
	assert.NotEqual(t, 0, obj.Id)

	// ---------------------------------------------
	// Now test with an update...
	// ---------------------------------------------
	obj = testutil.MakeDPNWorkItem()
	origModTime := obj.UpdatedAt
	response = client.DPNWorkItemSave(obj)

	// Check the request URL and method
	expectedUrl := fmt.Sprintf("/api/v2/dpn_item/%d/", obj.Id)
	assert.Equal(t, "PUT", response.Request.Method)
	assert.Equal(t, expectedUrl, response.Request.URL.Opaque)

	// Basic sanity check on response values
	assert.Nil(t, response.Error)

	obj = response.DPNWorkItem()
	assert.EqualValues(t, "DPNWorkItem", response.ObjectType())
	if obj == nil {
		t.Errorf("DPNWorkItem should not be nil")
	}
	assert.Equal(t, 1000, obj.Id)
	assert.NotEqual(t, origModTime, obj.UpdatedAt)
}
func dpnWorkItemListHandler(w http.ResponseWriter, r *http.Request) {
	list := make([]*models.DPNWorkItem, 4)
	for i := 0; i < 4; i++ {
		list[i] = testutil.MakeDPNWorkItem()
	}
	data := listResponseData()
	data["results"] = list
	listJson, _ := json.Marshal(data)
	w.Header().Set("Content-Type", "application/json")
	fmt.Fprintln(w, string(listJson))
}
func dpnWorkItemGetHandler(w http.ResponseWriter, r *http.Request) {
	obj := testutil.MakeDPNWorkItem()
	objJson, _ := json.Marshal(obj)
	w.Header().Set("Content-Type", "application/json")
	fmt.Fprintln(w, string(objJson))
}