How to use the pyramid.testing function in pyramid

To help you get started, we’ve selected a few pyramid examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github liqd / adhocracy3 / src / adhocracy_core / adhocracy_core / websockets / test_schemas.py View on Github external
def setUp(self):
        child = testing.DummyResource()
        self.child = child
        context = testing.DummyResource()
        context['child'] = child
        self.context = context
        request = testing.DummyRequest()
        request.root = context
        self.request = request
github liqd / adhocracy3 / src / adhocracy / adhocracy / subscriber / test_init.py View on Github external
def _create_new_version_event_with_isheet(context, isheet, registry, creator=None):
    return testing.DummyResource(__provides__=
                                 ISheetReferencedItemHasNewVersion,
                                 object=context,
                                 isheet=isheet,
                                 isheet_field='elements',
                                 old_version=testing.DummyResource(),
                                 new_version=testing.DummyResource(),
                                 registry=registry,
                                 creator=creator,
                                 root_versions=[])
github GoogleCloudPlatform / google-cloud-python-expenses-demo / gcloud_expenses / test_views.py View on Github external
def setUp(self):
        from pyramid import testing
        self.config = testing.setUp()
github Pylons / substanced / substanced / dump / tests.py View on Github external
def test_dump_with_subresources_resource_is_folder(self):
        from zope.interface import directlyProvides
        from substanced.interfaces import IFolder
        inst = self._makeOne()
        resource = testing.DummyResource()
        directlyProvides(resource, IFolder)
        resource['a'] = testing.DummyResource()
        context = DummyResourceDumpContext()
        inst._make_dump_context = lambda *arg, **kw: context
        inst.dump(resource, 'directory', subresources=True)
        self.assertEqual(context.dumped, resource['a'])
github liqd / adhocracy3 / src / adhocracy_core / adhocracy_core / resources / test_principal.py View on Github external
def test_get_groupids_user_exists(self, context, mock_sheet, request_, inst):
        from adhocracy_core.sheets.principal import IPermissions
        from adhocracy_core.testing import register_sheet
        group = testing.DummyResource(__name__='group1')
        mock_sheet.meta = mock_sheet.meta._replace(isheet=IPermissions)
        mock_sheet.get.return_value = {'groups': [group]}
        user = testing.DummyResource()
        register_sheet(user, mock_sheet, request_.registry)
        context['principals']['users']['User1'] = user
        assert inst.get_groupids('/principals/users/User1') == ['group:group1']
github Pylons / substanced / substanced / db / tests.py View on Github external
def setUp(self):
        self.config = testing.setUp()
github Pylons / pyramid_debugtoolbar / tests / test_views.py View on Github external
def _makeRequest(self):
        from pyramid_debugtoolbar.utils import ToolbarStorage
        request = testing.DummyRequest()
        request.matchdict['request_id'] = 'reqid'
        request.matchdict['frame_id'] = '0'

        toolbar = DummyToolbar()
        toolbar.traceback = self._makeTraceback('tbid')

        history = ToolbarStorage(10)
        history.put('reqid', toolbar)
        request.pdtb_history = history
        return request
github liqd / adhocracy3 / src / adhocracy_core / adhocracy_core / testing.py View on Github external
""" Return basic resource metadata."""
    from adhocracy_core.interfaces import resource_metadata
    from adhocracy_core.interfaces import IResource
    return resource_metadata._replace(iresource=IResource)


@fixture
def sheet_meta() -> SheetMetadata:
    """ Return basic sheet metadata."""
    from adhocracy_core.interfaces import sheet_metadata
    from adhocracy_core.interfaces import ISheet
    return sheet_metadata._replace(isheet=ISheet,
                                   schema_class=colander.MappingSchema)


class CorniceDummyRequest(testing.DummyRequest):

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.validated = {}
        self.errors = Errors(self)
        self.content_type = 'application/json'
        deserializer = {'application/json': extract_json_data}
        self.registry.cornice_deserializers = deserializer

    def authenticated_userid(self):
        return None

    @property
    def json_body(self):
        return json.loads(self.body)