Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_load(self):
context = testing.DummyResource()
resource = testing.DummyResource()
context.exists = lambda *arg: True
def _p_activate():
pass # this will not be covered if not run
context.resource = resource
resource._p_activate = _p_activate
def load_yaml(fn):
self.assertEqual(fn, 'name.yaml')
return {'a':1}
context.load_yaml = load_yaml
inst = self._makeOne('name', None)
inst.load(context)
self.assertTrue(resource._p_changed)
self.assertEqual(resource.a, 1)
def test_deserialize_value_url_valid_path(self, context, request_, node, rest_url):
inst = self.make_one()
context['child'] = testing.DummyResource()
node = node.bind(request=request_,
context=context)
result = inst.deserialize(node, rest_url + '/child')
assert result == context['child']
def setUp(self):
self.context = testing.DummyResource()
self.target = testing.DummyResource()
self.child = testing.DummyResource()
request = testing.DummyRequest()
request.root = self.context
self.request = request
def test_one_found(self):
from ..interfaces import IFolder
from ..interfaces import IService
site = testing.DummyResource(__provides__=IFolder)
catalog = testing.DummyResource(__provides__=IService)
site['catalog'] = catalog
self.assertEqual(self._callFUT(site, 'catalog'), [catalog])
def test_call_function(self):
decorator = self._makeOne()
venusian = DummyVenusian()
decorator.venusian = venusian
def foo(): pass
wrapped = decorator(foo)
self.assertTrue(wrapped is foo)
context = testing.DummyResource()
context.config = DummyConfigurator()
venusian.callback(context, None, 'abc')
self.assertEqual(context.config.view, 'abc')
def call_fut(self, descendant, ancestors):
from adhocracy_core.graph import Graph
context = testing.DummyResource(__objectmap__=self.context.__objectmap)
graph = Graph(context)
return Graph.is_in_subtree(graph, descendant, ancestors)
def _makeTree(self):
from substanced.interfaces import IFolder
from substanced.interfaces import IService
root = testing.DummyResource(__provides__=IFolder)
catalogs1 = root['catalogs'] = testing.DummyResource(
__provides__=IService)
catalog1 = testing.DummyResource()
catalogs1['catalog1'] = catalog1
sub = testing.DummyResource(__provides__=IFolder)
root['sub'] = sub
catalogs2 = sub['catalogs'] = testing.DummyResource(
__provides__=IService)
catalog2 = testing.DummyResource()
catalog1_2 = testing.DummyResource()
sub['catalogs'] = catalogs2
catalogs2['catalog2'] = catalog2
catalogs2['catalog1'] = catalog1_2
return root
def test_valid(self, request, context):
user = testing.DummyResource(active=True)
request.validated['user'] = user
self._call_fut(context, request)
assert not request.errors
def test_index():
"""Get the API descriptor"""
result = api.index(DummyResource(), DummyRequest())
# Pyramid's host url defaults to http://example.com
host = 'http://example.com'
links = result['links']
assert links['annotation']['create']['method'] == 'POST'
assert links['annotation']['create']['url'] == host + '/annotations'
assert links['annotation']['delete']['method'] == 'DELETE'
assert links['annotation']['delete']['url'] == host + '/annotations/:id'
assert links['annotation']['read']['method'] == 'GET'
assert links['annotation']['read']['url'] == host + '/annotations/:id'
assert links['annotation']['update']['method'] == 'PUT'
assert links['annotation']['update']['url'] == host + '/annotations/:id'
assert links['search']['method'] == 'GET'
assert links['search']['url'] == host + '/search'
def test_it_with_registration(self):
from zope.interface import Interface
from . import IEditable
request = testing.DummyRequest()
context = testing.DummyResource()
class adapter(object):
def __init__(self, context, request):
pass
request.registry.registerAdapter(adapter, (Interface, Interface),
IEditable)
result = self._callFUT(context, request)
self.assertEqual(result.__class__, adapter)