Exemple #1
0
    def test_blog(self):
        user = User("testUser", "*****@*****.**", "http://testImage.com")
        db.session.add(user)
        blog = Blog(user.id, "testName", "testSummary", "testContent")
        db.session.add(blog)
        db.session.commit()

        ret = Blog.query.filter_by(id=blog.id).first()
        self.assertEqual(user.id, ret.user_id)
Exemple #2
0
 def addBlog(self):
     user = self.addUser(admin=True)
     blog = Blog(user.id, self.testBlogName, self.testBlogSummary,
                 self.testBlogContent)
     db.session.add(blog)
     db.session.commit()
     ret = Blog.query.filter_by(id=blog.id).first()
     self.assertEqual(ret.id, blog.id)
     return ret
Exemple #3
0
    def test_toDict(self):
        user = User("testUser", "*****@*****.**", "http://testImage.com")
        db.session.add(user)
        blog = Blog(user.id, "testName", "testSummary", "testContent")
        db.session.add(blog)
        db.session.commit()

        ret = Blog.query.filter_by(id=blog.id).first()
        ret = toDict(ret)
        self.assertTrue("created_at" in ret)
        self.assertEqual(ret["id"], blog.id)
        self.assertTrue("id" not in ret["user"])
        self.assertEqual(ret["user"]["name"], user.name)
Exemple #4
0
    def post(self):
        if not current_user.admin:
            abort(403, message="No Permission!")
        args = self.getArgs('postBlog')

        if not args['name']:
            abort(400, message="name can not be empty!")
        if not args['summary']:
            abort(400, message="summary can not be empty!")
        if not args['content']:
            abort(400, message="content can not be empty!")

        blog = Blog(current_user.id, args['name'], args['summary'],
                    args['content'])
        db.session.add(blog)
        db.session.commit()
        ret = Blog.query.filter_by(id=blog.id).first()
        return toDict(ret)
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()