예제 #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)
예제 #3
0
 def get(self):
     '''
     Handles displaying a json for all blog entries
     '''
     self.response.headers['Content-Type'] = 'application/json'
     service = BlogService(BlogDataStoreFactory())
     blog_json = service.create_all_json()
     self.response.out.write(blog_json)
 def get(self):
     """
     Handles displaying a json for all blog entries
     """
     self.response.headers["Content-Type"] = "application/json"
     service = BlogService(BlogDataStoreFactory())
     blog_json = service.create_all_json()
     self.response.out.write(blog_json)
예제 #5
0
 def get(self):
     '''
     Handles initial get request
     '''
     self.response.headers['Content-Type'] = 'text/html'
     service = BlogService(BlogDataStoreFactory())
     blog_entries = service.fetchAll()
     values = {'blog_entries': blog_entries}
     path = os.path.join(os.path.dirname(__file__), 'blog.html')
     self.response.out.write(template.render(path, values))
 def get(self):
     """
     Handles initial get request
     """
     self.response.headers["Content-Type"] = "text/html"
     service = BlogService(BlogDataStoreFactory())
     blog_entries = service.fetchAll()
     values = {"blog_entries": blog_entries}
     path = os.path.join(os.path.dirname(__file__), "blog.html")
     self.response.out.write(template.render(path, values))
 def setUp(self):
     # First, create an instance of the Testbed class.
     self.testbed = testbed.Testbed()
     # Then activate the testbed, which prepares the service stubs for use.
     self.testbed.activate()
     # Next, declare which service stubs you want to use.
     self.testbed.init_datastore_v3_stub()
     self.factory = BlogDataStoreFactory()
     self.storage = self.factory.get_storage()
     self.service = BlogService(self.factory)
예제 #8
0
    def get(self, entry_id):
        '''
        Handles displaying a blog entry
        '''
        self.response.headers['Content-Type'] = 'text/html'
#        entry_id = self.request.get('entry_id')
        service = BlogService(BlogDataStoreFactory())
        data = service.fetch(int(entry_id))
        values = {'subject': data.subject, 'content':data.content}
        path = os.path.join(os.path.dirname(__file__), 'show_blog_entry.html')
        self.response.out.write(template.render(path, values))
 def get(self, entry_id):
     """
     Handles displaying a blog entry
     """
     self.response.headers["Content-Type"] = "text/html"
     #        entry_id = self.request.get('entry_id')
     service = BlogService(BlogDataStoreFactory())
     data = service.fetch(int(entry_id))
     values = {"subject": data.subject, "content": data.content}
     path = os.path.join(os.path.dirname(__file__), "show_blog_entry.html")
     self.response.out.write(template.render(path, values))
 def setUp(self):
     # First, create an instance of the Testbed class.
     self.testbed = testbed.Testbed()
     # Then activate the testbed, which prepares the service stubs for use.
     self.testbed.activate()
     # Next, declare which service stubs you want to use.
     self.testbed.init_datastore_v3_stub()
     self.factory = BlogDataStoreFactory()
     self.storage = self.factory.get_storage()
     self.service = BlogService(self.factory)
class Test(unittest.TestCase):


    def setUp(self):
        # First, create an instance of the Testbed class.
        self.testbed = testbed.Testbed()
        # Then activate the testbed, which prepares the service stubs for use.
        self.testbed.activate()
        # Next, declare which service stubs you want to use.
        self.testbed.init_datastore_v3_stub()
        self.factory = BlogDataStoreFactory()
        self.storage = self.factory.get_storage()
        self.service = BlogService(self.factory)



    def tearDown(self):
        self.testbed.deactivate()


    def test_create_json(self):
        subject = 'Test Subject'
        content = 'Test 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_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))
class Test(unittest.TestCase):
    def setUp(self):
        # First, create an instance of the Testbed class.
        self.testbed = testbed.Testbed()
        # Then activate the testbed, which prepares the service stubs for use.
        self.testbed.activate()
        # Next, declare which service stubs you want to use.
        self.testbed.init_datastore_v3_stub()
        self.factory = BlogDataStoreFactory()
        self.storage = self.factory.get_storage()
        self.service = BlogService(self.factory)

    def tearDown(self):
        self.testbed.deactivate()

    def test_create_json(self):
        subject = 'Test Subject'
        content = 'Test 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_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))