def post(self): ''' Handles blog entry creation ''' self.response.headers['Content-Type'] = 'text/html' isValid = True values = {} subject = self.request.get('subject') if not subject: values['subject_error'] = 'Blog subject is required' isValid = False else: logging.info("Creating blog entry with subject: %s" % str(subject)) content = self.request.get('content') if not content: values['content_error'] = 'Blog content is required' isValid = False else: logging.info("Creating blog entry with content: %s" % str(content)) path = None if not isValid: values['subject'] = subject values['content'] = content path = os.path.join(os.path.dirname(__file__), 'create_blog_entry.html') self.response.out.write(template.render(path, values)) else: blog = BlogData(subject=subject, content=content) service = BlogService(BlogDataStoreFactory()) service.save(blog) blog_id = blog.key().id() str_blog_id = str(blog_id) logging.info("Successfully posted blog entry. Redirectinr to '/unit5/%s" % str_blog_id ) self.redirect('/unit5/%s' % str_blog_id)
def post(self): """ Handles blog entry creation """ self.response.headers["Content-Type"] = "text/html" isValid = True values = {} subject = self.request.get("subject") if not subject: values["subject_error"] = "Blog subject is required" isValid = False else: logging.info("Creating blog entry with subject: %s" % str(subject)) content = self.request.get("content") if not content: values["content_error"] = "Blog content is required" isValid = False else: logging.info("Creating blog entry with content: %s" % str(content)) path = None if not isValid: values["subject"] = subject values["content"] = content path = os.path.join(os.path.dirname(__file__), "create_blog_entry.html") self.response.out.write(template.render(path, values)) else: blog = BlogData(subject=subject, content=content) service = BlogService(BlogDataStoreFactory()) service.save(blog) blog_id = blog.key().id() str_blog_id = str(blog_id) logging.info("Successfully posted blog entry. Redirectinr to '/unit5/%s" % str_blog_id) self.redirect("/unit5/%s" % str_blog_id)
def test_BlogToJson_with_double_quote(self): blog = BlogData(subject="Test1", content='Test1 blog"s content') self.storage.save(blog) blog_id = blog.key().id() stored_blog = self.storage.fetch(blog_id) actual = JsonUtils.blog_to_json(stored_blog); self.assertTrue('"subject": "Test1"' in actual,"Blog subject not parsed correctly in blog data: " + repr(actual)) self.assertTrue('"content": "Test1 blog\\"s content"' in actual,"Blog content not parsed correctly in blog data: " + repr(actual))
def test_create_json_with_double_quotes(self): subject = 'Test"s Subject' content = 'Test"s Content' blog = BlogData(subject=subject,content=content) blog.put() blog_id = blog.key().id() # blog_data = self.service.fetch(blog_id) json_string = self.service.create_json(blog_id) self.assertTrue(('"subject": "%s"' % subject) in json_string, "Actual json string: " + str(json_string)) self.assertTrue(('"content": "%s"' % content) in json_string, "Actual json string: " + str(json_string))
def test_BlogToJson_with_double_quote(self): blog = BlogData(subject="Test1", content='Test1 blog"s content') self.storage.save(blog) blog_id = blog.key().id() stored_blog = self.storage.fetch(blog_id) actual = JsonUtils.blog_to_json(stored_blog) self.assertTrue( '"subject": "Test1"' in actual, "Blog subject not parsed correctly in blog data: " + repr(actual)) self.assertTrue( '"content": "Test1 blog\\"s content"' in actual, "Blog content not parsed correctly in blog data: " + repr(actual))
def test_create_json_with_double_quotes(self): subject = 'Test"s Subject' content = 'Test"s Content' blog = BlogData(subject=subject, content=content) blog.put() blog_id = blog.key().id() # blog_data = self.service.fetch(blog_id) json_string = self.service.create_json(blog_id) self.assertTrue(('"subject": "%s"' % subject) in json_string, "Actual json string: " + str(json_string)) self.assertTrue(('"content": "%s"' % content) in json_string, "Actual json string: " + str(json_string))