Permalink
Browse files

Split out a dev file for easy testing

  • Loading branch information...
mjibson committed Feb 25, 2014
1 parent e1f3af0 commit 6ff438e1d1e9c4bb708a5765b5324482eca632e2
Showing with 114 additions and 61 deletions.
  1. +110 −0 dev.go
  2. +2 −3 main.go
  3. +2 −58 user.go
View
110 dev.go
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 2013 Matt Jibson <matt.jibson@gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+package goapp
+
+import (
+ "fmt"
+ "net/http"
+ "time"
+
+ mpg "github.com/MiniProfiler/go/miniprofiler_gae"
+ "github.com/mjibson/goon"
+
+ "appengine/datastore"
+ "appengine/user"
+)
+
+func init() {
+ if !isDevServer {
+ return
+ }
+ router.Handle("/user/clear-feeds", mpg.NewHandler(ClearFeeds)).Name("clear-feeds")
+ router.Handle("/test/atom.xml", mpg.NewHandler(TestAtom)).Name("test-atom")
+}
+
+func ClearFeeds(c mpg.Context, w http.ResponseWriter, r *http.Request) {
+ if !isDevServer {
+ return
+ }
+
+ cu := user.Current(c)
+ gn := goon.FromContext(c)
+ done := make(chan bool)
+ go func() {
+ u := &User{Id: cu.ID}
+ defer func() { done <- true }()
+ ud := &UserData{Id: "data", Parent: gn.Key(u)}
+ if err := gn.Get(u); err != nil {
+ c.Errorf("user del err: %v", err.Error())
+ return
+ }
+ gn.Get(ud)
+ u.Read = time.Time{}
+ ud.Read = nil
+ ud.Opml = nil
+ gn.PutMulti([]interface{}{u, ud})
+ c.Infof("%v cleared", u.Email)
+ }()
+ del := func(kind string) {
+ defer func() { done <- true }()
+ q := datastore.NewQuery(kind).KeysOnly()
+ keys, err := gn.GetAll(q, nil)
+ if err != nil {
+ c.Errorf("err: %v", err.Error())
+ return
+ }
+ if err := gn.DeleteMulti(keys); err != nil {
+ c.Errorf("err: %v", err.Error())
+ return
+ }
+ c.Infof("%v deleted", kind)
+ }
+ types := []interface{}{
+ &Feed{},
+ &Story{},
+ &StoryContent{},
+ &Log{},
+ &UserOpml{},
+ }
+ for _, i := range types {
+ k := gn.Kind(i)
+ go del(k)
+ }
+
+ for i := 0; i < len(types); i++ {
+ <-done
+ }
+
+ http.Redirect(w, r, fmt.Sprintf("%s?url=http://localhost:8080%s", routeUrl("add-subscription"), routeUrl("test-atom")), http.StatusFound)
+}
+
+func TestAtom(c mpg.Context, w http.ResponseWriter, r *http.Request) {
+ w.Write([]byte(testAtom))
+}
+
+const testAtom = `<?xml version="1.0"?>
+
+<feed xmlns="http://www.w3.org/2005/Atom">
+ <title>goread atom test</title>
+<entry><id>1</id><title>1 A look at &lt;em>em&lt;/em></title></entry>
+<entry><id>2</id><title type="html">2 A look at &lt;em>em&lt;/em></title></entry>
+<entry>
+ <id>4</id>
+ <title>Issue 8311 created: &quot;HtmlElementBuilder doesn&#39;t allow &lt;col&gt; elements in &lt;colgroup&gt;&quot;</title>
+</entry>
+</feed>
+`
View
@@ -25,12 +25,12 @@ import (
"net/url"
"time"
- "appengine"
- "appengine/datastore"
"github.com/MiniProfiler/go/miniprofiler"
mpg "github.com/MiniProfiler/go/miniprofiler_gae"
"github.com/gorilla/mux"
"github.com/mjibson/goon"
+ "appengine"
+ "appengine/datastore"
)
var router = new(mux.Router)
@@ -62,7 +62,6 @@ func init() {
router.Handle("/tasks/delete-old-feeds", mpg.NewHandler(DeleteOldFeeds)).Name("delete-old-feeds")
router.Handle("/tasks/delete-old-feed", mpg.NewHandler(DeleteOldFeed)).Name("delete-old-feed")
router.Handle("/user/add-subscription", mpg.NewHandler(AddSubscription)).Name("add-subscription")
- router.Handle("/user/clear-feeds", mpg.NewHandler(ClearFeeds)).Name("clear-feeds")
router.Handle("/user/delete-account", mpg.NewHandler(DeleteAccount)).Name("delete-account")
router.Handle("/user/export-opml", mpg.NewHandler(ExportOpml)).Name("export-opml")
router.Handle("/user/feed-history", mpg.NewHandler(FeedHistory)).Name("feed-history")
View
60 user.go
@@ -33,13 +33,13 @@ import (
"sync"
"time"
+ mpg "github.com/MiniProfiler/go/miniprofiler_gae"
+ "github.com/mjibson/goon"
"appengine"
"appengine/blobstore"
"appengine/datastore"
"appengine/taskqueue"
"appengine/user"
- mpg "github.com/MiniProfiler/go/miniprofiler_gae"
- "github.com/mjibson/goon"
"sanitizer"
)
@@ -555,62 +555,6 @@ func GetContents(c mpg.Context, w http.ResponseWriter, r *http.Request) {
w.Write(b)
}
-func ClearFeeds(c mpg.Context, w http.ResponseWriter, r *http.Request) {
- if !isDevServer {
- return
- }
-
- cu := user.Current(c)
- gn := goon.FromContext(c)
- done := make(chan bool)
- go func() {
- u := &User{Id: cu.ID}
- defer func() { done <- true }()
- ud := &UserData{Id: "data", Parent: gn.Key(u)}
- if err := gn.Get(u); err != nil {
- c.Errorf("user del err: %v", err.Error())
- return
- }
- gn.Get(ud)
- u.Read = time.Time{}
- ud.Read = nil
- ud.Opml = nil
- gn.PutMulti([]interface{}{u, ud})
- c.Infof("%v cleared", u.Email)
- }()
- del := func(kind string) {
- defer func() { done <- true }()
- q := datastore.NewQuery(kind).KeysOnly()
- keys, err := gn.GetAll(q, nil)
- if err != nil {
- c.Errorf("err: %v", err.Error())
- return
- }
- if err := gn.DeleteMulti(keys); err != nil {
- c.Errorf("err: %v", err.Error())
- return
- }
- c.Infof("%v deleted", kind)
- }
- types := []interface{}{
- &Feed{},
- &Story{},
- &StoryContent{},
- &Log{},
- &UserOpml{},
- }
- for _, i := range types {
- k := gn.Kind(i)
- go del(k)
- }
-
- for i := 0; i < len(types); i++ {
- <-done
- }
-
- http.Redirect(w, r, routeUrl("main"), http.StatusFound)
-}
-
func ExportOpml(c mpg.Context, w http.ResponseWriter, r *http.Request) {
cu := user.Current(c)
gn := goon.FromContext(c)

0 comments on commit 6ff438e

Please sign in to comment.