Example #1
0
func TestTag(t *testing.T) {
	fmt.Println("Start")
	models.RegistDB()
	Convey("should be test Tag", t, func() {

		Convey("get hot tags", func() {
			tags := models.GetHotTags(3)
			So(len(tags), ShouldEqual, 3)
		})
		Convey("get blog count", func() {
			tags := models.GetHotTags(3)
			count := tags[0].GetBlogCount()
			So(count, ShouldBeGreaterThan, 0)
		})
		Convey("get blogs", func() {

			tags := models.GetHotTags(3)
			tag := &models.Tag{Id: tags[0].Id}
			So(len(tag.Blogs), ShouldEqual, 0)
			tag.Get()
			So(len(tag.Blogs), ShouldBeGreaterThan, 0)
		})
		// tag := models.NewTag("TEST", -1)
		// Convey("`tag` should not be nil", func() {
		// 	So(tag, ShouldNotBeNil)
		// })
		// Convey("update tag to database", func() {
		// 	tag.Name = "Test"
		// 	tag.ParentId = -2
		// 	e := tag.Update()
		// 	So(e, ShouldEqual, nil)
		// })
		// Convey("get tag by name", func() {
		// 	t := models.GetTag("linux")
		// 	fmt.Println("new tag", t)
		// 	So(t.Id, ShouldNotEqual, 0)
		// })
		// Convey("delete tag to database", func() {
		// 	e := tag.Delete()
		// 	So(e, ShouldEqual, nil)
		// })
	})
}
Example #2
0
func TestBlog(t *testing.T) {
	models.RegistDB()
	Convey("should be test Blog", t, func() {
		blog := &models.Blog{
			Title:   "Test Blog",
			Summary: "Test Blog content ",
			Content: "something test",
		}
		Convey("`blog` should not be nil", func() {
			So(blog, ShouldNotBeNil)
		})
		Convey("insert blog to database", func() {
			e := blog.Insert()
			So(e, ShouldEqual, nil)
		})
		Convey("update blog to database", func() {
			blog.Insert()
			blog.Title = "Test Blog(new)"
			blog.Status = -1
			e := blog.Update()
			So(e, ShouldEqual, nil)
		})
		Convey("get blog by id", func() {
			blog.Insert()
			newblog, e := models.GetBlogById(blog.Id)
			So(e, ShouldEqual, nil)
			So(newblog.Title, ShouldEqual, blog.Title)
		})
		Convey("write blog into db", func() {
			blog.AddTagName("tag1")
			blog.AddTagName("tag5")
			blog.AddTagName("tag3")
			e := blog.WriteToDB()
			So(e, ShouldEqual, nil)
		})
	})
}
Example #3
0
func init() {
	_, file, _, _ := runtime.Caller(1)
	apppath, _ := filepath.Abs(filepath.Dir(filepath.Join(file, ".."+string(filepath.Separator))))
	beego.TestBeegoInit(apppath)
	models.RegistDB()
}
Example #4
0
func db_init() {
	models.RegistDB()
}