def _view(self, ddoc, view,
              use_devmode=False,
              params=None,
              unrecognized_ok=False,
              passthrough=False):
        """
        .. warning:: This method's API is not stable

        Execute a view (MapReduce) query

        :param string ddoc: Name of the design document
        :param string view: Name of the view function to execute
        :param params: Extra options to pass to the view engine
        :type params: string or dict

        :return: a :class:`HttpResult` object.
        """

        if params:
            if not isinstance(params, str):
                params = make_options_string(
                    params,
                    unrecognized_ok=unrecognized_ok,
                    passthrough=passthrough)
        else:
            params = ""

        ddoc = self._mk_devmode(ddoc, use_devmode)
        url = make_dvpath(ddoc, view) + params

        ret = self._http_request(type=_LCB.LCB_HTTP_TYPE_VIEW,
                                 path=url,
                                 method=_LCB.LCB_HTTP_METHOD_GET,
                                 response_format=FMT_JSON)
        return ret
    def test_passthrough(self):
        values = (
            "blah",
            -1,
            "-invalid/uri&char")

        for p in _HANDLER_MAP.keys():
            for v in values:
                expected = "{0}={1}".format(p, v)
                got = make_options_string({p:v}, passthrough=True)
                self.assertEqual(expected, got)


        # Ensure we still can't use unrecognized params
        self.assertRaises(ArgumentError,
                          make_options_string,
                          {'foo':'bar'},
                          passthrough=True)


        # ensure we still can't use "stupid" params
        badvals = (object(), None, True, False)
        for bv in badvals:
            self.assertRaises(ArgumentError,
                              make_options_string,
                              {'stale':bv},
                              passthrough=True)
Exemplo n.º 3
0
    def test_passthrough(self):
        values = (
            "blah",
            -1,
            "-invalid/uri&char")

        for p in _HANDLER_MAP.keys():
            for v in values:
                expected = "{0}={1}".format(p, v)
                got = make_options_string({p:v}, passthrough=True)
                self.assertEqual(expected, got)


        # Ensure we still can't use unrecognized params
        self.assertRaises(ArgumentError,
                          make_options_string,
                          {'foo':'bar'},
                          passthrough=True)


        # ensure we still can't use "stupid" params
        badvals = (object(), None, True, False)
        for bv in badvals:
            self.assertRaises(ArgumentError,
                              make_options_string,
                              {'stale':bv},
                              passthrough=True)
Exemplo n.º 4
0
    def test_unrecognized(self):
        keys = ("new_param", "another_param")
        values = ("blah", -1, "-invalid-uri-char^&")
        for p in keys:
            for v in values:
                got = make_options_string({p: v}, unrecognized_ok=True)
                expected = "{0}={1}".format(p, v)
                self.assertEqual(expected, got)

        badvals = (object(), True, False, None)
        for bv in badvals:
            self.assertRaises(ArgumentError,
                              make_options_string, {'foo': bv},
                              unrecognized_ok=True)
    def test_unrecognized(self):
        keys = ("new_param", "another_param")
        values = ("blah", -1, "-invalid-uri-char^&")
        for p in keys:
            for v in values:
                got = make_options_string({p:v},
                    unrecognized_ok=True)
                expected = "{0}={1}".format(p, v)
                self.assertEqual(expected, got)


        badvals = (object(), True, False, None)
        for bv in badvals:
            self.assertRaises(ArgumentError,
                              make_options_string,
                              {'foo':bv},
                              unrecognized_ok=True)
    def _view(self,
              ddoc,
              view,
              use_devmode=False,
              params=None,
              unrecognized_ok=False,
              passthrough=False):
        """
        .. warning:: This method's API is not stable

        Execute a view (MapReduce) query

        :param string ddoc: Name of the design document
        :param string view: Name of the view function to execute
        :param params: Extra options to pass to the view engine
        :type params: string or dict

        :return: a :class:`~couchbase.result.HttpResult` object.
        """

        if params:
            if not isinstance(params, str):
                params = make_options_string(params,
                                             unrecognized_ok=unrecognized_ok,
                                             passthrough=passthrough)
        else:
            params = ""

        ddoc = self._mk_devmode(ddoc, use_devmode)
        url = make_dvpath(ddoc, view) + params

        ret = self._http_request(type=_LCB.LCB_HTTP_TYPE_VIEW,
                                 path=url,
                                 method=_LCB.LCB_HTTP_METHOD_GET,
                                 response_format=FMT_JSON)
        return ret
Exemplo n.º 7
0
 def _assert_vopteq(self, expected, key, value):
     s = make_options_string({key: value})
     self.assertEqual(s, expected)
 def _assert_vopteq(self, expected, key, value):
     s = make_options_string({key:value})
     self.assertEqual(s, expected)