Esempio n. 1
0
def test_json():
    """Test the json representation of a blog."""
    blog = Blog("Test", "Test Author")
    blog.create_post("Test", "Test Content")
    expected = {"title": "Test", "author": "Test Author", "posts": [{"title": "Test", "content": "Test Content"}]}

    assert blog.json() == expected
Esempio n. 2
0
    def new_blog(self, title, description):
        blog = Blog(author=self.email,
                    title=title,
                    description=description,
                    author_id=self._id)

        blog.save_to_mongo()
Esempio n. 3
0
def test_create_post_in_blog():
    """Tests if a post is created in a blog. """
    blog = Blog("Test", "Test Author")
    blog.create_post("Test Post", "Test Content")

    assert len(blog.posts) == 1
    assert blog.posts[0].title == "Test Post"
    assert blog.posts[0].content == "Test Content"
Esempio n. 4
0
def create_new_blog():
    if request.method == 'GET':
        return render_template('new_blog.html')
    else:
        title = request.form['title']
        description = request.form['description']
        user = Member.get_by_email(session['email'])

        new_blog = Blog(user.email, title, description, user._id)
        new_blog.save_to_mongo()

        return make_response(user_blogs(user._id))
Esempio n. 5
0
def test_create_blog():
    """Test the creation of a blog."""
    blog = Blog("Test", "Test Author")

    assert blog.title == "Test"
    assert blog.author == "Test Author"
    assert blog.posts == []
Esempio n. 6
0
def blog_posts(blog_id):
    blog = Blog.from_mongo(blog_id)
    posts = blog.get_posts()
    return render_template('posts.html',
                           posts=posts,
                           blog_title=blog.title,
                           blog_id=blog._id)
Esempio n. 7
0
def test_repr_multiple_posts():
    """Test the __repr__ function with multiple posts."""
    blog = Blog("Test", "Test Author")
    blog.posts = ["test"]
    blog2 = Blog("My Day", "Fabio")
    blog2.posts = ["test", "another"]

    assert blog.__repr__() == "Test by Test Author (1 post)"
    assert blog2.__repr__() == "My Day by Fabio (2 posts)"
Esempio n. 8
0
def test_repr():
    """Test the __repr__ function."""
    blog = Blog("Test", "Test Author")
    blog2 = Blog("My Day", "Fabio")

    assert blog.__repr__() == "Test by Test Author (0 posts)"
    assert blog2.__repr__() == "My Day by Fabio (0 posts)"
Esempio n. 9
0
def ask_create_blog():
    """Ask to the user the blog title and the author."""
    title = input("Insert the blog title: ")
    author = input("Insert your name: ")

    blogs[title] = Blog(title, author)
Esempio n. 10
0
 def new_post(blog_id, title, content, date=datetime.datetime.utcnow()):
     blog = Blog.from_mongo(blog_id)
     blog.new_post(title=title, content=content, date=date)
Esempio n. 11
0
 def get_blogs(self):
     return Blog.find_by_author_id(self._id)
Esempio n. 12
0
def setup_blog():
    """Initialize a blog for all tests."""
    blog = Blog("Test", "Test Author")
    src.app.blogs = {"Test": blog}
Esempio n. 13
0
def test_json_no_posts():
    """Tests the json representation without posts. """
    blog = Blog("Test", "Test Author")
    expected = {"title": "Test", "author": "Test Author", "posts": []}

    assert blog.json() == expected