def rql_merge_with(ext_with, to_extend): out = {} out.update(to_extend) if is_literal(ext_with): if has_nested_literal(ext_with): raise RqlRuntimeError('No nested r.literal()!') for k, v in iteritems(ext_with): if is_literal(v): if has_nested_literal(v): raise RqlRuntimeError('No nested r.literal()!') if k not in to_extend: out[k] = util.clone(v) else: d1_val = to_extend[k] if is_literal(v): out[k] = util.clone(v) else: if isinstance(d1_val, dict) and (isinstance( v, dict) or isinstance(v, LITERAL_OBJECT)): out[k] = rql_merge_with(v, d1_val) elif isinstance(d1_val, list) and (isinstance( v, list) or isinstance(v, LITERAL_LIST)): out[k] = util.cat(d1_val, v) else: out[k] = util.clone(v) return out
def test_create_admin_account_throws_rql_runtime_error(self): with patch.object(Interactions, 'insert', side_effect=RqlRuntimeError(None, None, None)): with self.assertRaises(RqlRuntimeError) as cm: create_admin_account() self.assertEqual(cm.exception, RqlRuntimeError(None, None, None))
class WhenTestingDrop(unittest.TestCase): def setUp(self): pass @patch('pywebhooks.database.rethinkdb.drop.get_connection') def test_drop_database(self, connection_method): connection_method.return_value = Mock(__enter__=Mock, __exit__=Mock()) with patch.object(rethink, 'db_drop', return_value=Mock()) as \ db_drop_method: drop_database() db_drop_method.assert_called_once_with(DEFAULT_DB_NAME) @patch('pywebhooks.database.rethinkdb.drop.get_connection', side_effect=RqlDriverError(None)) def test_drop_database_throws_rql_driver_error(self, _): with self.assertRaises(RqlDriverError) as cm: drop_database() self.assertEqual(cm.exception, RqlDriverError(None)) @patch('pywebhooks.database.rethinkdb.drop.get_connection', side_effect=RqlRuntimeError(None, None, None)) def test_drop_database_throws_rql_runtime_error(self, _): with self.assertRaises(RqlRuntimeError) as cm: drop_database() self.assertEqual(cm.exception, RqlRuntimeError(None, None, None))
def test_reset_key_rql_runtime_error(self): with self.app.test_request_context(): with patch.object(Interactions, 'query', side_effect=RqlRuntimeError(None, None, None)): response = reset_key('johndoe', 'api_key') self.assertRaises(RqlRuntimeError) self.assertEqual(response.status_code, client.INTERNAL_SERVER_ERROR)
def test_delete_rql_runtime_error(self): with self.app.test_request_context(): with patch.object(Interactions, 'delete', side_effect=RqlRuntimeError(None, None, None)): response = delete(DEFAULT_SUBSCRIPTIONS_TABLE, '123') self.assertRaises(RqlRuntimeError) self.assertEqual(response.status_code, client.INTERNAL_SERVER_ERROR)
def test_delete_registration_rql_runtime_error(self): with self.app.test_request_context(): with patch.object(Interactions, 'delete_specific', side_effect=RqlRuntimeError(None, None, None)): response = delete_registration('123') self.assertRaises(RqlRuntimeError) self.assertEqual(response.status_code, client.INTERNAL_SERVER_ERROR)
def test_query_rql_runtime_error(self): with self.app.test_request_context(): with patch.object(Interactions, 'get', side_effect=RqlRuntimeError(None, None, None)): response = query(DEFAULT_REGISTRATIONS_TABLE, record_id='123') self.assertRaises(RqlRuntimeError) self.assertEqual(response.status_code, client.INTERNAL_SERVER_ERROR)
def test_update_failed_count_exceptions(self): with patch.object(Interactions, 'get', side_effect=RqlRuntimeError(None, None, None)): self.assertIsNone(update_failed_count(account_id='123')) with patch.object(Interactions, 'get', side_effect=RqlDriverError(None)): self.assertIsNone(update_failed_count(account_id='123'))
def test_insert_account_rql_runtime_error(self): with self.app.test_request_context(): with patch.object(Interactions, 'query', side_effect=RqlRuntimeError(None, None, None)): response = insert_account(DEFAULT_SUBSCRIPTIONS_TABLE, **self.param_kwargs) self.assertRaises(RqlRuntimeError) self.assertEqual(response.status_code, client.INTERNAL_SERVER_ERROR)
def raise_rql_runtime_error(self, msg): from rethinkdb.errors import RqlRuntimeError # temporary jankiness to get it working # doing it this way means error messages won't # be properly printed term = AttrHaving({ 'args': (), 'optargs': {}, 'compose': (lambda x, y: 'COMPOSED') }) raise RqlRuntimeError(msg, term, [])
def _check_error_response(cls, response, term): if response.type == pResponse.RUNTIME_ERROR: message = response.data[0] frames = response.backtrace return RqlRuntimeError(message, term, frames) elif response.type == pResponse.COMPILE_ERROR: message = response.data[0] frames = response.backtrace return RqlCompileError(message, term, frames) elif response.type == pResponse.CLIENT_ERROR: message = response.data[0] frames = response.backtrace return RqlClientError(message, term, frames) elif response.type not in (pResponse.SUCCESS_ATOM, pResponse.SUCCESS_SEQUENCE, pResponse.SUCCESS_PARTIAL, pResponse.SUCCESS_FEED, pResponse.WAIT_COMPLETE): return RqlDriverError( "Unknown Response type %d encountered in response." % response.type)
def _check_connections(self): if self.rdb_conn not in connections: raise RqlRuntimeError('Connection is not in the connection pool')
def test_drop_database_throws_rql_runtime_error(self, _): with self.assertRaises(RqlRuntimeError) as cm: drop_database() self.assertEqual(cm.exception, RqlRuntimeError(None, None, None))