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
def new_blog(self, title, description): blog = Blog(author=self.email, title=title, description=description, author_id=self._id) blog.save_to_mongo()
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"
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))
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 == []
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)
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)"
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)"
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)
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)
def get_blogs(self): return Blog.find_by_author_id(self._id)
def setup_blog(): """Initialize a blog for all tests.""" blog = Blog("Test", "Test Author") src.app.blogs = {"Test": blog}
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