Source

moin-2.0 / MoinMoin / storage / middleware / _tests / test_validation.py

# Copyright: 2011,2012 MoinMoin:ThomasWaldmann
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.

"""
MoinMoin - validation tests
"""


from __future__ import absolute_import, division

from MoinMoin.storage.middleware.validation import ContentMetaSchema, UserMetaSchema

from MoinMoin.constants import keys
from MoinMoin.constants.contenttypes import CONTENTTYPE_USER

from MoinMoin.util.crypto import make_uuid


class TestValidation(object):
    def test_content(self):
        class REV(dict):
            """ fake rev """

        rev = REV()
        rev[keys.ITEMID] = make_uuid()
        rev[keys.REVID] = make_uuid()
        rev[keys.ACL] = u"All:read"

        meta = {
            keys.REVID: make_uuid(),
            keys.PARENTID: make_uuid(),
            keys.NAME: [u"a", ],
            keys.NAMESPACE: u"",
            keys.ACL: u"All:read",
            keys.TAGS: [u"foo", u"bar"],
        }

        state = {'trusted': False, # True for loading a serialized representation or other trusted sources
                 keys.NAME: u'somename', # name we decoded from URL path
                 keys.ACTION: u'SAVE',
                 keys.HOSTNAME: u'localhost',
                 keys.ADDRESS: u'127.0.0.1',
                 keys.USERID: make_uuid(),
                 keys.HASH_ALGORITHM: u'b9064b9a5efd8c6cef2d38a8169a0e1cbfdb41ba',
                 keys.SIZE: 0,
                 keys.WIKINAME: u'ThisWiki',
                 keys.NAMESPACE: u'',
                 'rev_parent': rev,
                 'acl_parent': u"All:read",
                 'contenttype_current': u'text/x.moin.wiki;charset=utf-8',
                 'contenttype_guessed': u'text/plain;charset=utf-8',
                }

        m = ContentMetaSchema(meta)
        valid = m.validate(state)
        assert m[keys.CONTENTTYPE].value == u'text/x.moin.wiki;charset=utf-8'
        if not valid:
            for e in m.children:
                print e.valid, e
            print m.valid, m
        assert valid

    def test_user(self):
        meta = {
            keys.ITEMID: make_uuid(),
            keys.REVID: make_uuid(),
            keys.NAME: [u"user name", ],
            keys.NAMESPACE: u"userprofiles",
            keys.EMAIL: u"foo@example.org",
        }

        state = {'trusted': False, # True for loading a serialized representation or other trusted sources
                 keys.NAME: u'somename', # name we decoded from URL path
                 keys.ACTION: u'SAVE',
                 keys.HOSTNAME: u'localhost',
                 keys.ADDRESS: u'127.0.0.1',
                 keys.WIKINAME: u'ThisWiki',
                 keys.NAMESPACE: u'',
                }

        m = UserMetaSchema(meta)
        valid = m.validate(state)
        assert m[keys.CONTENTTYPE].value == CONTENTTYPE_USER
        if not valid:
            for e in m.children:
                print e.valid, e
            print m.valid, m
        assert valid
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.