예제 #1
0
    def test_ranges(self):
        expected = "startkey={0}".format(ulp.quote(json.dumps("foo")))
        self._assert_vopteq(expected, "mapkey_range", ["foo"])
        self._assert_vopteq_multi(
            {
                'startkey': json.dumps("foo"),
                'endkey': json.dumps("bar")
            }, "mapkey_range", ["foo", "bar"])

        expected = "startkey_docid=bar"
        self._assert_vopteq(expected, "dockey_range", ["bar"])
        self._assert_vopteq_multi(
            {
                'startkey_docid': "range_begin",
                'endkey_docid': "range_end"
            }, "dockey_range", ["range_begin", "range_end"])

        for p in ('mapkey_range', 'dockey_range'):
            self._assert_vopteq('', p, [])
            self._assert_vopteq('', p, UNSPEC)
            self._assert_vopteq('', p, [UNSPEC, UNSPEC])
            self._assert_vopteq('', p, [UNSPEC])

            self.assertRaises(ArgumentError, self._assert_vopteq, "blah", p,
                              [object()])

            self.assertRaises(ArgumentError, self._assert_vopteq, "blah", p,
                              None)
예제 #2
0
    def _assert_vopteq_multi(self, d, key, value):
        q = Query(**{key: value})
        enc = q.encoded
        res = {}
        for kvp in enc.split("&"):
            k, v = kvp.split("=")
            res[k] = v

        d = d.copy()
        for k in d:
            d[k] = ulp.quote(d[k])

        self.assertEqual(res, d)
예제 #3
0
    def test_string_params(self):
        # This test is mainly to see that 'stupid' things don't make
        # their way through as strings, like booleans and None
        sparams = ('endkey_docid', 'startkey_docid')

        goodvals = ("string", -1, "OHAI!", '&&escape_me_nao&&')
        badvals = (True, False, None, object(), [])

        for p in sparams:
            for v in goodvals:
                expected = "{0}={1}".format(p, ulp.quote(str(v)))
                self._assert_vopteq(expected, p, v)

            for v in badvals:
                self.assertRaises(ArgumentError, make_options_string, {p: v})
예제 #4
0
    def test_encode_string_to_json(self):
        jparams = ('endkey', 'key', 'startkey')

        values = ('dummy', 42, None, True, False, {
            "chicken": "broth"
        }, ["noodle", "soup"], ["lone element"], ("empty tuple", ))

        for p in jparams:
            for v in values:
                expected = p + '=' + ulp.quote(json.dumps(v))
                print("Expected", expected)
                self._assert_vopteq(expected, p, v)

            self.assertRaises(ArgumentError, self._assert_vopteq, "blah", p,
                              object())
예제 #5
0
    def test_encode_to_jarray(self):
        jparams = ('keys', )  #add more here
        values = (['foo', 'bar'], ['foo'])

        badvalues = (True, False, {"foo": "bar"}, 1, "string")

        for p in jparams:
            for v in values:

                print(v)
                expected = p + '=' + ulp.quote(json.dumps(v))
                self._assert_vopteq(expected, p, v)

            for v in badvalues:
                self.assertRaises(ArgumentError, self._assert_vopteq, "blah",
                                  p, v)