Exemplo n.º 1
0
 def test_create_admin_account_throws_rql_driver_error(self):
     with patch.object(Interactions, 'insert',
                       side_effect=RqlDriverError(None)):
         with self.assertRaises(RqlDriverError) as cm:
             create_admin_account()
             self.assertEqual(cm.exception,
                              RqlDriverError(None))
Exemplo n.º 2
0
    def close(self, noreply_wait=False, token=None, exception=None):
        self._closing = True
        if exception is not None:
            err_message = "Connection is closed (%s)." % str(exception)
        else:
            err_message = "Connection is closed."

        # Cursors may remove themselves when errored, so copy a list of them
        for cursor in list(self._cursor_cache.values()):
            cursor._error(err_message)

        for query, async_res in iter(self._user_queries.values()):
            async_res.set_exception(RqlDriverError(err_message))

        self._user_queries = {}
        self._cursor_cache = {}

        if noreply_wait:
            noreply = net.Query(pQuery.NOREPLY_WAIT, token, None, None)
            self.run_query(noreply, False)

        try:
            self._socket.close()
        except OSError:
            pass
Exemplo n.º 3
0
    def _reader(self):
        try:
            while True:
                buf = self._socket.recvall(12)
                (token, length,) = struct.unpack("<qL", buf)
                buf = self._socket.recvall(length)

                cursor = self._cursor_cache.get(token)
                if cursor is not None:
                    cursor._extend(buf)
                elif token in self._user_queries:
                    # Do not pop the query from the dict until later, so
                    # we don't lose track of it in case of an exception
                    query, async_res = self._user_queries[token]
                    res = net.Response(token, buf, self._parent._get_json_decoder(query))
                    if res.type == pResponse.SUCCESS_ATOM:
                        async_res.set(net.maybe_profile(res.data[0], res))
                    elif res.type in (pResponse.SUCCESS_SEQUENCE,
                                      pResponse.SUCCESS_PARTIAL):
                        cursor = GeventCursor(self, query, res)
                        async_res.set(net.maybe_profile(cursor, res))
                    elif res.type == pResponse.WAIT_COMPLETE:
                        async_res.set(None)
                    else:
                        async_res.set_exception(res.make_error(query))
                    del self._user_queries[token]
                elif not self._closing:
                    raise RqlDriverError("Unexpected response received.")
        except Exception as ex:
            if not self._closing:
                self.close(exception=ex)
Exemplo n.º 4
0
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_driver_error(self):
     with self.app.test_request_context():
         with patch.object(Interactions, 'query',
                           side_effect=RqlDriverError(None)):
                 response = reset_key('johndoe', 'api_key')
                 self.assertRaises(RqlDriverError)
                 self.assertEqual(response.status_code,
                                  client.INTERNAL_SERVER_ERROR)
 def test_delete_rql_driver_error(self):
     with self.app.test_request_context():
         with patch.object(Interactions, 'delete',
                           side_effect=RqlDriverError(None)):
             response = delete(DEFAULT_SUBSCRIPTIONS_TABLE, '123')
             self.assertRaises(RqlDriverError)
             self.assertEqual(response.status_code,
                              client.INTERNAL_SERVER_ERROR)
 def test_delete_registration_rql_driver_error(self):
     with self.app.test_request_context():
         with patch.object(Interactions, 'delete_specific',
                           side_effect=RqlDriverError(None)):
             response = delete_registration('123')
             self.assertRaises(RqlDriverError)
             self.assertEqual(response.status_code,
                              client.INTERNAL_SERVER_ERROR)
 def test_query_rql_driver_error(self):
     with self.app.test_request_context():
         with patch.object(Interactions, 'get',
                           side_effect=RqlDriverError(None)):
             response = query(DEFAULT_REGISTRATIONS_TABLE, record_id='123')
             self.assertRaises(RqlDriverError)
             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'))
Exemplo n.º 10
0
 def test_delete_account_rql_driver_error(self):
     with self.app.test_request_context():
         with patch.object(Interactions, 'query',
                           side_effect=RqlDriverError(None)):
             response = insert_account(DEFAULT_SUBSCRIPTIONS_TABLE,
                                       **self.param_kwargs)
             self.assertRaises(RqlDriverError)
             self.assertEqual(response.status_code,
                              client.INTERNAL_SERVER_ERROR)
Exemplo n.º 11
0
 def test_update_rql_driver_error(self):
     with self.app.test_request_context():
         with patch.object(Interactions, 'update',
                           side_effect=RqlDriverError(None)):
             update(DEFAULT_REGISTRATIONS_TABLE,
                    record_id='123',
                    username=None,
                    updates={})
             self.assertRaises(RqlDriverError)
Exemplo n.º 12
0
 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)
Exemplo n.º 13
0
 def test_drop_database_throws_rql_driver_error(self, _):
     with self.assertRaises(RqlDriverError) as cm:
         drop_database()
         self.assertEqual(cm.exception, RqlDriverError(None))