当前位置: 首页>>代码示例>>Golang>>正文


Golang aetest.Login函数代码示例

本文整理汇总了Golang中appengine/aetest.Login函数的典型用法代码示例。如果您正苦于以下问题:Golang Login函数的具体用法?Golang Login怎么用?Golang Login使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Login函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestEditVisitPageMissingPathInfo

func TestEditVisitPageMissingPathInfo(t *testing.T) {
	inst, err := aetest.NewInstance(&aetest.Options{StronglyConsistentDatastore: true})
	if err != nil {
		t.Fatalf("Failed to create instance: %v", err)
	}
	defer inst.Close()

	url := "/editvisit/"
	req, err := inst.NewRequest("GET", url, nil)
	if err != nil {
		t.Fatalf("Failed to create req: %v", err)
	}

	aetest.Login(&user.User{Email: "[email protected]"}, req)

	w := httptest.NewRecorder()
	c := appengine.NewContext(req)

	addTestUser(c, "[email protected]", true)

	editvisitpage(c, w, req)

	code := w.Code
	if code != http.StatusBadRequest {
		t.Errorf("got code %v, want %v", code, http.StatusBadRequest)
	}

	body := w.Body.Bytes()
	expected := []byte("id is missing in path for update request /editvisit/")
	if !bytes.Contains(body, expected) {
		t.Errorf("got body %v, did not contain %v", string(body),
			string(expected))
	}

	url += "12345"
	req, err = inst.NewRequest("GET", url, nil)
	if err != nil {
		t.Fatalf("Failed to create req: %v", err)
	}

	aetest.Login(&user.User{Email: "[email protected]"}, req)

	w = httptest.NewRecorder()
	c = appengine.NewContext(req)

	editvisitpage(c, w, req)

	code = w.Code
	if code != http.StatusBadRequest {
		t.Errorf("got code %v, want %v", code, http.StatusBadRequest)
	}

	body = w.Body.Bytes()
	expected = []byte("id is missing in path for update request /editvisit/")
	if !bytes.Contains(body, expected) {
		t.Errorf("got body %v, did not contain %v", string(body),
			string(expected))
	}

}
开发者ID:jimhopp,项目名称:frederic,代码行数:60,代码来源:web_test.go

示例2: TestHomePage

func TestHomePage(t *testing.T) {
	inst, err := aetest.NewInstance(&aetest.Options{StronglyConsistentDatastore: true})
	if err != nil {
		t.Fatalf("Failed to create instance: %v", err)
	}
	defer inst.Close()

	req, err := inst.NewRequest("GET", "/", nil)
	if err != nil {
		t.Fatalf("Failed to create req1: %v", err)
	}

	aetest.Login(&user.User{Email: "[email protected]"}, req)

	w := httptest.NewRecorder()
	c := appengine.NewContext(req)
	addTestUser(c, "[email protected]", true)

	homepage(c, w, req)

	code := w.Code
	if code != http.StatusOK {
		t.Errorf("got code %v, want %v", code, http.StatusOK)
	}

	body := w.Body.Bytes()
	expected := []byte("[email protected]")
	if !bytes.Contains(body, expected) {
		t.Errorf("got body %v, did not contain %v", string(body), string(expected))
	}
	if !bytes.Contains(body, []byte("Logout")) {
		t.Errorf("got body %v, did not contain %v", body,
			[]byte("Logout"))
	}
}
开发者ID:jimhopp,项目名称:frederic,代码行数:35,代码来源:web_test.go

示例3: TestEndpointsNotAuthorized

func TestEndpointsNotAuthorized(t *testing.T) {
	inst, err := aetest.NewInstance(nil)
	if err != nil {
		t.Fatalf("Failed to create instance: %v", err)
	}
	defer inst.Close()

	for i := 0; i < len(endpoints); i++ {
		req, err := inst.NewRequest("GET", endpoints[i].url, nil)
		if err != nil {
			t.Fatalf("Failed to create req1: %v", err)
		}
		w := httptest.NewRecorder()
		c := appengine.NewContext(req)

		aetest.Login(&user.User{Email: "[email protected]"}, req)
		endpoints[i].handler(c, w, req)

		code := w.Code
		if code != http.StatusForbidden {
			t.Errorf("got code %v for endpoint %v, want %v", code,
				endpoints[i].url, http.StatusForbidden)
		}
		if endpoints[i].humanReadable {
			body := w.Body.Bytes()
			notauth := `Sorry`
			if !bytes.Contains(body, []byte(notauth)) {
				t.Errorf("endpoint %v: got body %v, did not contain %v", endpoints[i].url, string(body), notauth)
			}
		}
	}
}
开发者ID:jimhopp,项目名称:frederic,代码行数:32,代码来源:web_test.go

示例4: TestBuildPageHandler

func TestBuildPageHandler(t *testing.T) {
	opt := &aetest.Options{AppID: "unittest", StronglyConsistentDatastore: true}
	user := &user.User{Email: "[email protected]", Admin: true, ID: "1234567890"}
	inst, err := aetest.NewInstance(opt)
	if err != nil {
		t.Fatalf(err.Error())
	}
	defer inst.Close()
	request, err := inst.NewRequest("POST", "/build", strings.NewReader("Name=ABC&chip=true&fox=true&hour=3&minute=0"))
	if err != nil {
		t.Fatalf("Failed to create request: %v", err)
	}
	request.Header.Set("Content-Type", "application/x-www-form-urlencoded; param=value")
	aetest.Login(user, request)
	recoder := httptest.NewRecorder()
	buildPageHandler(recoder, request)
	if recoder.Code != 302 {
		b, _ := ioutil.ReadAll(recoder.Body)
		t.Fatalf("unexpected %d, expected 302, body=%s", recoder.Code, string(b))
	}
	context := appengine.NewContext(request)
	g := goon.FromContext(context)
	v := Village{No: 1}
	if err := g.Get(&v); err != nil {
		t.Fatalf("unexpected err, expected Get Village{No: 1}")
	}
	if v.Name != "ABC" || v.Chip == false || v.IncludeFox == false || v.UpdatetimeHour != 3 || v.UpdatetimeMinute != 0 {
		t.Fatalf("Failed: Cant't get correct Data from datastore")
	}
}
开发者ID:tSU-RooT,项目名称:Lycos,代码行数:30,代码来源:lycos_test.go

示例5: TestAddVisitPageMissingClient

func TestAddVisitPageMissingClient(t *testing.T) {
	inst, err := aetest.NewInstance(&aetest.Options{StronglyConsistentDatastore: true})
	if err != nil {
		t.Fatalf("Failed to create instance: %v", err)
	}
	defer inst.Close()

	url := "/recordvisit/"
	req, err := inst.NewRequest("GET", url, nil)
	if err != nil {
		t.Fatalf("Failed to create req: %v", err)
	}

	aetest.Login(&user.User{Email: "[email protected]"}, req)

	w := httptest.NewRecorder()
	c := appengine.NewContext(req)

	addTestUser(c, "[email protected]", true)

	recordvisitpage(c, w, req)

	code := w.Code
	if code != http.StatusBadRequest {
		t.Errorf("got code %v, want %v", code, http.StatusNotFound)
	}

	body := w.Body.Bytes()
	expected := []byte("Invalid/missing client id")
	if !bytes.Contains(body, expected) {
		t.Errorf("got body %v, did not contain %v", string(body),
			string(expected))
	}
}
开发者ID:jimhopp,项目名称:frederic,代码行数:34,代码来源:web_test.go

示例6: TestListUsersPageNotAdmin

func TestListUsersPageNotAdmin(t *testing.T) {
	inst, err := aetest.NewInstance(&aetest.Options{StronglyConsistentDatastore: true})
	if err != nil {
		t.Fatalf("Failed to create instance: %v", err)
	}
	defer inst.Close()

	req, err := inst.NewRequest("GET", "/users", nil)
	if err != nil {
		t.Fatalf("Failed to create req: %v", err)
	}

	aetest.Login(&user.User{Email: "[email protected]"}, req)

	w := httptest.NewRecorder()
	c := appengine.NewContext(req)
	addTestUser(c, "[email protected]", false)

	edituserspage(c, w, req)

	code := w.Code
	if code != http.StatusForbidden {
		t.Errorf("got code %v, want %v", code, http.StatusForbidden)
	}

}
开发者ID:jimhopp,项目名称:frederic,代码行数:26,代码来源:web_test.go

示例7: TestGetClientMissingParm

func TestGetClientMissingParm(t *testing.T) {
	inst, err := aetest.NewInstance(&aetest.Options{StronglyConsistentDatastore: true})
	if err != nil {
		t.Fatalf("Failed to create instance: %v", err)
	}
	defer inst.Close()

	url := "/client/"
	req, err := inst.NewRequest("GET", url, nil)
	if err != nil {
		t.Fatalf("Failed to create req: %v", err)
	}

	aetest.Login(&user.User{Email: "[email protected]"}, req)

	w := httptest.NewRecorder()
	c := appengine.NewContext(req)
	addTestUser(c, "[email protected]", true)

	getclientpage(c, w, req)

	code := w.Code
	if code != http.StatusNotFound {
		t.Errorf("got code %v, want %v", code, http.StatusOK)
	}

	body := w.Body.Bytes()
	msg := []byte("client id missing in path")
	if !bytes.Contains(body, msg) {
		t.Errorf("got body %v, did not contain %v", string(body),
			string(msg))
	}
}
开发者ID:jimhopp,项目名称:frederic,代码行数:33,代码来源:web_test.go

示例8: TestListUsersPage

func TestListUsersPage(t *testing.T) {
	inst, err := aetest.NewInstance(&aetest.Options{StronglyConsistentDatastore: true})
	if err != nil {
		t.Fatalf("Failed to create instance: %v", err)
	}
	defer inst.Close()

	newusers := []appuser{
		{Email: "[email protected]", IsAdmin: true},
		{Email: "[email protected]", IsAdmin: false},
		{Email: "[email protected]", IsAdmin: false},
	}

	req, err := inst.NewRequest("GET", "/users", nil)
	if err != nil {
		t.Fatalf("Failed to create req: %v", err)
	}

	aetest.Login(&user.User{Email: "[email protected]"}, req)

	w := httptest.NewRecorder()
	c := appengine.NewContext(req)
	addTestUser(c, "[email protected]", true)

	for i := range newusers {
		_, err := addTestUser(c, newusers[i].Email,
			newusers[i].IsAdmin)
		if err != nil {
			t.Fatalf("unable to add user: %v", err)
		}
	}

	edituserspage(c, w, req)

	code := w.Code
	if code != http.StatusOK {
		t.Errorf("got code %v, want %v", code, http.StatusOK)
	}

	body := w.Body.Bytes()
	rows := []string{"[email protected]",
		"[email protected]",
		"[email protected]",
		`<input type="checkbox" id="admin0" name="admin" checked="checked">`,
		`<input type="checkbox" id="admin1" name="admin">`,
		// [email protected] is user #3
		`<input type="checkbox" id="admin3" name="admin">`,
	}
	for i := range rows {
		if !bytes.Contains(body, []byte(rows[i])) {
			t.Errorf("got body %v, did not contain %v", string(body), rows[i])
		}
	}
}
开发者ID:jimhopp,项目名称:frederic,代码行数:54,代码来源:web_test.go

示例9: TestListClientsPage

func TestListClientsPage(t *testing.T) {
	inst, err := aetest.NewInstance(&aetest.Options{StronglyConsistentDatastore: true})
	if err != nil {
		t.Fatalf("Failed to create instance: %v", err)
	}
	defer inst.Close()

	newclients := []client{
		{Firstname: "frederic", Lastname: "ozanam"},
		{Firstname: "John", Lastname: "Doe"},
		{Firstname: "Jane", Lastname: "Doe"},
	}
	ids := make(map[string]int64, len(newclients))
	for i := 0; i < len(newclients); i++ {
		id, err := addclienttodb(newclients[i], inst)
		if err != nil {
			t.Fatalf("unable to add client: %v", err)
		}
		ids[newclients[i].Lastname+`,`+newclients[i].Firstname] = id
	}
	req, err := inst.NewRequest("GET", "/listclients", nil)
	if err != nil {
		t.Fatalf("Failed to create req: %v", err)
	}

	aetest.Login(&user.User{Email: "[email protected]"}, req)

	w := httptest.NewRecorder()
	c := appengine.NewContext(req)
	addTestUser(c, "[email protected]", true)

	listclientspage(c, w, req)

	code := w.Code
	if code != http.StatusOK {
		t.Errorf("got code %v, want %v", code, http.StatusOK)
	}

	body := w.Body.Bytes()
	rows := []string{"<td>Clients</td>",
		"<a href=\"/client/" + strconv.FormatInt(ids["ozanam,frederic"], 10) +
			"\">ozanam, frederic</a>",
		"<a href=\"/client/" + strconv.FormatInt(ids["Doe,John"], 10) +
			"\">Doe, John</a>",
		"<a href=\"/client/" + strconv.FormatInt(ids["Doe,Jane"], 10) +
			"\">Doe, Jane</a>",
	}
	for i := 0; i < len(rows); i++ {
		if !bytes.Contains(body, []byte(rows[i])) {
			t.Errorf("got body %v, did not contain %v", string(body), rows[i])
		}
	}
}
开发者ID:jimhopp,项目名称:frederic,代码行数:53,代码来源:web_test.go

示例10: TestEditClientPage

func TestEditClientPage(t *testing.T) {
	inst, err := aetest.NewInstance(&aetest.Options{StronglyConsistentDatastore: true})
	if err != nil {
		t.Fatalf("Failed to create instance: %v", err)
	}
	defer inst.Close()

	newclient := client{Firstname: "frederic", Lastname: "ozanam"}

	id, err := addclienttodb(newclient, inst)
	if err != nil {
		t.Fatalf("unable to add client: %v", err)
	}

	sid := strconv.FormatInt(id, 10)

	url := "/editclient/" + sid
	req, err := inst.NewRequest("GET", url, nil)
	if err != nil {
		t.Fatalf("Failed to create req: %v", err)
	}

	aetest.Login(&user.User{Email: "[email protected]"}, req)

	w := httptest.NewRecorder()
	c := appengine.NewContext(req)
	addTestUser(c, "[email protected]", true)

	editclientpage(c, w, req)

	code := w.Code
	if code != http.StatusOK {
		t.Errorf("got code %v, want %v", code, http.StatusOK)
	}

	body := w.Body.Bytes()
	rows := []string{`value="frederic"`,
		`value="ozanam"`,
		`method: "PUT"`,
		`url: "/api/client/` + sid + `"`,
	}
	for i := 0; i < len(rows); i++ {
		if !bytes.Contains(body, []byte(rows[i])) {
			t.Errorf("got body %v, did not contain %v", string(body), rows[i])
		}
	}
}
开发者ID:jimhopp,项目名称:frederic,代码行数:47,代码来源:web_test.go

示例11: TestCheckAdmin

func TestCheckAdmin(t *testing.T) {
	if !isGAEtest {
		t.Skipf("not implemented yet; isGAEtest = %v", isGAEtest)
	}
	defer resetTestState(t)
	defer preserveConfig()()

	h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("ok"))
	})

	config.Whitelist = []string{"[email protected]"}
	config.Admins = []string{"[email protected]"}

	table := []struct {
		env   string
		email string
		code  int
	}{
		{"stage", "", http.StatusFound},
		{"stage", "[email protected]", http.StatusForbidden},
		{"stage", "[email protected]", http.StatusForbidden},
		{"stage", "[email protected]", http.StatusOK},
		{"prod", "", http.StatusFound},
		{"prod", "[email protected]", http.StatusForbidden},
		{"prod", "[email protected]", http.StatusForbidden},
		{"prod", "[email protected]", http.StatusOK},
	}
	for _, test := range table {
		config.Env = test.env
		w := httptest.NewRecorder()
		r := newTestRequest(t, "GET", "/", nil)
		if test.email != "" {
			aetest.Login(&user.User{Email: test.email}, r)
		}
		checkAdmin(h).ServeHTTP(w, r)

		if w.Code != test.code {
			t.Errorf("%s: w.Code = %d; want %d %s\nResponse: %s",
				test.email, w.Code, test.code, w.Header().Get("location"), w.Body.String())
		}
		if w.Code == http.StatusOK && w.Body.String() != "ok" {
			t.Errorf("w.Body = %s; want 'ok'", w.Body.String())
		}
	}
}
开发者ID:pathikdevani,项目名称:ioweb2015,代码行数:46,代码来源:server_gae_test.go

示例12: TestPostWriteHandler

func TestPostWriteHandler(t *testing.T) {
	opt := &aetest.Options{AppID: "unittest", StronglyConsistentDatastore: true}
	user := &user.User{Email: "[email protected]", Admin: true, ID: "1234567890"}
	inst, err := aetest.NewInstance(opt)
	if err != nil {
		t.Fatalf(err.Error())
	}
	defer inst.Close()
	args := "comment=TestMessage&characterID=CharacterID&vno=1&commentType=" + Public.String()
	request, err := inst.NewRequest("POST", "/write", strings.NewReader(args))
	if err != nil {
		t.Fatalf("Failed to create request: %v", err)
	}
	request.Header.Set("Content-Type", "application/x-www-form-urlencoded; param=value")
	aetest.Login(user, request)
	recoder := httptest.NewRecorder()
	context := appengine.NewContext(request)
	g := goon.FromContext(context)

	// Pre
	v := Village{No: 1}
	vKey, err := g.Put(&v)
	if err != nil {
		t.Fatalf("Failed to Put Village: %v", err)
	}
	p := Person{ParentKey: vKey, CharacterID: "CharacterID", Name: "Player1", UserID: user.ID}
	if _, err := g.Put(&p); err != nil {
		t.Fatalf("Failed to Put Person: %v", err)
	}

	villagePostWriteHandler(recoder, request)
	if recoder.Code != 302 {
		b, _ := ioutil.ReadAll(recoder.Body)
		t.Fatalf("unexpected %d, expected 302, body=%s", recoder.Code, string(b))
	}
	query := datastore.NewQuery("Post").Ancestor(vKey).Filter("Day =", 0).Order("-Time").Limit(1)
	var posts []Post
	if _, err := g.GetAll(query, &posts); err != nil || len(posts) < 1 {
		t.Fatalf("Failed to Get Post: %v", err)
	}
	po := posts[0]
	if po.Text != "TestMessage" || po.AuthorID != user.ID || po.Type != Public || po.Author != p.Name {
		t.Log(po)
		t.Fatalf("Failed: Cant't get correct Data from datastore")
	}
}
开发者ID:tSU-RooT,项目名称:Lycos,代码行数:46,代码来源:lycos_test.go

示例13: TestListClientsPageIsSorted

func TestListClientsPageIsSorted(t *testing.T) {
	inst, err := aetest.NewInstance(&aetest.Options{StronglyConsistentDatastore: true})
	if err != nil {
		t.Fatalf("Failed to create instance: %v", err)
	}
	defer inst.Close()

	newclients := []client{
		{Firstname: "Frederic", Lastname: "Ozanam"},
		{Firstname: "John", Lastname: "Doe"},
		{Firstname: "jane", Lastname: "doe"},
	}
	for i := 0; i < len(newclients); i++ {
		_, err := addclienttodb(newclients[i], inst)
		if err != nil {
			t.Fatalf("unable to add client: %v", err)
		}
	}
	req, err := inst.NewRequest("GET", "/listclients", nil)
	if err != nil {
		t.Fatalf("Failed to create req: %v", err)
	}

	aetest.Login(&user.User{Email: "[email protected]"}, req)

	w := httptest.NewRecorder()
	c := appengine.NewContext(req)
	addTestUser(c, "[email protected]", true)

	listclientspage(c, w, req)

	code := w.Code
	if code != http.StatusOK {
		t.Errorf("got code %v, want %v", code, http.StatusOK)
	}

	body := w.Body.Bytes()
	m, err := regexp.Match(`(?s).*doe.*jane.*Doe.*John.*Ozanam.*Frederic`, body)

	if err != nil {
		t.Errorf("got error on regexp match: %v", err)
	}
	if !m {
		t.Errorf("names not sorted: %v", string(body))
	}
}
开发者ID:jimhopp,项目名称:frederic,代码行数:46,代码来源:web_test.go

示例14: TestAddVisitPageForNonexistentClient

func TestAddVisitPageForNonexistentClient(t *testing.T) {
	inst, err := aetest.NewInstance(&aetest.Options{StronglyConsistentDatastore: true})
	if err != nil {
		t.Fatalf("Failed to create instance: %v", err)
	}
	defer inst.Close()

	newclient := client{Firstname: "frederic", Lastname: "ozanam"}

	id, err := addclienttodb(newclient, inst)
	if err != nil {
		t.Fatalf("unable to add client: %v", err)
	}

	id++

	sid := strconv.FormatInt(id, 10)

	url := "/recordvisit/" + sid
	req, err := inst.NewRequest("GET", url, nil)
	if err != nil {
		t.Fatalf("Failed to create req: %v", err)
	}

	aetest.Login(&user.User{Email: "[email protected]"}, req)

	w := httptest.NewRecorder()
	c := appengine.NewContext(req)
	addTestUser(c, "[email protected]", true)

	recordvisitpage(c, w, req)

	code := w.Code
	if code != http.StatusNotFound {
		t.Errorf("got code %v, want %v", code, http.StatusNotFound)
	}

	body := w.Body.Bytes()
	expected := []byte("Unable to find client with id " + sid)
	if !bytes.Contains(body, expected) {
		t.Errorf("got body %v, did not contain %v", string(body),
			string(expected))
	}
}
开发者ID:jimhopp,项目名称:frederic,代码行数:44,代码来源:web_test.go

示例15: TestAddClientPage

func TestAddClientPage(t *testing.T) {
	inst, err := aetest.NewInstance(&aetest.Options{StronglyConsistentDatastore: true})
	if err != nil {
		t.Fatalf("Failed to create instance: %v", err)
	}
	defer inst.Close()

	req, err := inst.NewRequest("GET", "/addclient", nil)
	if err != nil {
		t.Fatalf("Failed to create req: %v", err)
	}

	aetest.Login(&user.User{Email: "[email protected]"}, req)

	w := httptest.NewRecorder()
	c := appengine.NewContext(req)
	addTestUser(c, "[email protected]", true)

	newclientpage(c, w, req)

	code := w.Code
	if code != http.StatusOK {
		t.Errorf("got code %v, want %v", code, http.StatusOK)
	}

	body := w.Body.Bytes()
	rows := []string{`method: "POST"`,
		`url: "/api/client"`,
	}
	for i := 0; i < len(rows); i++ {
		if !bytes.Contains(body, []byte(rows[i])) {
			t.Errorf("got body %v, did not contain %v", string(body), rows[i])
		}
	}
	//TODO: confirm response, create new req with filled-in values, submit?
	//      Or does this call for something like Selenium?
}
开发者ID:jimhopp,项目名称:frederic,代码行数:37,代码来源:web_test.go


注:本文中的appengine/aetest.Login函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。