本文整理汇总了Golang中lib/server/testhelper.TemporaryAllow函数的典型用法代码示例。如果您正苦于以下问题:Golang TemporaryAllow函数的具体用法?Golang TemporaryAllow怎么用?Golang TemporaryAllow使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TemporaryAllow函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Test_API_Tasks_Crawlers_Ameblo_Posts
func Test_API_Tasks_Crawlers_Ameblo_Posts(t *testing.T) {
assert := gaetest.NewAssert(t)
assert.Nil(gaetest.ResetFixtureFromFile(ts.Context, "./fixtures/Test_API_Tasks_Crawlers_Ameblo_Posts.json", nil, "hplink"), "fixture")
p := entities.AmebloPost.Query().MustExecute(ts.GET("/").Request)
postList := p.Data.([]hplink.AmebloPost)
assert.EqInt(1, len(postList))
httptest.StartMockServer(func(mock *httptest.MockServer) {
mock.Routes().GET("/morningmusume-9ki/post.html", middleware.ServeFile("./fixtures/mocks/ameblo.jp//morningmusume-9ki/post.html"))
crawler.MockExternalResource(map[string]string{
"http://ameblo.jp/morningmusume-9ki/entry-12201946654.html": fmt.Sprintf("%s//morningmusume-9ki/post.html", mock.BaseURL()),
}, func() {
runner := testhelper.NewAsyncTaskTestRunner(t, instance.Routes(), ts)
runner.OnMonitor(func(testreq *httptest.TestRequest, f func()) {
testhelper.TemporaryAllow(testreq, "hplink.admin", f)
})
runner.OnTrigger(func(testreq *httptest.TestRequest, f func()) {
testhelper.TemporaryAllow(testreq, "hplink.admin", f)
})
runner.Run("/api/hplink/tasks/crawlers/ameblo/posts/", url.Values{})
p := entities.AmebloPost.Query().MustExecute(ts.GET("/").Request)
postList := p.Data.([]hplink.AmebloPost)
assert.EqInt(1, len(postList))
assert.EqStr("ノーメイク☆譜久村聖", postList[0].Title)
assert.EqStr("譜久村聖", postList[0].Theme)
assert.EqStr("morningmusume.mizuki_fukumura", postList[0].MemberKey)
// It also creates a URL cache
assert.EqInt(1, entities.URLCache.Query().MustCount(ts.GET("/").Request))
})
})
}
示例2: Test_API_IEPGRecord_OptInOut_Excluded
func Test_API_IEPGRecord_OptInOut_Excluded(t *testing.T) {
assert := gaetest.NewAssert(t)
assert.Nil(gaetest.ResetFixtureFromFile(ts.Context, "./fixtures/Test_API_IEPGRecord_OptInOut.json", nil, "intern.pt"), "fixture")
req := ts.PUTForm(fmt.Sprintf("/api/intern/pt/iepg/records/%s/opt-in/", "excluded"), url.Values{
"opt_in": []string{"1"},
})
helper.TemporaryAllow(req, "family", func() {
var got pt.IEPG
res := req.RouteTo(instance.Routes())
assert.HTTPStatus(200, res)
assert.JSONResponse(&got, res)
assert.OK(got.OptIn, "OptIn")
assert.OK(!got.OptOut, "OptOut")
})
req = ts.PUTForm(fmt.Sprintf("/api/intern/pt/iepg/records/%s/opt-in/", "excluded"), url.Values{
"opt_in": []string{"0"},
})
helper.TemporaryAllow(req, "family", func() {
var got pt.IEPG
res := req.RouteTo(instance.Routes())
assert.HTTPStatus(200, res)
assert.JSONResponse(&got, res)
assert.OK(!got.OptIn, "OptIn")
assert.OK(!got.OptOut, "OptOut")
})
}
示例3: Test_API_Tasks_Crawlers_Ameblo_EntryLists
func Test_API_Tasks_Crawlers_Ameblo_EntryLists(t *testing.T) {
assert := gaetest.NewAssert(t)
assert.Nil(gaetest.ResetFixtureFromFile(ts.Context, "./fixtures/Test_API_Tasks_Crawlers_Ameblo_EntryLists.json", nil, "hplink"), "fixture")
httptest.StartMockServer(func(mock *httptest.MockServer) {
mock.Routes().GET("/morningmusume-9ki/entrylist.html", middleware.ServeFile("./fixtures/mocks/ameblo.jp//morningmusume-9ki/entrylist.html"))
crawler.MockExternalResource(map[string]string{
"http://ameblo.jp/morningmusume-9ki/entrylist.html": fmt.Sprintf("%s//morningmusume-9ki/entrylist.html", mock.BaseURL()),
}, func() {
runner := testhelper.NewAsyncTaskTestRunner(t, instance.Routes(), ts)
runner.OnMonitor(func(testreq *httptest.TestRequest, f func()) {
testhelper.TemporaryAllow(testreq, "hplink.admin", f)
})
runner.OnTrigger(func(testreq *httptest.TestRequest, f func()) {
testhelper.TemporaryAllow(testreq, "hplink.admin", f)
})
runner.Run("/api/hplink/tasks/crawlers/ameblo/entrylists/", url.Values{})
p := entities.AmebloPost.Query().Order("-PostAt").MustExecute(ts.GET("/").Request)
postList := p.Data.([]hplink.AmebloPost)
assert.EqInt(20, len(postList))
assert.EqStr("ノーメイク☆譜久村聖", postList[0].Title)
assert.EqStr("", postList[0].Theme)
assert.EqStr("morningmusume.mizuki_fukumura", postList[0].MemberKey)
assert.EqStr("http://ameblo.jp/morningmusume-9ki/", postList[0].SettingsURL)
p = entities.CrawlerSettings.Query().Filter("URL=", "http://ameblo.jp/morningmusume-9ki/").MustExecute(ts.GET("/").Request)
assert.EqInt(1, p.Length())
settings := p.Head().(*hplink.CrawlerSettings)
assert.EqInt(int(hplink.CrawlerStatusSuccess), int(settings.Status))
})
})
}
示例4: Test_API_Task_Sync
func Test_API_Task_Sync(t *testing.T) {
assert := gaetest.NewAssert(t)
gaetest.CleanupDatastore(ts.Context, "hplink")
httptest.StartMockServer(func(mock *httptest.MockServer) {
mock.Routes().GET("/", middleware.ServeFile("./fixtures/mocks/helloproject.html"))
mock.Routes().GET("/c-ute/", middleware.ServeFile("./fixtures/mocks/c-ute/index.html"))
mock.Routes().GET("/c-ute/*", middleware.StaticFile("", "fixtures/mocks/c-ute/"))
crawler.MockExternalResource(map[string]string{
"http://www.helloproject.com/artist/": fmt.Sprintf("%s", mock.BaseURL()),
"http://www.helloproject.com/artist/c-ute/": fmt.Sprintf("%sc-ute/", mock.BaseURL()),
"http://www.helloproject.com/artist/c-ute/profile/maimi_yajima/": fmt.Sprintf("%sc-ute/maimi_yajima.html", mock.BaseURL()),
"http://www.helloproject.com/artist/c-ute/profile/saki_nakajima/": fmt.Sprintf("%sc-ute/saki_nkajima.html", mock.BaseURL()),
"http://www.helloproject.com/artist/c-ute/profile/airi_suzuki/": fmt.Sprintf("%sc-ute/airi_suzuki.html", mock.BaseURL()),
"http://www.helloproject.com/artist/c-ute/profile/chisato_okai/": fmt.Sprintf("%sc-ute/chisato_okai.html", mock.BaseURL()),
"http://www.helloproject.com/artist/c-ute/profile/mai_hagiwara/": fmt.Sprintf("%sc-ute/mai_hagiwara.html", mock.BaseURL()),
}, func() {
runner := testhelper.NewAsyncTaskTestRunner(t, instance.Routes(), ts)
runner.OnMonitor(func(testreq *httptest.TestRequest, f func()) {
testhelper.TemporaryAllow(testreq, "hplink.admin", f)
})
runner.OnTrigger(func(testreq *httptest.TestRequest, f func()) {
testhelper.TemporaryAllow(testreq, "hplink.admin", f)
})
runner.Run("/api/hplink/tasks/profile/", url.Values{})
p := entities.Artist.Query().Order("Index").MustExecute(ts.GET("/").Request)
artistList := p.Data.([]hplink.Artist)
assert.EqInt(1, len(artistList))
assert.EqInt(0, artistList[0].Index)
assert.EqStr("c-ute", artistList[0].Key)
assert.EqStr("℃-ute", artistList[0].Name)
p = entities.Member.Query().Order("Index").Filter("ArtistKey=", "c-ute").MustExecute(ts.GET("/").Request)
memberList := p.Data.([]hplink.Member)
assert.EqInt(5, len(memberList))
assert.EqInt(0, memberList[0].Index)
assert.EqStr("c-ute", memberList[0].ArtistKey)
assert.EqStr("c-ute.maimi_yajima", memberList[0].Key)
assert.EqStr("矢島舞美", memberList[0].Name)
entities.FillMemberPublicProfiles(ts.GET("/").Request, memberList)
assert.NotNil(memberList[0].PublicProfile)
assert.EqStr("c-ute.maimi_yajima", memberList[0].PublicProfile.Key)
assert.EqStr("埼玉県", memberList[0].PublicProfile.Hometown)
_, settings := entities.CrawlerSettings.Get().Key("http://ameblo.jp/c-ute-official").MustOne(ts.GET("/").Request)
assert.NotNil(settings)
assert.EqStr("c-ute", settings.(*hplink.CrawlerSettings).ArtistKey)
assert.EqInt(int(hplink.CrawlerSettingsTypeAmeblo), int(settings.(*hplink.CrawlerSettings).Type))
})
})
}
示例5: Test_API_POST_Me_Gates
func Test_API_POST_Me_Gates(t *testing.T) {
assert := gaetest.NewAssert(t)
app := NewApp()
req := ts.POSTForm("/api/users/me/gates/", url.Values{
"keys": []string{"foo"},
})
res := req.RouteTo(app.Routes())
assert.HTTPStatus(200, res)
var got map[string]bool
assert.JSONResponse(&got, res)
assert.EqInt(1, len(got))
assert.Not(got["foo"])
req = ts.POSTForm("/api/users/me/gates/", url.Values{
"keys": []string{"foo"},
})
testhelper.TemporaryAllow(req, "foo", func() {
res := req.RouteTo(app.Routes())
assert.HTTPStatus(200, res)
var got map[string]bool
assert.JSONResponse(&got, res)
assert.EqInt(1, len(got))
assert.OK(got["foo"])
})
}
示例6: Test_API_Config_Put
func Test_API_Config_Put(t *testing.T) {
assert := gaetest.NewAssert(t)
testUser := httptest.NewTestUser().SetID("facebook:12345")
dummy := ts.GET("/")
configs.TemporarySetConfig(dummy.Request,
"facebook_page_id", "12345",
func() {
messenger.TemporaryOptIn(dummy.Request,
"12345", testUser.ID(),
func() {
var notif pt.MessengerNotification
req := ts.PUTForm("/api/intern/pt/configs/facebook%3A12345/messenger.json", url.Values{
"id": []string{"messenger"},
"user_id": []string{"testuser"},
"summary": []string{"true"},
"on_start": []string{"true"},
"on_end": []string{"false"},
})
req.Request.User = testUser
helper.TemporaryAllow(req, "family", func() {
res := req.RouteTo(instance.Routes())
assert.HTTPStatus(200, res)
assert.JSONResponse(¬if, res)
assert.EqStr("testuser", notif.UserID, "MessengerNotification.UserID")
assert.OK(notif.Summary, "MessengerNotification.Summary")
assert.OK(notif.OnStart, "MessengerNotification.OnStart")
assert.OK(!notif.OnEnd, "MessengerNotification.OnEnd")
})
},
)
},
)
}
示例7: Test_API_IEPGRecord_Delete
func Test_API_IEPGRecord_Delete(t *testing.T) {
assert := gaetest.NewAssert(t)
assert.Nil(gaetest.ResetFixtureFromFile(ts.Context, "./fixtures/Test_API_IEPGRecord_Delete.json", nil, "intern.pt"), "fixture")
req := ts.DELETE(fmt.Sprintf("/api/intern/pt/iepg/records/%s.json", "iepg1"))
helper.TemporaryAllow(req, "family", func() {
res := req.RouteTo(instance.Routes())
assert.HTTPStatus(200, res)
})
req = ts.DELETE(fmt.Sprintf("/api/intern/pt/iepg/records/%s.json", "iepg2"))
helper.TemporaryAllow(req, "family", func() {
res := req.RouteTo(instance.Routes())
assert.HTTPStatus(403, res)
})
}
示例8: Test_API_Config_Get_Default
func Test_API_Config_Get_Default(t *testing.T) {
assert := gaetest.NewAssert(t)
assert.Nil(gaetest.ResetFixtureFromFile(ts.Context, "./fixtures/Test_API_Config_Get.json", nil), "fixture")
testUser := httptest.NewTestUser().SetID("facebook:6789")
dummy := ts.GET("/")
configs.TemporarySetConfig(dummy.Request,
"facebook_page_id", "12345",
func() {
messenger.TemporaryOptIn(dummy.Request,
"12345", testUser.ID(),
func() {
var notif pt.MessengerNotification
req := ts.GET("/api/intern/pt/configs/facebook%3A6789/messenger.json")
req.Request.User = testUser
helper.TemporaryAllow(req, "family", func() {
res := req.RouteTo(instance.Routes())
assert.HTTPStatus(200, res)
assert.JSONResponse(¬if, res)
assert.EqStr("facebook:6789", notif.UserID, "MessengerNotification.UserID")
assert.OK(!notif.Summary, "MessengerNotification.Summary")
assert.OK(!notif.OnStart, "MessengerNotification.OnStart")
assert.OK(!notif.OnEnd, "MessengerNotification.OnEnd")
})
},
)
},
)
}
示例9: Test_API_IEPGExclusion_Delete
func Test_API_IEPGExclusion_Delete(t *testing.T) {
assert := gaetest.NewAssert(t)
req := ts.DELETE("/api/intern/pt/channels/test1.json")
helper.TemporaryAllow(req, "family", func() {
res := req.RouteTo(instance.Routes())
assert.HTTPStatus(200, res)
})
}
示例10: Test_API_CrawlerSettings_Delete
func Test_API_CrawlerSettings_Delete(t *testing.T) {
assert := gaetest.NewAssert(t)
assert.Nil(gaetest.ResetFixtureFromFile(ts.Context, "./fixtures/Test_API_CrawlerSettings_Delete.json", nil, "hplink"), "fixture")
req := ts.DELETE("/api/hplink/crawlersettings/http%3A%2F%2Fameblo.jp%2Fc-ute-official%2F.json")
testhelper.TemporaryAllow(req, "hplink.admin", func() {
res := req.RouteTo(instance.Routes())
assert.HTTPStatus(200, res)
_, settings := entities.CrawlerSettings.Get().Key("http://ameblo.jp/c-ute-official/").MustOne(ts.GET("/").Request)
assert.Nil(settings)
})
}
示例11: Test_API_IEPGRecord_OptInOut_NonAutoCollected
func Test_API_IEPGRecord_OptInOut_NonAutoCollected(t *testing.T) {
assert := gaetest.NewAssert(t)
assert.Nil(gaetest.ResetFixtureFromFile(ts.Context, "./fixtures/Test_API_IEPGRecord_OptInOut.json", nil, "intern.pt"), "fixture")
req := ts.PUTForm(fmt.Sprintf("/api/intern/pt/iepg/records/%s/opt-in/", "iepg1"), url.Values{
"opt_in": []string{"1"},
})
helper.TemporaryAllow(req, "family", func() {
res := req.RouteTo(instance.Routes())
assert.HTTPStatus(400, res)
})
}
示例12: Test_API_IEPGExclusion_RunTask
func Test_API_IEPGExclusion_RunTask(t *testing.T) {
assert := gaetest.NewAssert(t)
assert.Nil(gaetest.ResetFixtureFromFile(ts.Context, "./fixtures/Test_API_IEPGExclusion_RunTask.json", nil, "intern.pt"))
now, _ := wcg.ParseDateTime("2016-01-01T00:00:00Z")
lib.TemporarySetNow(now, func() {
runner := helper.NewAsyncTaskTestRunner(t, instance.Routes(), ts)
runner.OnTrigger(func(req *httptest.TestRequest, trigger func()) {
helper.TemporaryAllow(req, "family", trigger)
})
runner.OnMonitor(func(req *httptest.TestRequest, monitor func()) {
helper.TemporaryAllow(req, "family", monitor)
})
runner.Run("/api/intern/pt/iepg/exclusions/task/", url.Values{})
req := ts.GET("/dummy")
_, flagged := IEPG.Get().Key("test1").MustOne(req.Request)
assert.OK(len(flagged.(*pt.IEPG).ExcludedBy) > 0)
})
}
示例13: Test_API_Config_Get_NoPageIDConfigured
func Test_API_Config_Get_NoPageIDConfigured(t *testing.T) {
assert := gaetest.NewAssert(t)
dummy := ts.GET("/")
configs.TemporarySetConfig(dummy.Request,
"facebook_page_id", "",
func() {
req := ts.GET("/api/intern/pt/configs/facebook%3A12345/messenger.json")
helper.TemporaryAllow(req, "family", func() {
res := req.RouteTo(instance.Routes())
assert.HTTPStatus(403, res)
})
},
)
}
示例14: Test_API_IEPGRecord_Put
func Test_API_IEPGRecord_Put(t *testing.T) {
assert := gaetest.NewAssert(t)
assert.Nil(gaetest.ResetFixtureFromFile(ts.Context, "./fixtures/Test_API_IEPGRecord_Put.json", nil, "intern.pt"), "fixture")
req := ts.PUTForm(fmt.Sprintf("/api/intern/pt/iepg/records/%s.json", "iepg1"), url.Values{
"program_title": []string{"Test Program"},
"start_at": []string{"2015-01-01T19:00:00.000Z"},
"end_at": []string{"2015-01-01T19:00:00.000Z"},
"category": []string{"test"},
"cid": []string{"21"},
"sid": []string{"aa"},
})
helper.TemporaryAllow(req, "family", func() {
res := req.RouteTo(instance.Routes())
assert.HTTPStatus(200, res)
var got pt.IEPG
assert.JSONResponse(&got, res)
assert.EqStr("Test Program", got.ProgramTitle, "program_title")
assert.EqStr("21", got.CID, "CID")
assert.EqStr("aa", got.SID, "SID")
assert.EqInt(int(pt.IEPGSourceUser), int(got.Source), "Source")
})
req = ts.PUTForm(fmt.Sprintf("/api/intern/pt/iepg/records/%s.json", "iepg2"), url.Values{
"program_title": []string{"Test Program"},
"start_at": []string{"2015-01-01T19:00:00.000Z"},
"end_at": []string{"2015-01-01T19:00:00.000Z"},
"category": []string{"test"},
"cid": []string{"21"},
"sid": []string{"aa"},
})
helper.TemporaryAllow(req, "family", func() {
res := req.RouteTo(instance.Routes())
assert.HTTPStatus(403, res)
})
}
示例15: Test_API_IEPGKeyword_Post
func Test_API_IEPGKeyword_Post(t *testing.T) {
assert := gaetest.NewAssert(t)
req := ts.POSTForm("/api/intern/pt/iepg/keywords/", url.Values{
"keyword": []string{"テストキーワード"},
"scope": []string{"1"},
"category": []string{"カテゴリ"},
})
helper.TemporaryAllow(req, "family", func() {
res := req.RouteTo(instance.Routes())
assert.HTTPStatus(201, res)
var got pt.IEPGKeyword
assert.JSONResponse(&got, res)
assert.EqStr("テストキーワード", got.Keyword, "IEPGKeyword.Keyword")
})
}