// getIEPGURLResolver returns iepgURLResolver object. // the mock object in '__test_iepg_url_resolver' local variable in the request can be used for testing. func getIEPGURLResolver(req *wcg.Request) *iepgURLResolver { if req.IsTest() { if v := req.Local("__test_iepg_url_resolver"); v != nil { if v1, ok := v.(*iepgURLResolver); ok { return v1 } } } return defaultIEPGURLResolver }
// PushTask to push a task into the queue. func (queue *PushQueue) PushTask(req *wcg.Request, urlPath string, form url.Values) error { var queueName string if req.IsTest() || lib.IsOnLocalGAE() { queueName = "default" } else { queueName = queue.Name } if _, err := taskqueue.Add(gae.NewContext(req), taskqueue.NewPOSTTask(urlPath, form), queueName); err != nil { req.Logger.Errorf("[Queue] Error adding a task (%s) into the queue (%q): %v", urlPath, queueName, err) return err } return nil }
func newRemoteAPIContext(req *wcg.Request, host string) (context.Context, error) { // TODO: migrate file to datastore? if !lib.IsOnLocalGAE() && !req.IsTest() { return nil, fmt.Errorf("RemoteAPI use on GAE is not supported yet.") } var hc *http.Client var err error const defaultCredentialEnvKey = "GOOGLE_APPLICATION_CREDENTIALS" if os.Getenv(defaultCredentialEnvKey) != "" { hc, err = google.DefaultClient(gae.NewContext(req), remoteCtxScopes...) } else { return nil, ErrNoRemoteAPIKeyIsConfigured } if err != nil { return nil, err } return remote_api.NewRemoteContext(host, hc) }
func newMediaClient(req *wcg.Request) (*media.Client, error) { const fallbackServer = "speedland-ng-dev.appspot.com" kind := entities.OAuth2ClientSettings if lib.IsOnLocalGAE() || req.IsTest() { kind = kind.NewRemote(fallbackServer) } _, settings, err := kind.Get().Key(OAuth2ClientKey).One(req) if err != nil { return nil, err } if settings == nil { if lib.IsOnLocalGAE() || req.IsTest() { return nil, fmt.Errorf("OAuthClient `%s` is not configured on %s", OAuth2ClientKey, fallbackServer) } return nil, fmt.Errorf("OAuthClient `%s` is not configured", OAuth2ClientKey) } return media.NewClient( settings.(*models.OAuth2ClientSettings).GenClient(urlfetch.NewContext(req)), ), nil }