本文整理匯總了Golang中github.com/ninnemana/API/models/customer.CustomerUser.Delete方法的典型用法代碼示例。如果您正苦於以下問題:Golang CustomerUser.Delete方法的具體用法?Golang CustomerUser.Delete怎麽用?Golang CustomerUser.Delete使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/ninnemana/API/models/customer.CustomerUser
的用法示例。
在下文中一共展示了CustomerUser.Delete方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: DeleteCustomerUser
func DeleteCustomerUser(rw http.ResponseWriter, r *http.Request, enc encoding.Encoder, params martini.Params) string {
var err error
var cu customer.CustomerUser
if params["id"] != "" {
cu.Id = params["id"]
} else if r.FormValue("id") != "" {
cu.Id = r.FormValue("id")
} else {
err = errors.New("Trouble getting customer user ID")
apierror.GenerateError("Trouble getting customer user ID", err, rw, r)
return ""
}
if err = cu.Delete(); err != nil {
apierror.GenerateError("Trouble deleting customer user", err, rw, r)
return ""
}
return encoding.Must(enc.Encode(cu))
}
示例2: BenchmarkCRUDCustomerUser
func BenchmarkCRUDCustomerUser(b *testing.B) {
dtx, err := apicontextmock.Mock()
if err != nil {
b.Log(err)
}
var cu customer.CustomerUser
cu.Id = dtx.UserID
qs := make(url.Values, 0)
qs.Add("key", dtx.APIKey)
Convey("CustomerUser", b, func() {
form := url.Values{"name": {"Mitt Romney"}, "email": {"[email protected]"}, "pass": {"robthepoor"}, "customerID": {strconv.Itoa(dtx.CustomerID)}, "isActive": {"true"}, "locationID": {"1"}, "isSudo": {"true"}, "cust_ID": {"1"}}
//create
(&httprunner.BenchmarkOptions{
Method: "POST",
Route: "/customer/user/register",
ParameterizedRoute: "/customer/user/register",
Handler: RegisterUser,
QueryString: &qs,
JsonBody: cu,
FormBody: form,
Runs: b.N,
}).RequestBenchmark()
//authenticate user
form = url.Values{"email": {"[email protected]"}, "password": {"robthepoor"}}
(&httprunner.BenchmarkOptions{
Method: "POST",
Route: "/customer/auth",
ParameterizedRoute: "/customer/auth",
Handler: AuthenticateUser,
QueryString: &qs,
JsonBody: nil,
FormBody: nil,
Runs: b.N,
}).RequestBenchmark()
//authenticate user by key
(&httprunner.BenchmarkOptions{
Method: "GET",
Route: "/customer/auth",
ParameterizedRoute: "/customer/auth",
Handler: KeyedUserAuthentication,
QueryString: &qs,
JsonBody: nil,
FormBody: nil,
Runs: b.N,
}).RequestBenchmark()
//delete
(&httprunner.BenchmarkOptions{
Method: "DELETE",
Route: "/customer/user/register",
ParameterizedRoute: "/customer/user/register/" + cu.Id,
Handler: DeleteCustomerUser,
QueryString: &qs,
JsonBody: cu,
FormBody: nil,
Runs: b.N,
}).RequestBenchmark()
form = url.Values{"email": {"[email protected]"}, "password": {"robthepoor"}}
})
cu.Delete()
err = apicontextmock.DeMock(dtx)
if err != nil {
b.Log(err)
}
}
示例3: TestCustomer
//.........這裏部分代碼省略.........
bodyJson := bytes.NewReader(bodyBytes)
thyme := time.Now()
testThatHttp.Request("put", "/customer", "", "?key=", SaveCustomer, bodyJson, "application/json")
So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
So(testThatHttp.Response.Code, ShouldEqual, 200)
err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &c)
So(err, ShouldBeNil)
So(c, ShouldHaveSameTypeAs, customer.Customer{})
So(c.Id, ShouldBeGreaterThan, 0)
//test update customer
c.Fax = "666-1313"
c.State.Id = 1
bodyBytes, _ = json.Marshal(c)
bodyJson = bytes.NewReader(bodyBytes)
thyme = time.Now()
testThatHttp.Request("put", "/customer/", ":id", strconv.Itoa(c.Id)+"?key=", SaveCustomer, bodyJson, "application/json")
So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
So(testThatHttp.Response.Code, ShouldEqual, 200)
err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &c)
So(err, ShouldBeNil)
So(c, ShouldHaveSameTypeAs, customer.Customer{})
So(c.Id, ShouldBeGreaterThan, 0)
thyme = time.Now()
testThatHttp.RequestWithDtx("post", "/customer", "", "?key=", GetCustomer, nil, "", dtx)
So(testThatHttp.Response.Code, ShouldEqual, 200)
err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &c)
So(err, ShouldBeNil)
So(c, ShouldHaveSameTypeAs, customer.Customer{})
So(c.Id, ShouldBeGreaterThan, 0)
// get customer locations
thyme = time.Now()
testThatHttp.RequestWithDtx("get", "/customer/locations", "", "?key=", GetLocations, nil, "", dtx)
So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()*6)
So(testThatHttp.Response.Code, ShouldEqual, 200)
err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &c.Locations)
So(err, ShouldBeNil)
So(c.Locations, ShouldHaveSameTypeAs, []customer.CustomerLocation{})
// //get user
thyme = time.Now()
testThatHttp.RequestWithDtx("post", "/customer/user", "", "?key="+dtx.APIKey, GetUser, nil, "", nil)
So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
So(testThatHttp.Response.Code, ShouldEqual, 200)
err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &cu)
So(err, ShouldBeNil)
So(cu, ShouldHaveSameTypeAs, customer.CustomerUser{})
//get users
thyme = time.Now()
testThatHttp.RequestWithDtx("get", "/customer/users", "", "?key=", GetUsers, nil, "", dtx)
So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()*5)
So(testThatHttp.Response.Code, ShouldEqual, 200)
var cus []customer.CustomerUser
err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &cus)
So(err, ShouldBeNil)
So(cus, ShouldHaveSameTypeAs, []customer.CustomerUser{})
// get customer price
// price.CustID = c.Id
// price.Create()
// thyme = time.Now()
// testThatHttp.Request("get", "/new/customer/price/", ":id", strconv.Itoa(p.ID)+"?key="+apiKey, GetCustomerPrice, nil, "")
// So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
// So(testThatHttp.Response.Code, ShouldEqual, 200)
// var price float64
// err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &price)
// So(err, ShouldBeNil)
// So(price, ShouldHaveSameTypeAs, 7.1)
// //get customer cart reference
// ci.CustID = c.Id
// ci.Create()
// thyme = time.Now()
// testThatHttp.Request("get", "/new/customer/cartRef/", ":id", strconv.Itoa(p.ID)+"?key="+apiKey, GetCustomerCartReference, nil, "")
// So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
// So(testThatHttp.Response.Code, ShouldEqual, 200)
// var reference int
// err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &reference)
// So(err, ShouldBeNil)
// So(reference, ShouldHaveSameTypeAs, 7)
//test delete customer
thyme = time.Now()
testThatHttp.Request("delete", "/customer/", ":id", strconv.Itoa(c.Id)+"?key=", DeleteCustomer, nil, "")
So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
So(testThatHttp.Response.Code, ShouldEqual, 200)
err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &c)
So(err, ShouldBeNil)
So(c, ShouldHaveSameTypeAs, customer.Customer{})
So(c.Id, ShouldBeGreaterThan, 0)
})
//cleanup
err = cu.Delete()
err = c.Delete()
}
示例4: TestCustomerUser
//.........這裏部分代碼省略.........
So(testThatHttp.Response.Code, ShouldEqual, 200)
err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &c)
So(err, ShouldBeNil)
So(c, ShouldHaveSameTypeAs, customer.Customer{})
//test get user by id
thyme = time.Now()
testThatHttp.Request("get", "/customer/", ":id", cu.Id+"?key="+apiKey, GetUserById, nil, "")
So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
So(testThatHttp.Response.Code, ShouldEqual, 200)
err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &cu)
So(err, ShouldBeNil)
So(cu, ShouldHaveSameTypeAs, customer.CustomerUser{})
//test change user password
form = url.Values{"email": {"[email protected]"}, "oldPass": {"robthepoor"}, "newPass": {"prolife"}}
v = form.Encode()
body = strings.NewReader(v)
thyme = time.Now()
testThatHttp.Request("post", "/customer/user/changePassword", "", "?key="+apiKey, ChangePassword, body, "application/x-www-form-urlencoded")
So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()*2)
So(testThatHttp.Response.Code, ShouldEqual, 200)
var result string
err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &result)
So(err, ShouldBeNil)
So(result, ShouldHaveSameTypeAs, "Success")
//test reset user password
form = url.Values{"email": {"[email protected]"}, "customerID": {strconv.Itoa(c.CustomerId)}}
v = form.Encode()
body = strings.NewReader(v)
thyme = time.Now()
testThatHttp.Request("post", "/customer/user/resetPassword", "", "?key="+apiKey, ResetPassword, body, "application/x-www-form-urlencoded")
So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
So(testThatHttp.Response.Code, ShouldEqual, 200)
err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &result)
So(err, ShouldBeNil)
So(result, ShouldHaveSameTypeAs, "Success")
//test generate api key
thyme = time.Now()
testThatHttp.Request("post", "/customer/user/", ":id/key/:type", cu.Id+"/key/PRIVATE?key="+apiKey, GenerateApiKey, nil, "")
So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
So(testThatHttp.Response.Code, ShouldEqual, 200)
var newKey customer.ApiCredentials
err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &newKey)
So(err, ShouldBeNil)
So(newKey.Key, ShouldHaveSameTypeAs, "string")
//test delete customer users by customerId
var cu2 customer.CustomerUser
cu2.Create([]int{1})
c.JoinUser(cu2)
thyme = time.Now()
testThatHttp.Request("delete", "/customer/allUsersByCustomerID/", ":id", strconv.Itoa(c.Id), DeleteCustomerUsersByCustomerID, nil, "")
So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
So(testThatHttp.Response.Code, ShouldEqual, 200)
var response string
err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &response)
So(err, ShouldBeNil)
So(response, ShouldHaveSameTypeAs, "this is a string")
//test delete customer user
thyme = time.Now()
testThatHttp.Request("delete", "/customer/user/", ":id", cu.Id, DeleteCustomerUser, nil, "")
So(time.Since(thyme).Nanoseconds(), ShouldBeLessThan, time.Second.Nanoseconds()/2)
So(testThatHttp.Response.Code, ShouldEqual, 200)
err = json.Unmarshal(testThatHttp.Response.Body.Bytes(), &cu)
So(err, ShouldBeNil)
So(cu, ShouldHaveSameTypeAs, customer.CustomerUser{})
So(cu.Id, ShouldNotBeEmpty)
cu2.Delete()
})
//teardown
err = c.Delete()
if err != nil {
t.Log(err)
}
if database.EmptyDb != nil {
err = pub.Delete()
if err != nil {
t.Log(err)
}
err = pri.Delete()
if err != nil {
t.Log(err)
}
err = auth.Delete()
if err != nil {
t.Log(err)
}
}
err = cu.Delete()
if err != nil {
t.Log(err)
}
}