Exemplo n.º 1
0
 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))
Exemplo n.º 4
0
 def test_BlogListToJson(self):
     blog1 = BlogData(subject="Test1", content='Test1 blog content')
     self.storage.save(blog1)
     blog2 = BlogData(subject="Test2", content='Test2 blog content')
     self.storage.save(blog2)
     blog_list = self.storage.fetchAll()
     actual = JsonUtils.blog_list_to_json(blog_list)
     print actual
     print str(len(actual))
     self.assertFalse(len(actual) == 0)
    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_fetchAll(self):
     b1 = BlogData(subject='blog1', content='This is blog1')
     self.storage.save(b1)
     b2 = BlogData(subject='blog2', content='This is blog2')
     self.storage.save(b2)
     expected = 2
     actual = list(self.storage.fetchAll())
     actual_count = len(actual)
     self.assertEquals(
         expected, actual_count, "Blog count of " + str(expected) +
         ' size was not found. Actual count: ' + str(actual_count))
     print repr(actual)
Exemplo n.º 7
0
 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_fetch(self):
     b = BlogData(subject='blog1', content='This is blog1')
     expected = b.subject
     self.storage.save(b)
     b1 = self.storage.fetch(1)
     self.assertEquals(expected, b1.subject,
                       "Blog with id " + str(expected) + ' was not found.')
     pass
Exemplo n.º 10
0
    def fetch(self, entry_id):
#        blog_entry = None
#        sql = "select * from BlogData where entry_id=" + entry_id
        blog_entry = BlogData.get_by_id(entry_id)
#        blog_entries = db.GqlQuery(sql)
#        for entry in blog_entries:
#            blog_entry = entry

        return blog_entry
 def test_save(self):
     b3 = BlogData(subject='blog1', content='This is blog1')
     self.storage.save(b3)
     b3a = self.storage.fetch(1)
     self.assertEquals(
         b3.subject, b3a.subject, "Blog " + str(b3) +
         ' was not saved. This was saved instead: ' + str(b3a))
     self.assertEquals(
         b3.content, b3a.content, "Blog " + str(b3) +
         ' was not saved. This was saved instead: ' + str(b3a))
     pass
 def testPut(self):
     data = BlogData(subject='Foo', content='Foo blog')
     data.put()
     pass
 def testPut(self):
     data = BlogData(subject='Foo',content='Foo blog')
     data.put()
     pass