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 = WikiDataStoreFactory()
     self.storage = self.factory.get_storage()
     self.service = WikiService(self.factory)
Esempio n. 2
0
 def get(self, entry_id):
     '''
     Handles displaying a wiki entry
     '''
     logging.info("Running ShowWikiEntry.get()")
     logging.info("Request path: %s" % str(self.request.path))
     self.response.headers['Content-Type'] = 'text/html'
     check_cookie(self)
     wiki_id = self.request.get('wiki_id')
     data = None
     service = WikiService(WikiDataStoreFactory())
     if wiki_id:
         data = service.fetch(int(wiki_id))
     else:
         url = WebappUtils.getLastPathElement(self.request)
         if not url:
             url = 'WikiFrontPage'
         logging.info('url: %s' % str(url))
         data = service.fetchCurrentUrl(url)
     if data:
         logging.info('Getting WikiData: %s' % str_WikiData(data))
     else:
         logging.info('No data found')
     values = {'wiki': data}
     if not data:
         redirect = '/final/_edit/%s' % url
         logging.info(
             "Data not found for wiki. Redirecting to edit page: %s" %
             redirect)
         self.redirect(redirect)
     else:
         path = os.path.join(os.path.dirname(__file__),
                             '../templates/show_wiki_entry.html')
         self.response.out.write(template.render(path, values))
Esempio n. 3
0
 def get(self, entry_id):
     '''
     For showing wiki history
     '''
     logging.info("Running ShowWikiHistory.get()")
     self.response.headers['Content-Type'] = 'text/html'
     check_cookie(self)
     url = WebappUtils.getLastPathElement(self.request)
     service = WikiService(WikiDataStoreFactory())
     data = service.fetchHistory(url)
     values = {'wiki_entries': data, "url": url}
     path = os.path.join(os.path.dirname(__file__),
                         '../templates/history.html')
     self.response.out.write(template.render(path, values))
Esempio n. 4
0
 def get(self):
     '''
     Handles initial get request
     '''
     self.response.headers['Content-Type'] = 'text/html'
     check_cookie(self)
     service = WikiService(WikiDataStoreFactory())
     wiki_entries, last_queried = service.fetchAll()
     current = time.time()
     last_queried_all = current - last_queried
     values = {
         'wiki_entries': wiki_entries,
         "last_queried_all": last_queried_all
     }
     path = os.path.join(os.path.dirname(__file__),
                         '../templates/wiki.html')
     self.response.out.write(template.render(path, values))
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 = WikiDataStoreFactory()
        self.storage = self.factory.get_storage()
        self.service = WikiService(self.factory)



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


    def test_create_json(self):
        url = 'Test Subject'
        content = 'Test Content'
        wiki = WikiData(url=url,content=content)
        wiki.put()
        wiki_id = wiki.key().id()
#        wiki_data = self.service.fetch(wiki_id)
        json_string = self.service.create_json(wiki_id)
        self.assertTrue(('"url": "%s"' % url) 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):
        url = 'Test"s Subject'
        content = 'Test"s Content'
        wiki = WikiData(url=url,content=content)
        wiki.put()
        wiki_id = wiki.key().id()
#        wiki_data = self.service.fetch(wiki_id)
        json_string = self.service.create_json(wiki_id)
        quote = url.find('"')
        json_url = url[0:quote] + '\\' + url[quote:]
        quote = content.find('"')
        json_content = content[0:quote] + '\\' + content[quote:]
        self.assertTrue(('"url": "%s"' % json_url) in json_string, "Actual json string: " + str(json_string))
        self.assertTrue(('"content": "%s"' % json_content) in json_string, "Actual json string: " + str(json_string))
Esempio n. 6
0
 def post(self, param=None):
     '''
     Handles wiki entry creation
     '''
     logging.info("Running EditWikiEntry.post()")
     logging.info('Parameter=%s' % param)
     self.response.headers['Content-Type'] = 'text/html'
     check_cookie(self)
     isValid = True
     values = {}
     #        url = self.request.get('url')
     url = WebappUtils.getLastPathElement(self.request)
     if not url:
         url = param[1:]
     if not url:
         values['url_error'] = 'Wiki url is required'
         isValid = False
     else:
         logging.info("Creating wiki entry with url: %s" % str(url))
     content = self.request.get('content')
     if not content:
         values['content_error'] = 'Wiki content is required'
         isValid = False
     else:
         logging.info("Creating wiki entry with content: %s" % str(content))
     path = None
     if not isValid:
         values['url'] = url
         values['content'] = content
         path = os.path.join(os.path.dirname(__file__),
                             '../templates/edit_wiki_entry.html')
         self.response.out.write(template.render(path, values))
     else:
         wiki = WikiData(url=url, content=content)
         service = WikiService(WikiDataStoreFactory())
         logging.info("Saving WikiData: %s" % str_WikiData(wiki))
         service.save(wiki)
         logging.info(
             "Successfully posted wiki entry. Redirecting to '/final/%s" %
             url)
         self.redirect('/final/%s' % url)
Esempio n. 7
0
 def get(self, foo=None):
     '''
     Handles request for the create page
     '''
     logging.info("Running EditWikiEntry.get()")
     self.response.headers['Content-Type'] = 'text/html'
     check_cookie(self)
     wiki_id = self.request.get('wiki_id')
     data = None
     service = WikiService(WikiDataStoreFactory())
     url = ''
     if wiki_id:
         data = service.fetch(wiki_id)
     else:
         url = WebappUtils.getLastPathElement(self.request)
         data = service.fetchCurrentUrl(url)
     logging.info('Data: %s' % (str(data)))
     values = {'url': url, 'content': ''}
     if data:
         values = {'url': data.url, 'content': data.content}
     path = os.path.join(os.path.dirname(__file__),
                         '../templates/edit_wiki_entry.html')
     self.response.out.write(template.render(path, values))