def create_post(self, title, body, author, cdate=None): from ghostwriter.Post import Post, PostManager po = Post(author.uid, title, cdate) po.setContent(body) return po
def test_delete_blog_post(self): self.authenticate() from ghostwriter.Post import Post, PostManager from flask import json p = Post(1, 'Get Content Test') p.setContent('Post content') pm = PostManager() pm.addPost(p) res = self.app.delete('/api/post/' + str(p.ID) + '/', follow_redirects=True) self.assertEqual(res.status, '200 OK') res = self.app.delete('/api/post/' + str(p.ID) + '/', follow_redirects=True) self.assertEqual(res.status, '404 NOT FOUND')
def test_get_content(self): self.authenticate() from ghostwriter.Post import Post, PostManager from flask import json p = Post(1, 'Get Content Test') p.setContent('Post content') pm = PostManager() pm.addPost(p) res = self.app.get('/api/post/' + str(p.ID) + '/content', follow_redirects=True) self.assertEqual(res.status, '200 OK') post_data = res.data self.assertEqual(b'Post content', post_data) self.deauthenticate()
def post_create(): """ Creates post Returns post metadata, with ID """ from ghostwriter.Post import Post, PostManager pm = PostManager() post = Post(current_user.uid, request.form['title']) pm.addPost(post) jdata = { 'id': post.ID, 'title': post.title, 'creation_date': post.creation_date.isoformat(), 'summary': post.getSummary(), 'owner': { 'id': post.getOwner().uid, 'name': post.getOwner().name } } return jsonify(jdata), 200
def test_set_and_get_metadata(self): self.authenticate() from ghostwriter.Post import Post, PostManager from flask import json p = Post(1, 'Get Meta Test') p.setContent('Post content') pm = PostManager() pm.addPost(p) res = self.app.put('/api/post/' + str(p.ID) + '/', data={'title': 'New Meta Test'}, follow_redirects=True) self.assertEqual(res.status, '200 OK') res = self.app.get('/api/post/' + str(p.ID) + '/', follow_redirects=True) self.assertEqual(res.status, '200 OK') post_data = json.loads(res.data) self.assertEqual('New Meta Test', post_data['title']) self.deauthenticate()