コード例 #1
0
    def test_Roles_member(self):
        from plone.app.caching.operations.etags import Roles

        class DummyMember(object):

            def getRolesInContext(self, context):
                return ['Member', 'Manager']

        class DummyPortalState(object):
            implements(Interface)
            adapts(DummyContext, Interface)

            def __init__(self, context, request):
                pass

            def anonymous(self):
                return False

            def member(self):
                return DummyMember()

        provideAdapter(DummyPortalState, name=u"plone_portal_state")

        environ = {'SERVER_NAME': 'example.com', 'SERVER_PORT': '80'}
        response = HTTPResponse()
        request = HTTPRequest(StringIO(), environ, response)
        published = DummyPublished(DummyContext())

        etag = Roles(published, request)

        self.assertEqual('Manager;Member', etag())
コード例 #2
0
    def test_Roles_anonymous(self):
        from plone.app.caching.operations.etags import Roles

        @implementer(Interface)
        @adapter(DummyContext, Interface)
        class DummyPortalState(object):
            def __init__(self, context, request):
                pass

            def anonymous(self):
                return True

            def member(self):
                return None

        provideAdapter(DummyPortalState, name=u'plone_portal_state')

        environ = {'SERVER_NAME': 'example.com', 'SERVER_PORT': '80'}
        response = HTTPResponse()
        request = HTTPRequest(StringIO(), environ, response)
        published = DummyPublished(DummyContext())

        etag = Roles(published, request)

        self.assertEqual('Anonymous', etag())