Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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=[])
def tearDown(self):
testing.tearDown()
def setUp(self):
from pyramid import testing
self.config = testing.setUp()
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'])
def tearDown(self):
testing.tearDown()
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']
def setUp(self):
self.config = testing.setUp()
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
""" 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)