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_map_setter_failure(self):
"""
Test that the map setter fails if a dict is not supplied
"""
try:
self.view.map = 'function (doc) {\n emit(doc._id, 1);\n}'
self.fail('Above statement should raise an Exception')
except CloudantArgumentError as err:
self.assertEqual(
str(err),
'The map property must be a dictionary.'
)
def test_set_year_with_invalid_month_for_volume_usage_data(self):
"""
Test raising an exception when retrieving volume usage data with an
invalid month parameter
"""
try:
self.client.connect()
year = 2016
month = 13
with self.assertRaises(CloudantArgumentError) as cm:
self.client.volume_usage(year, month)
expected = ('Invalid year and/or month supplied. '
'Found: year - 2016, month - 13')
self.assertEqual(str(cm.exception), expected)
finally:
self.client.disconnect()
def test_callable_without_selector(self):
"""
Test Query __call__ without providing a selector
"""
query = Query(self.db)
try:
query(fields=['_id', '_rev'])
self.fail('Above statement should raise an Exception')
except CloudantArgumentError as err:
self.assertEqual(
str(err),
'No selector in the query or the selector was empty. '
'Add a selector to define the query and retry.'
def test_reduce_setter_failure(self):
"""
Test that the reduce setter fails if a string is not supplied
"""
with self.assertRaises(CloudantArgumentError) as cm:
self.view.reduce = {'_count'}
err = cm.exception
self.assertEqual(str(err), 'The reduce property must be a string.')
def test_invalid_feed_value(self):
"""
Test that an invalid feed argument value is caught and an exception is
raised
"""
feed = Feed(self.client, feed='foo')
with self.assertRaises(CloudantArgumentError) as cm:
invalid_feed = [x for x in feed]
self.assertTrue(str(cm.exception).startswith(
'Invalid value (foo) for feed option.'))
def test_deleting_index_without_index_name(self):
"""
Tests that deleting an index without an index name provided fails as
expected.
"""
ddoc = DesignDocument(self.db, '_design/ddoc001')
index = Index(self.db, 'ddoc001', fields=['name', 'age'])
self.assertFalse(ddoc.exists())
with self.assertRaises(CloudantArgumentError) as cm:
index.delete()
err = cm.exception
self.assertEqual(
str(err),
'Deleting an index requires an index name be provided.'
)
def test_invalid_argument_type(self):
"""
Test that an invalid argument type is caught and an exception is raised
"""
feed = Feed(self.db, conflicts=0)
with self.assertRaises(CloudantArgumentError) as cm:
invalid_feed = [x for x in feed]
self.assertTrue(
str(cm.exception).startswith('Argument conflicts not instance of expected type:')
)
def test_create_a_search_index_invalid_argument(self):
"""
Test that a TEXT index is not created when an invalid argument is given.
"""
index = TextIndex(self.db, 'ddoc001', 'index001', foo='bar')
with self.assertRaises(CloudantArgumentError) as cm:
index.create()
err = cm.exception
self.assertEqual(str(err), 'Invalid argument: foo')
def test_share_database_invalid_role(self):
"""
Test the sharing of a database fails when provided an invalid role.
"""
share = 'user-{0}'.format(unicode_(uuid.uuid4()))
with self.assertRaises(CloudantArgumentError) as cm:
self.db.share_database(share, ['_writer', '_invalid_role'])
err = cm.exception
self.assertEqual(
str(err),
'Invalid role(s) provided: '
'[\'_writer\', \'_invalid_role\']. Valid roles are: '
def test_invalid_stale(self):
"""
Test stale translation fails when the value is not either
'ok' or 'update_after' is used.
"""
msg = 'Argument stale not instance of expected type:'
with self.assertRaises(CloudantArgumentError) as cm:
python_to_couch({'stale': 10})
self.assertTrue(str(cm.exception).startswith(msg))
msg = 'Invalid value for stale option foo'
with self.assertRaises(CloudantArgumentError) as cm:
python_to_couch({'stale': 'foo'})
self.assertTrue(str(cm.exception).startswith(msg))