Exemplo n.º 1
0
    def test_linkfy_keyword(self, text=TEXT_UNICODE):
        query = WikiEntries().all()
        entities = query.fetch(query.count())
        keywords = list(set([entity.name for entity in entities]))

        for keyword in keywords:
            text = text.replace(keyword, u'<a href="/%s">%s</a>' % (transformer.quote(keyword), keyword))

        self.assertEqual(text, LINKFIED_TEXT_UNICODE)
Exemplo n.º 2
0
    def setUp(self):
        self.testbed = testbed.Testbed()

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

        entity = WikiEntries(name=u'テストページ')

        entity.put()
Exemplo n.º 3
0
def linkfy_keyword(text):
    query = WikiEntries().all()
    entities = query.fetch(query.count())
    keywords = list(set([entity.name for entity in entities]))

    for keyword in keywords:
        text = text.replace(keyword,
                            u'<a href="/%s">%s</a>' % (quote(keyword), keyword))

    return text
Exemplo n.º 4
0
    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 エントリーを書いて下さい。')
Exemplo n.º 5
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.º 6
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.º 7
0
    def __init__(self, name, entity=None):
        self.name = transformer.unquote(name)
        self.post_requests = {u'content': u'', u'format': u''}
        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 = template.unescape(self.wikify_content())
        else:
            self.existence = False
            self.entity = \
                WikiEntries(content=u'新しい wiki エントリーを書いて下さい。')
Exemplo n.º 8
0
class Page(object):
    """Abstraction for a wiki page

    This class handles all the wiki pages. First, you can call the page
    instance from `load` method with page name, or you can also check first if
    the page is existed or not from `hasentry` method with page name.
    """

    def __init__(self, name, entity=None):
        self.name = transformer.unquote(name)
        self.post_requests = {u'content': u'', u'format': u''}
        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 = template.unescape(self.wikify_content())
        else:
            self.existence = False
            self.entity = \
                WikiEntries(content=u'新しい wiki エントリーを書いて下さい。')

    @staticmethod
    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

    def exists(self):
        return self.existence

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

    def 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()

    def 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.º 9
0
def get_entries():
    query = WikiEntries.all()

    query.order('-modified')

    return query.fetch(query.count())
Exemplo n.º 10
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.º 11
0
    def test_get_entries(self):
        query = WikiEntries.all()

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