def test_handle_feed_unwraps_t_umblr_com_links(self): item = { 'permalinkUrl': 'A', 'id': 'A', 'content': 'x <a href="http://t.umblr.com/redirect?z=http%3A%2F%2Fwrap%2Fped&t=YmZkMzQy..."></a> y', } superfeedr.handle_feed(json.dumps({'items': [item]}), self.source) posts = list(BlogPost.query()) self.assert_blogposts([BlogPost(id='A', source=self.source.key, feed_item=item, unsent=['http://wrap/ped'])])
def create_post(): new_post = BlogPost( title=request.form['title'], content=request.form['content'], author=request.form['author'], created=datetime.now(), ) db.session.add(new_post) db.session.commit() return redirect('posts')
def test_handle_feed_allows_bridgy_publish_links(self): item = { 'permalinkUrl': 'A', 'content': 'a https://brid.gy/publish/twitter b' } self.expect_task('propagate-blogpost', key=BlogPost(id='A')) self.mox.ReplayAll() superfeedr.handle_feed(json_dumps({'items': [item]}), self.source) self.assert_equals(['https://brid.gy/publish/twitter'], BlogPost.get_by_id('A').unsent)
def test_handle_feed(self): item_a = {'permalinkUrl': 'A', 'content': 'a http://a.com http://foo.com/self/link b'} post_a = BlogPost(id='A', source=self.source.key, feed_item=item_a, # self link should be discarded unsent=['http://a.com/']) self.expect_task('propagate-blogpost', key=post_a) self.mox.ReplayAll() superfeedr.handle_feed({'items': [item_a]}, self.source) self.assert_blogposts([post_a])
def test_notify_link_too_long(self): too_long = 'http://a/' + 'b' * _MAX_STRING_LENGTH item = {'id': 'X', 'content': f'a http://x/y {too_long} z'} post = BlogPost(id='X', source=self.source.key, feed_item=item, unsent=['http://x/y'], status='new') self.expect_task('propagate-blogpost', key=post) self.mox.ReplayAll() resp = self.client.post('/notify/foo.com', json={'items': [item]}) self.assertEqual(200, resp.status_code) self.assert_blogposts([post])
def create_post(): if request.method == 'POST': post.title = request.form['title'] post.author = request.form['author'] post.content = request.form['content'] new_post = BlogPost(title=post_title, content=post_content, author=post_author) db.session.add(new_post) db.session.commit() return redirect('/posts') else: return render_template('create.html')
def test_handle_feed(self): item_a = { 'permalinkUrl': 'A', 'content': 'a http://a.com http://foo.com/self/link b' } superfeedr.handle_feed(json.dumps({'items': [item_a]}), self.source) self.assert_blogposts([ BlogPost(id='A', source=self.source.key, feed_item=item_a, unsent=['http://a.com/']) ]) # self link should be discarded
def test_notify_handler(self): class Handler(superfeedr.NotifyHandler): SOURCE_CLS = testutil.FakeSource app = webapp2.WSGIApplication([('/notify/(.+)', Handler)], debug=True) item = {'id': 'X', 'content': 'a http://x/y z'} self.feed = json.dumps({'items': [item]}) resp = app.get_response('/notify/foo.com', method='POST', body=self.feed) self.assertEquals(200, resp.status_int) self.assert_blogposts([BlogPost(id='X', source=self.source.key, feed_item=item, unsent=['http://x/y'])])
def test_handle_feed_truncates_links(self): self.mox.stubs.Set(superfeedr, 'MAX_BLOGPOST_LINKS', 2) item_a = {'permalinkUrl': 'A', 'content': 'a http://a http://b http://c z'} post_a = BlogPost(id='A', source=self.source.key, feed_item=item_a, unsent=['http://a/', 'http://b/']) self.expect_task('propagate-blogpost', key=post_a) self.mox.ReplayAll() superfeedr.handle_feed({'items': [item_a]}, self.source) self.assert_blogposts([post_a])
def create_blogpost(db: Session, blogpost: schemas.BlogPostCreate, user_id: int): db_blogpost = BlogPost( title=blogpost.title, body=blogpost.body, date=blogpost.date, user_id=user_id, ) db.add(db_blogpost) db.commit() db.refresh(db_blogpost) return db_blogpost
def test_handle_feed_cleans_links(self): item = { 'permalinkUrl': 'A', 'id': 'A', 'content': 'x <a href="http://abc?source=rss----12b80d28f892---4', } superfeedr.handle_feed(json.dumps({'items': [item]}), self.source) self.assert_blogposts([ BlogPost(id='A', source=self.source.key, feed_item=item, unsent=['http://abc/']) ])
def test_subscribe(self): expected = { 'hub.mode': 'subscribe', 'hub.topic': 'fake feed url', 'hub.callback': 'http://localhost/fake/notify/foo.com', 'format': 'json', 'retrieve': 'true', } item_a = {'permalinkUrl': 'A', 'content': 'a http://a.com a'} item_b = {'permalinkUrl': 'B', 'summary': 'b http://b.com b'} feed = json.dumps({'items': [item_a, {}, item_b]}) self.expect_requests_post(superfeedr.PUSH_API_URL, feed, data=expected, auth=mox.IgnoreArg()) self.mox.ReplayAll() superfeedr.subscribe(self.source, self.handler) self.assert_blogposts( [BlogPost(id='A', source=self.source.key, feed_item=item_a, unsent=['http://a.com']), BlogPost(id='B', source=self.source.key, feed_item=item_b, unsent=['http://b.com']), ])
def test_handle_feed_cleans_links(self): item = { 'permalinkUrl': 'A', 'id': 'A', 'content': 'x <a href="http://abc?source=rss----12b80d28f892---4', } post = BlogPost(id='A', source=self.source.key, feed_item=item, unsent=['http://abc/']) self.expect_task('propagate-blogpost', key=post) self.mox.ReplayAll() superfeedr.handle_feed({'items': [item]}, self.source) self.assert_blogposts([post])
def test_handle_feed_unwraps_t_umblr_com_links(self): item = { 'permalinkUrl': 'A', 'id': 'A', 'content': 'x <a href="http://t.umblr.com/redirect?z=http%3A%2F%2Fwrap%2Fped&t=YmZkMzQy..."></a> y', } post = BlogPost(id='A', source=self.source.key, feed_item=item, unsent=['http://wrap/ped']) self.expect_task('propagate-blogpost', key=post) self.mox.ReplayAll() superfeedr.handle_feed({'items': [item]}, self.source) self.assert_blogposts([post])
def test_notify_handler(self): item = {'id': 'X', 'content': 'a http://x/y z'} self.feed = json.dumps({'items': [item]}) resp = fake_app.get_response('/notify/foo.com', method='POST', body=self.feed) self.assertEquals(200, resp.status_int) self.assert_blogposts([ BlogPost(id='X', source=self.source.key, feed_item=item, unsent=['http://x/y']) ])
def create_post(): form = BlogPostForm() if form.validate_on_submit(): blog_post = BlogPost( text=form.text.data, user_id=current_user.id) db.session.add(blog_post) db.session.commit() flash('Blog Post Created') return redirect(url_for('core.index')) return render_template('create_post.html', form=form)
def postview(_postid: str): ''' :param _postid: Post id in database :return: Render the post with given id to the user ''' dblogaction({'Log': str(request), 'ip': request.remote_addr, 'time': datetime.now()}) #Log to the database post = dbretrievepost(_postid) local_post = BlogPost(nomePost=post['nomePost'], conteudoPost=post['conteudoPost'], descPost=post['descPost'], categoriaPost=post['categoriaPost'], imagemPost=post['imagemPost'], dataPost=post['dataPost']) return render_template('postview.html', titulo=post['nomePost'], post=local_post)
def new_post(): if request.method == 'GET': return render_template('admin/blog-editor.html') elif request.method == 'POST': post_data = BlogPost(heading=request.form["heading"], url=request.form["heading"].lower().replace( " ", "-"), description=request.form["description"], content=request.form["content"], image=request.form["image"]) db.session.add(post_data) db.session.commit() return redirect(url_for("post", posturl=post_data.url))
def create(request): if request.POST: # title = request.POST.get("title") # timestamp = datetime.now() # body = request.POST.get("body") #BlogPost(title=title, timestamp=timestamp, body=body).save() form = BlogPostForm(request.POST) if form.is_valid(): BlogPost(title=form.cleaned_data["title"], timestamp=datetime.now(), body=form.cleaned_data["body"]).save() ctx = {} ctx.update(csrf(request)) postList = BlogPost.objects.all().order_by("-timestamp") ctx["posts"] = postList form = BlogPostForm() ctx["form"] = form return render_to_response("create.html", ctx)
def post(): if request.method == 'POST': post_title = request.form['title'] post_content = request.form['content'] post_author = request.form['author'] new_post = BlogPost(title=post_title, content=post_content, author=post_author) db.session.add(new_post) db.session.commit() return redirect('/posts') else: all_posts = BlogPost.query.order_by(BlogPost.date_posted).all() return render_template('posts.html', posts=all_posts)
def home(): error = None form = MessageForm(request.form) if form.validate_on_submit(): new_message = BlogPost( form.title.data, form.description.data, current_user.id ) db.session.add(new_message) db.session.commit() flash('New entry was successfully posted. Thanks.') return redirect(url_for('home')) else: posts = db.session.query(BlogPost).all() return render_template('hello.html', posts=posts, form=form, error=error)
def test_notify_handler(self): item = {'id': 'X', 'content': 'a http://x/y z'} post = BlogPost(id='X', source=self.source.key, feed_item=item, unsent=['http://x/y']) self.expect_task('propagate-blogpost', key=post) self.mox.ReplayAll() self.feed = json_dumps({'items': [item]}) resp = fake_app.get_response('/notify/foo.com', method='POST', text=self.feed) self.assertEqual(200, resp.status_int) self.assert_blogposts([post])
def index(): form = BlogPostForm() if form.validate_on_submit(): blog_post = BlogPost(text=form.text.data, user_id=current_user.id) db.session.add(blog_post) db.session.commit() flash('Blog Post Created') return redirect(url_for('core.index')) page = request.args.get('page', 1, type=int) blog_posts = BlogPost.query.order_by(BlogPost.date.desc()).paginate( page=page, per_page=3) return render_template('index.html', blog_posts=blog_posts, form=form)
def test_notify_utf8(self): """Check that we handle unicode chars in content ok, including logging.""" self.feed = '{"items": [{"id": "X", "content": "a ☕ z"}]}' resp = fake_app.get_response('/notify/foo.com', method='POST', text=self.feed) self.assertEqual(200, resp.status_int) self.assert_blogposts([ BlogPost(id='X', source=self.source.key, feed_item={ 'id': 'X', 'content': 'a ☕ z' }, status='complete') ])
def test_notify_link_too_long(self): too_long = 'http://a/' + 'b' * _MAX_STRING_LENGTH item = {'id': 'X', 'content': 'a http://x/y %s z' % too_long} self.feed = json.dumps({'items': [item]}) resp = fake_app.get_response('/notify/foo.com', method='POST', body=self.feed) self.assertEquals(200, resp.status_int) self.assert_blogposts([ BlogPost(id='X', source=self.source.key, feed_item=item, unsent=['http://x/y'], status='new') ], tasks=False)
def post(self): subject = self.request.get("subject") content = self.request.get("content") uid = self.get_user_id() if self.user: if subject and content: new_post = BlogPost(subject=subject, content=content, author=uid) new_post.put() new_id = new_post.key().id() self.redirect('/blog/' + str(new_id)) else: error = "Please enter a subject and blog content" self.render("newpost.html", error=error) else: self.redirect("/login")
def test_notify_url_too_long(self): item = { 'id': 'X' * (_MAX_KEYPART_BYTES + 1), 'content': 'a http://x/y z' } self.feed = json_dumps({'items': [item]}) resp = fake_app.get_response('/notify/foo.com', method='POST', text=self.feed) self.assertEqual(200, resp.status_int) self.assert_blogposts([ BlogPost(id='X' * _MAX_KEYPART_BYTES, source=self.source.key, feed_item=item, failed=['http://x/y'], status='complete') ])
def test_notify_link_too_long(self): too_long = 'http://a/' + 'b' * _MAX_STRING_LENGTH item = {'id': 'X', 'content': 'a http://x/y %s z' % too_long} post = BlogPost(id='X', source=self.source.key, feed_item=item, unsent=['http://x/y'], status='new') self.expect_task('propagate-blogpost', key=post) self.mox.ReplayAll() self.feed = json_dumps({'items': [item]}) resp = fake_app.get_response('/notify/foo.com', method='POST', text=self.feed) self.assertEqual(200, resp.status_int) self.assert_blogposts([post])
def post(self): params = {} subject = self.request.get("subject") blog_content = self.request.get("blog_content").replace('\n', '<br/>') params['subject'] = subject params['blog_content'] = blog_content if subject and blog_content: b = BlogPost(subject=subject, blog_content=blog_content, author=self.user.username, likes=0) b.put() self.redirect('/post/{0}'.format(b.key().id())) else: params['error'] = "subject and content, please!" self.render_new_post(**params)
def make_post(): loaded_message = request.get_json() body = loaded_message["body"] title = loaded_message["title"] the_time = datetime.datetime.now() fixed_time = the_time.strftime("%B %d, %Y") author = "*****@*****.**" insert_payload = BlogPost( time=fixed_time, body=body, title=title, author=author, ) insert_payload.put() return jsonify(success=True)