Exemplo n.º 1
0
    def load(name):
        normalized_name = transformer.normalize(name)
        query = WikiEntries.all()

        query.filter(u'name_normalized =', normalized_name).order(u'-modified')

        entity = query.get()

        if entity:
            page = Page(name, entity)
        else:
            page = Page(name)

        return page
Exemplo n.º 2
0
    def test_load(self, name=QUOTED_NAME_UNICODE):
        normalized_name = transformer.normalize(name)
        query = WikiEntries.all()

        query.filter(u'name_normalized =', normalized_name).order(u'-modified')

        entity = query.get()

        if entity:
            page_ = page.Page(name, entity)
        else:
            page_ = page.Page(name)

        self.assertIsInstance(page_, page.Page)
Exemplo n.º 3
0
def get_entries():
    query = WikiEntries.all()

    query.order('-modified')

    return query.fetch(query.count())
Exemplo n.º 4
0
class PageTestCase(unittest.TestCase):
    def setUp(self, name=QUOTED_NAME_UNICODE, entity=None):
        self.testbed = testbed.Testbed()

        self.testbed.activate()
        self.testbed.init_datastore_v3_stub()

        # __init__ processes

        self.name = transformer.unquote(name)
        self.post_requests = {u'content': u'',
                              u'format': u'markdown-extra'}
        self.path = {u'view': '/' + transformer.quote(self.name),
                     u'edit': '/' + transformer.quote(self.name) + '?mode=edit',
                     u'remove':
                '/' + transformer.quote(self.name) + '?mode=edit&action=remove',
                     u'newpage':
                  '/' + transformer.quote(u'新しいページ') + '?mode=edit'}

        if entity:
            self.existence = True
            self.entity = entity
            self.name = self.entity.name
            self.content = self.wikify_content()
        else:
            self.existence = False
            self.entity = \
                WikiEntries(content=u'新しい wiki エントリーを書いて下さい。')

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

    def test_load(self, name=QUOTED_NAME_UNICODE):
        normalized_name = transformer.normalize(name)
        query = WikiEntries.all()

        query.filter(u'name_normalized =', normalized_name).order(u'-modified')

        entity = query.get()

        if entity:
            page_ = page.Page(name, entity)
        else:
            page_ = page.Page(name)

        self.assertIsInstance(page_, page.Page)

    def test_exists(self):
        self.assertIsInstance(self.existence, bool)

    def test_remove(self):
        try:
            self.entity.delete()
        except NotSavedError:
            logging.warn(u'Non existed entry is requested to remove.')
        # Not tested yet

    def test_save(self):
        now = datetime.datetime.now()

        if not self.entity.created:
            self.entity.created = now

        self.entity.content = self.post_requests[u'content']
        self.entity.format = self.post_requests[u'format']
        self.entity.modified = now
        self.entity.name = self.name
        self.entity.name_normalized = transformer.normalize(self.name)

        self.entity.put()
        self.assertEqual(1, len(self.entity.all().fetch(10)))

    def test_wikify_content(self):
        transforms = [transformer.AutoLink()]
        content = self.entity.content

        for transform in transforms:
            content = transform.run(content)

        return transformer.markdownize(transformer.linkfy_keyword(content))
Exemplo n.º 5
0
    def test_get_entries(self):
        query = WikiEntries.all()

        query.order('-modified')
        query.fetch(query.count())