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_collection_library_registrations_post(self):
"""Test what might happen POSTing to collection_library_registrations."""
# First test the failure cases.
m = self.manager.admin_collection_library_registrations_controller.process_collection_library_registrations
# Here, the user doesn't have permission to start the
# registration process.
self.admin.remove_role(AdminRole.SYSTEM_ADMIN)
with self.request_context_with_admin("/", method="POST"):
assert_raises(AdminNotAuthorized, m)
self.admin.add_role(AdminRole.SYSTEM_ADMIN)
# The collection ID doesn't correspond to any real collection.
with self.request_context_with_admin("/", method="POST"):
flask.request.form = MultiDict([("collection_id", "1234")])
response = m()
eq_(MISSING_COLLECTION, response)
# Pass in a collection ID so that doesn't happen again.
collection = self._collection()
collection.external_account_id = "collection url"
# Oops, the collection doesn't actually support registration.
form = MultiDict([
("collection_id", collection.id),
("library_short_name", "not-a-library"),
def test_jti2id():
eq_(tokenstr.jti2id('t12'), 12)
assert_raises(TypeError, lambda:
tokenstr.jti2id('xx'))
assert_raises(TypeError, lambda:
tokenstr.jti2id(None))
return Background(n_backgrounds=10, path='../ground_pics', width_range=[])
def instantiate_widthtoolittle():
return Background(n_backgrounds=10, path='../ground_pics', input_size=(250, 200), width_range=[32, 33])
def instantiate_nowidth():
return Background(n_backgrounds=10, path='../ground_pics')
def call_none():
d = Crop()
d.call(None)
assert_raises(ValueError, instantiate_name_none)
assert_raises(ValueError, instantiate_nobackgrounds)
assert_raises(ValueError, instantiate_foldernotexist)
assert_raises(ValueError, instantiate_folderisfile)
assert_raises(ValueError, instantiate_nresnegative)
assert_raises(ValueError, instantiate_inputsizenotuple)
assert_raises(ValueError, instantiate_inputsizeno2)
assert_raises(ValueError, instantiate_inputsizenegative)
assert_raises(ValueError, instantiate_widthnone)
assert_raises(ValueError, instantiate_widthnotlist)
assert_raises(ValueError, instantiate_widthemptylist)
assert_raises(ValueError, instantiate_widthtoolittle)
assert_raises(ValueError, instantiate_nowidth)
assert_raises(ValueError, call_none)
with RaiseAssertor(Exception):
raise Exception
with RaiseAssertor(Exception):
raise TypeError
def f():
with RaiseAssertor(ZeroDivisionError):
raise MyException
nose.tools.assert_raises(Failure, f)
with RaiseAssertor(Failure):
f()
def g():
with RaiseAssertor(Exception):
pass
nose.tools.assert_raises(Failure, g)
with RaiseAssertor(Failure):
g()
def h():
with RaiseAssertor(RuntimeError, 'booga'):
pass
nose.tools.assert_raises(Failure, h)
with RaiseAssertor(Failure):
h()
with RaiseAssertor(Failure) as raise_assertor:
assert isinstance(raise_assertor, RaiseAssertor)
with RaiseAssertor(RuntimeError):
{}[0]
assert isinstance(raise_assertor.exception, Exception)
def should_raise_exception_without_saving(self):
assert_raises(UnsafeBehaviorError, self.doc.save)
assert not self.doc.collection.calls('insert')
def test_min_max_prob(self):
"""Tests setting of probability factors."""
assert_raises(FactorError, self.factors.set_min_max_prob, -0.1, 0.5)
assert_raises(FactorError, self.factors.set_min_max_prob, 1.1, 0.5)
assert_raises(FactorError, self.factors.set_min_max_prob, 0.1, -0.5)
assert_raises(FactorError, self.factors.set_min_max_prob, 0.1, 1.5)
assert_raises(FactorError, self.factors.set_min_max_prob, 0.5, 0.1)
self.factors.set_min_max_prob(0.1, 0.5)
assert_equal(0.1, self.factors.min_prob)
assert_equal(0.5, self.factors.max_prob)
def test_getitem__when_there_are_no_arguments(self, sys):
sys.argv = ['catsnap']
config = ArgumentConfig()
assert_raises(KeyError, lambda: config['bucket'])
def test_remove_key(self):
batch = cf.batch()
batch.insert('1', ROWS['1'])
batch.remove('1')
batch.send()
assert_raises(NotFoundException, cf.get, '1')
def test_illegal_input():
'''Test `resolve` raises exception when given illegal input.'''
nose.tools.assert_raises(Exception,
resolve,
'asdgfasdgas if 4 else asdfasdfa ')
nose.tools.assert_raises(Exception,
resolve,
'dgf sdfg sdfga ')
nose.tools.assert_raises(Exception,
resolve,
'4- ')
def test_no_cache_attached(self):
"""Test behavior or CacheManifest if no cache is available."""
manifest = CacheManifest()
# If no cache is enabled, an error is raised
self.env.cache = False
assert_raises(EnvironmentError,
manifest.remember, self.bundle, self.env, 'the-version')
assert_raises(EnvironmentError,
manifest.query, self.bundle, self.env)