def test_toDict(self): category = Category(name='testCategory', image='http://testImage', about='testAbout') db.session.add(category) db.session.commit() course = Course(name="testCourseName", image='http://testImage', about='testAbout', category_id=category.id) db.session.add(course) chapter = Chapter(course.id, 1, "testChapter1", "http://testVideoUrl", "testContent") db.session.add(chapter) db.session.commit() ret = Chapter.query.filter_by(id=chapter.id).first() ret = toDict(ret) self.assertTrue("created_at" in ret) self.assertEqual(ret["id"], chapter.id) self.assertEqual(ret["order"], 1) self.assertEqual(ret["name"], "testChapter1") self.assertEqual(ret["video_url"], "http://testVideoUrl") self.assertEqual(ret["content"], "testContent") self.assertEqual(ret["course_id"], chapter.course_id)
def addCategory(self): category = Category(name='testCategory', image='http://testImage', about='testAbout') db.session.add(category) db.session.commit() ret = Category.query.filter_by(id=category.id).first() self.assertEqual(ret.id, category.id) return ret
def test_toDict(self): category = Category(name='testCategory', image='http://testImage', about='testAbout') db.session.add(category) db.session.commit() ret = category.query.filter_by(id=category.id).first() ret = toDict(ret) self.assertTrue("created_at" in ret) self.assertEqual(ret["id"], category.id) self.assertEqual(ret["name"], "testCategory")
def post(self): if not current_user.admin: abort(403, message="No Permission!") args = self.getArgs('postCategory') self.abortIfArgsEmpty(args, [ArgCategoryName, ArgCategoryImage, ArgCategoryAbout]) category = Category(*(args[i.name] for i in [ArgCategoryName, ArgCategoryImage, ArgCategoryAbout])) db.session.add(category) db.session.commit() ret = Category.query.filter_by(id=category.id).first() return toDict(ret)
def test_course(self): category = Category(name='testCategory', image='http://testImage', about='testAbout') db.session.add(category) db.session.commit() course = Course(name="testCourseName", image='http://testImage', about='testAbout', category_id=category.id) db.session.add(course) db.session.commit() ret = course.query.filter_by(id=course.id).first() self.assertEqual(ret.name, "testCourseName")
def test_chapter(self): category = Category(name='testCategory', image='http://testImage', about='testAbout') db.session.add(category) db.session.commit() course = Course(name="testCourseName", image='http://testImage', about='testAbout', category_id=category.id) db.session.add(course) chapter = Chapter(course.id, 1, "testChapter1", "http://testVideoUrl", "testContent") db.session.add(chapter) db.session.commit() ret = Chapter.query.filter_by(id=chapter.id).first() self.assertEqual(ret.order, 1) self.assertEqual(ret.name, "testChapter1") self.assertEqual(ret.video_url, "http://testVideoUrl") self.assertEqual(ret.content, "testContent")
def opt_init(): from edustack.models import db from edustack.models.user import LocalAuth, User from edustack.models.blog import Blog, Comment from edustack.models.course import Course, Chapter, Category def add_local_user(name, email, admin=False): emailHash = hashlib.md5(email).hexdigest() image = r"http://www.gravatar.com/avatar/{0}?d=mm&s=120".format( emailHash) if admin: image = r"http://tp3.sinaimg.cn/2804214754/180/5668812169/1" db.session.add(User(name, email, image, admin)) db.session.commit() user = User.query.filter_by(email=email).first() db.session.add(LocalAuth(user.id, password=emailHash)) db.session.commit() return user adminUser = add_local_user("admin", "*****@*****.**", admin=True) add_local_user("test1", "*****@*****.**") add_local_user("test2", "*****@*****.**") blogStr = """ An h1 header ============ Paragraphs are separated by a blank line. 2nd paragraph. *Italic*, **bold**, and `monospace`. Itemized lists look like: * this one * that one * the other one and images can be specified like so: ![example image](http://www.unexpected-vortices.com/sw/rippledoc/example-image.jpg "An exemplary image") """ for i in range(6): blog = Blog(user_id=adminUser.id, name="Markdown2 Example {0}".format(i), summary="Example about Markdown blog {0}".format(i), content=blogStr) db.session.add(blog) comment = Comment( adminUser.id, blog.id, "http://www.unexpected-" "vortices.com/sw/rippledoc/quick-markdown-example.html") db.session.add(comment) db.session.commit() for i in range(5): category = Category( name='Category {0}'.format(i), image= 'https://raw.githubusercontent.com/wu-wenxiang/Media-WebLink/master/qiniu/Test-f4f338218d4245cf8fad114381f0e30a-CloudTools.png', about='Test About Category') db.session.add(category) db.session.commit() for j in range(12): course = Course( name='Course {0}'.format(j), image= 'https://raw.githubusercontent.com/wu-wenxiang/Media-WebLink/master/qiniu/Test-f4f338218d4245cf8fad114381f0e30a-CloudTools.png', about='Test About Text', category_id=category.id) db.session.add(course) db.session.commit() for k in range(1, 9): chapter = Chapter( course_id=course.id, order=k, name='Chapter {0}'.format(k), video_url= 'https://raw.githubusercontent.com/wu-wenxiang/Media-WebLink/master/qiniu/Test-f4f338218d4245cf8fad114381f0e30a-sport.mp4', content='Test Chapter Content') db.session.add(chapter) db.session.commit() db.session.commit()