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_invalid_limit(self):
"""
Test limit translation fails when a non-integer value is used.
"""
msg = 'Argument limit not instance of expected type:'
with self.assertRaises(CloudantArgumentError) as cm:
python_to_couch({'limit': True})
self.assertTrue(str(cm.exception).startswith(msg))
def test_invalid_startkey_docid(self):
"""
Test startkey_docid translation fails when a non-string value is used.
"""
msg = 'Argument startkey_docid not instance of expected type:'
with self.assertRaises(CloudantArgumentError) as cm:
python_to_couch({'startkey_docid': 10})
self.assertTrue(str(cm.exception).startswith(msg))
def test_valid_group(self):
"""
Test group translation is successful.
"""
self.assertEqual(python_to_couch({'group': True}), {'group': 'true'})
self.assertEqual(python_to_couch({'group': False}), {'group': 'false'})
def test_invalid_group_level(self):
"""
Test group_level translation fails when a non-integer value is used.
"""
msg = 'Argument group_level not instance of expected type:'
with self.assertRaises(CloudantArgumentError) as cm:
python_to_couch({'group_level': True})
self.assertTrue(str(cm.exception).startswith(msg))
def test_invalid_group(self):
"""
Test group translation fails when a non-bool value is used.
"""
msg = 'Argument group not instance of expected type:'
with self.assertRaises(CloudantArgumentError) as cm:
python_to_couch({'group': 10})
self.assertTrue(str(cm.exception).startswith(msg))
def test_valid_inclusive_end(self):
"""
Test inclusive_end translation is successful.
"""
self.assertEqual(
python_to_couch({'inclusive_end': True}),
{'inclusive_end': 'true'}
)
self.assertEqual(
python_to_couch({'inclusive_end': False}),
{'inclusive_end': 'false'}
)
def test_invalid_descending(self):
"""
Test descending translation fails when a non-bool value is used.
"""
msg = 'Argument descending not instance of expected type:'
with self.assertRaises(CloudantArgumentError) as cm:
python_to_couch({'descending': 10})
self.assertTrue(str(cm.exception).startswith(msg))
def test_valid_endkey(self):
"""
Test endkey translation is successful.
"""
self.assertEqual(python_to_couch({'endkey': 10}), {'endkey': 10})
# Test with long type
self.assertEqual(python_to_couch({'endkey': LONG_NUMBER}), {'endkey': LONG_NUMBER})
self.assertEqual(
python_to_couch({'endkey': 'foo'}),
{'endkey': '"foo"'}
)
self.assertEqual(
python_to_couch({'endkey': ['foo', 10]}),
{'endkey': '["foo", 10]'}
)
def test_invalid_keys_invalid_key(self):
"""
Test keys translation fails when a key value used in the key list is
not a valid value.
"""
msg = 'Key list element not of expected type:'
with self.assertRaises(CloudantArgumentError) as cm:
python_to_couch({'keys': ['foo', True, 'bar']})
self.assertTrue(str(cm.exception).startswith(msg))
def test_valid_startkey_docid(self):
"""
Test startkey_docid translation is successful.
"""
self.assertEqual(
python_to_couch({'startkey_docid': 'foo'}),
{'startkey_docid': 'foo'}
)