Esempio n. 1
0
 def test_basic(self):
     data = http_fetch_json("/put", dict(key="test_basic", value="12345"))
     data = http_fetch_json("/get", dict(key="test_basic"))
     assert data == "12345"
     data = http_fetch_json("/get", dict(key="test_basic", format="json"))
     assert data == "12345"
     data = http_fetch("/get", dict(key="test_basic", format="txt"))
     assert data == "test_basic,12345\n"
     data = http_fetch("/get", dict(key="test_basic", format="txt", separator="/"))
     assert data == "test_basic/12345\n"
     data = http_fetch("/put", dict(key="test_basic", value="22", format="txt"))
     data = http_fetch_json("/get", dict(key="test_basic"))
     assert data == "22"
     data = http_fetch_json("/put", dict(key="test_basic", value="33", format="json"))
     data = http_fetch_json("/get", dict(key="test_basic"))
     assert data == "33"
     data = http_fetch_json("/put", dict(key="test_basic"), body="44")
     data = http_fetch_json("/get", dict(key="test_basic"))
     assert data == "44"
     data = http_fetch_json("/del", dict(key="test_basic"))
     data = http_fetch_json("/get", dict(key="test_basic"), 404, "NOT_FOUND")
     data = http_fetch("/get", dict(key="test_basic", format="txt"), 404)
     data = http_fetch_json("/get", dict(key="test_basic", format="json"), 404, "NOT_FOUND")
     data = http_fetch_json("/put", dict(key="test_basic", value="a"))
     data = http_fetch("/del", dict(key="test_basic", format="txt"))
     data = http_fetch_json("/get", dict(key="test_basic"), 404, "NOT_FOUND")
 def test_lists_2(self):
     http_fetch_json('/list_prepend', dict(key='new_list', value='appval1'))
     data = http_fetch_json(
         '/list_prepend',
         dict(key='new_list', value='appvala', return_data='1'))
     assert data['value'] == ['appvala', 'appval1']
     data = http_fetch(
         '/list_prepend',
         dict(key='new_list',
              value='appvalb',
              return_data='1',
              format='txt'))
     assert data == 'new_list,appvalb,appvala,appval1\n'
     data = http_fetch_json('/get', dict(key='new_list'))
     assert data == 'appvalb,appvala,appval1'
     data = http_fetch_json('/list_pop', dict(key='new_list'))
     assert data['popped'] == ['appvalb']
     data = http_fetch_json('/get', dict(key='new_list'))
     assert data == 'appvala,appval1'
     data = http_fetch('/list_pop',
                       dict(key='new_list', position='-1', format='txt'))
     assert data == 'appval1\n'
     data = http_fetch_json('/get', dict(key='new_list'))
     assert data == 'appvala'
     http_fetch_json(
         '/list_append',
         dict(key='new_list', value=["blah1", "blah2", "blah3"]))
     data = http_fetch_json('/get', dict(key='new_list'))
     assert data == 'appvala,blah1,blah2,blah3'
     data = http_fetch_json('/list_pop',
                            dict(key='new_list', position='2', count='2'))
     assert data['popped'] == ['blah2', 'blah3']
 def test_basic(self):
     data = http_fetch_json('/put', dict(key='test_basic', value='12345'))
     data = http_fetch_json('/get', dict(key='test_basic'))
     assert data == '12345'
     data = http_fetch_json('/get', dict(key='test_basic', format='json'))
     assert data == '12345'
     data = http_fetch('/get', dict(key='test_basic', format='txt'))
     assert data == 'test_basic,12345\n'
     data = http_fetch('/get',
                       dict(key='test_basic', format='txt', separator='/'))
     assert data == 'test_basic/12345\n'
     data = http_fetch('/put',
                       dict(key='test_basic', value='22', format='txt'))
     data = http_fetch_json('/get', dict(key='test_basic'))
     assert data == '22'
     data = http_fetch_json(
         '/put', dict(key='test_basic', value='33', format='json'))
     data = http_fetch_json('/get', dict(key='test_basic'))
     assert data == '33'
     data = http_fetch_json('/put', dict(key='test_basic'), body="44")
     data = http_fetch_json('/get', dict(key='test_basic'))
     assert data == '44'
     data = http_fetch_json('/del', dict(key='test_basic'))
     data = http_fetch_json('/get', dict(key='test_basic'), 404,
                            'NOT_FOUND')
     data = http_fetch('/get', dict(key='test_basic', format='txt'), 404)
     data = http_fetch_json('/get', dict(key='test_basic', format='json'),
                            404, 'NOT_FOUND')
     data = http_fetch_json('/put', dict(key='test_basic', value='a'))
     data = http_fetch('/del', dict(key='test_basic', format='txt'))
     data = http_fetch_json('/get', dict(key='test_basic'), 404,
                            'NOT_FOUND')
Esempio n. 4
0
    def test_basic(self):
        data = http_fetch_json('/put', dict(key='test', value='12345'))
        data = http_fetch_json('/get', dict(key='test'))
        assert data == '12345'
        data = http_fetch('/get', dict(key='test', format='txt'))
        assert data == 'test,12345\n'
        data = http_fetch_json('/del', dict(key='test'))
        data = http_fetch_json('/get', dict(key='test'), 404, 'NOT_FOUND')
        
        http_fetch_json("/put", dict(), 400, 'MISSING_ARG_KEY')
        http_fetch_json("/put", dict(key='test'), 400, 'MISSING_ARG_VALUE')
        http_fetch_json("/get", dict(), 400, 'MISSING_ARG_KEY')
        
        http_fetch_json('/put', dict(key='test1', value='asdf1'))
        http_fetch_json('/put', dict(key='test2', value='asdf2'))
        
        data = http_fetch('/mget', dict(key=['test1', 'test2', 'test3'], format='txt'))
        print data
        assert data == 'test1,asdf1\ntest2,asdf2\n'
        
        
        # test list stuff
        http_fetch_json('/get', dict(key='list_test'), 404, 'NOT_FOUND')
        data = http_fetch_json('/list_append', dict(key='list_test', value='testvalue1', echo_data='1'))
        assert data == 'testvalue1'
        data = http_fetch_json('/list_append', dict(key='list_test', value='testvalue2'))
        assert data == ''
        data = http_fetch_json('/get', dict(key='list_test'))
        assert data == 'testvalue1,testvalue2'
        data = http_fetch_json('/list_append', dict(key='list_test', value='testvalue3'))
        data = http_fetch_json('/list_remove', dict(key='list_test', value='testvalue2'))
        data = http_fetch_json('/get', dict(key='list_test'))
        assert data == 'testvalue1,testvalue3'
        data = http_fetch_json('/list_remove', dict(key='list_test', value='testvalue1'))
        data = http_fetch_json('/get', dict(key='list_test'))
        assert data == 'testvalue3'
        
        # try a /put with a POST body
        http_fetch_json('/put', dict(key='testpost'), body='asdfpost')
        data = http_fetch_json('/get', dict(key='testpost'))
        assert data == 'asdfpost'
        data = http_fetch_json('/del', dict(key='testpost'))
        
        # test dump to csv
        # we need to check more than 500 entries
        for x in range(505):
            http_fetch_json('/put', dict(key='dump.%d' % x, value='dump.value.%d' % x))
        
        data = http_fetch('/dump_csv')
        assert data.startswith("dump.0,dump.value.0\n")
        assert data.endswith("test2,asdf2\n")
        assert data.count("\n") > 505
        
        data = http_fetch('/dump_csv', dict(key="dump."))
        assert data.count("\n") == 505

        
 def test_multikey(self):
     http_fetch_json('/put', dict(key='test_multikey_1', value='asdf1'))
     http_fetch_json('/put', dict(key='test_multikey_2', value='asdf2'))
     data = http_fetch_json(
         '/mget',
         dict(
             key=['test_multikey_1', 'test_multikey_2', 'test_multikey_3']))
     assert data == [{
         'key': 'test_multikey_1',
         'value': 'asdf1'
     }, {
         'key': 'test_multikey_2',
         'value': 'asdf2'
     }]
     data = http_fetch(
         '/mget',
         dict(key=['test_multikey_1', 'test_multikey_2', 'test_multikey_3'],
              format='txt'))
     assert data == 'test_multikey_1,asdf1\ntest_multikey_2,asdf2\n'
     data = http_fetch_json("/fwmatch", dict(key="test_multikey"))
     assert data == [{
         'key': 'test_multikey_1',
         'value': 'asdf1'
     }, {
         'key': 'test_multikey_2',
         'value': 'asdf2'
     }]
     data = http_fetch_json(
         "/range_match", dict(start="test_multikey_1",
                              end="test_multikey_2"))
     assert data == [{
         'key': 'test_multikey_1',
         'value': 'asdf1'
     }, {
         'key': 'test_multikey_2',
         'value': 'asdf2'
     }]
     data = http_fetch(
         "/range_match",
         dict(start="test_multikey_1", end="test_multikey_2", format='txt'))
     assert data == "test_multikey_1,asdf1\ntest_multikey_2,asdf2\n"
     data = http_fetch("/fwmatch", dict(key="test_multikey", format="txt"))
     assert data == "test_multikey_1,asdf1\ntest_multikey_2,asdf2\n"
     http_fetch_json(
         '/mput',
         body=
         'test_multikey_3,mv1a;mv1b\ntest_multikey_4,mv2a;mv2b\ntest_multikey_5,mv3a'
     )
     data = http_fetch_json('/get', dict(key='test_multikey_3'))
     assert data == 'mv1a;mv1b'
     data = http_fetch(
         '/mget',
         dict(key=['test_multikey_4', 'test_multikey_5'], format='txt'))
     assert data == 'test_multikey_4,mv2a;mv2b\ntest_multikey_5,mv3a\n'
     http_fetch_json('/mput', body='test_multikey_ms,a,b,c')
     data = http_fetch_json('/get', dict(key='test_multikey_ms'))
     assert data == 'a,b,c'
Esempio n. 6
0
 def test_dump_csv(self):
     # we need to check more than 500 entries
     http_fetch_json("/put", dict(key="zzz.dump", value="bump.value"))
     for x in range(505):
         http_fetch_json("/put", dict(key="dump.%d" % x, value="dump.value.%d" % x))
     data = http_fetch("/dump_csv")
     assert data.startswith("dump.0,dump.value.0\n")
     assert data.count("\n") > 505
     data = http_fetch("/dump_csv", dict(key="dump."))
     assert data.count("\n") == 505
 def test_dump_csv(self):
     # we need to check more than 500 entries
     http_fetch_json('/put', dict(key='zzz.dump', value='bump.value'))
     for x in range(505):
         http_fetch_json('/put',
                         dict(key='dump.%d' % x, value='dump.value.%d' % x))
     data = http_fetch('/dump_csv')
     assert data.startswith("dump.0,dump.value.0\n")
     assert data.count("\n") > 505
     data = http_fetch('/dump_csv', dict(key="dump."))
     assert data.count("\n") == 505
Esempio n. 8
0
 def test_lists_2(self):
     http_fetch_json("/list_prepend", dict(key="new_list", value="appval1"))
     data = http_fetch_json("/list_prepend", dict(key="new_list", value="appvala", return_data="1"))
     assert data["value"] == ["appvala", "appval1"]
     data = http_fetch("/list_prepend", dict(key="new_list", value="appvalb", return_data="1", format="txt"))
     assert data == "new_list,appvalb,appvala,appval1\n"
     data = http_fetch_json("/get", dict(key="new_list"))
     assert data == "appvalb,appvala,appval1"
     data = http_fetch_json("/list_pop", dict(key="new_list"))
     assert data["popped"] == ["appvalb"]
     data = http_fetch_json("/get", dict(key="new_list"))
     assert data == "appvala,appval1"
     data = http_fetch("/list_pop", dict(key="new_list", position="-1", format="txt"))
     assert data == "appval1\n"
     data = http_fetch_json("/get", dict(key="new_list"))
     assert data == "appvala"
     http_fetch_json("/list_append", dict(key="new_list", value=["blah1", "blah2", "blah3"]))
     data = http_fetch_json("/get", dict(key="new_list"))
     assert data == "appvala,blah1,blah2,blah3"
     data = http_fetch_json("/list_pop", dict(key="new_list", position="2", count="2"))
     assert data["popped"] == ["blah2", "blah3"]
Esempio n. 9
0
 def test_multikey(self):
     http_fetch_json("/put", dict(key="test_multikey_1", value="asdf1"))
     http_fetch_json("/put", dict(key="test_multikey_2", value="asdf2"))
     data = http_fetch_json("/mget", dict(key=["test_multikey_1", "test_multikey_2", "test_multikey_3"]))
     assert data == [{"key": "test_multikey_1", "value": "asdf1"}, {"key": "test_multikey_2", "value": "asdf2"}]
     data = http_fetch("/mget", dict(key=["test_multikey_1", "test_multikey_2", "test_multikey_3"], format="txt"))
     assert data == "test_multikey_1,asdf1\ntest_multikey_2,asdf2\n"
     data = http_fetch_json("/fwmatch", dict(key="test_multikey"))
     assert data == [{"key": "test_multikey_1", "value": "asdf1"}, {"key": "test_multikey_2", "value": "asdf2"}]
     data = http_fetch_json("/range_match", dict(start="test_multikey_1", end="test_multikey_2"))
     assert data == [{"key": "test_multikey_1", "value": "asdf1"}, {"key": "test_multikey_2", "value": "asdf2"}]
     data = http_fetch("/range_match", dict(start="test_multikey_1", end="test_multikey_2", format="txt"))
     assert data == "test_multikey_1,asdf1\ntest_multikey_2,asdf2\n"
     data = http_fetch("/fwmatch", dict(key="test_multikey", format="txt"))
     assert data == "test_multikey_1,asdf1\ntest_multikey_2,asdf2\n"
     http_fetch_json("/mput", body="test_multikey_3,mv1a;mv1b\ntest_multikey_4,mv2a;mv2b\ntest_multikey_5,mv3a")
     data = http_fetch_json("/get", dict(key="test_multikey_3"))
     assert data == "mv1a;mv1b"
     data = http_fetch("/mget", dict(key=["test_multikey_4", "test_multikey_5"], format="txt"))
     assert data == "test_multikey_4,mv2a;mv2b\ntest_multikey_5,mv3a\n"
     http_fetch_json("/mput", body="test_multikey_ms,a,b,c")
     data = http_fetch_json("/get", dict(key="test_multikey_ms"))
     assert data == "a,b,c"
Esempio n. 10
0
    def test_basic(self):
        # put/get in order
        http_fetch('/put', dict(data='12345'))
        http_fetch('/put', dict(data='23456'))
        data = json.loads(http_fetch('/stats', dict(format="json")))
        assert data['depth'] == 2
        assert data['bytes'] == 10
        data = http_fetch('/get')
        assert data == "12345"
        data = http_fetch('/get')
        assert data == "23456"
        data = http_fetch('/get')
        assert data == ''

        data = json.loads(http_fetch('/stats', dict(format="json")))
        assert data['depth'] == 0
        assert data['bytes'] == 0

        # mget
        http_fetch('/put', dict(data='12345'))
        http_fetch('/put', dict(data='23456'))
        http_fetch('/put', dict(data='34567'))
        http_fetch('/put', dict(data='45678'))
        data = http_fetch('/mget', dict(items=5))
        assert data == '12345\n23456\n34567\n45678\n'

        # mput GET req
        http_fetch('/mput', dict(data='test1\ntest2\ntest3'))
        data = http_fetch('/get')
        assert data == 'test1'
        data = http_fetch('/get')
        assert data == 'test2'
        data = http_fetch('/get')
        assert data == 'test3'

        # mput POST req
        http_fetch('/mput', body='test1\ntest2\ntest3')
        data = http_fetch('/get')
        assert data == 'test1'
        data = http_fetch('/get')
        assert data == 'test2'
        data = http_fetch('/get')
        assert data == 'test3'
Esempio n. 11
0
    def test_basic(self):
        # put/get in order
        http_fetch("/put", dict(data="12345"))
        http_fetch("/put", dict(data="23456"))
        data = json.loads(http_fetch("/stats", dict(format="json")))
        assert data["depth"] == 2
        assert data["bytes"] == 10
        data = http_fetch("/get")
        assert data == "12345"
        data = http_fetch("/get")
        assert data == "23456"
        data = http_fetch("/get")
        assert data == ""

        data = json.loads(http_fetch("/stats", dict(format="json")))
        assert data["depth"] == 0
        assert data["bytes"] == 0

        # mget
        http_fetch("/put", dict(data="12345"))
        http_fetch("/put", dict(data="23456"))
        http_fetch("/put", dict(data="34567"))
        http_fetch("/put", dict(data="45678"))
        data = http_fetch("/mget", dict(items=5))
        assert data == "12345\n23456\n34567\n45678\n"

        # mput GET req
        http_fetch("/mput", dict(data="test1\ntest2\ntest3"))
        data = http_fetch("/get")
        assert data == "test1"
        data = http_fetch("/get")
        assert data == "test2"
        data = http_fetch("/get")
        assert data == "test3"

        # mput POST req
        http_fetch("/mput", body="test1\ntest2\ntest3")
        data = http_fetch("/get")
        assert data == "test1"
        data = http_fetch("/get")
        assert data == "test2"
        data = http_fetch("/get")
        assert data == "test3"
Esempio n. 12
0
 def test_missing(self):
     http_fetch_json("/put", dict(), 400, "MISSING_ARG_KEY")
     http_fetch_json("/put", dict(key="test_missing"), 400, "MISSING_ARG_VALUE")
     http_fetch_json("/get", dict(), 400, "MISSING_ARG_KEY")
     http_fetch_json("/del", dict(), 400, "MISSING_ARG_KEY")
     http_fetch_json("/fwmatch", dict(), 400, "MISSING_ARG_KEY")
     http_fetch("/put", dict(format="txt"), 400)
     http_fetch("/put", dict(format="txt", key="test_missing"), 400)
     http_fetch("/get", dict(format="txt"), 400)
     http_fetch("/del", dict(format="txt"), 400)
     http_fetch_json("/get", dict(key="test_missing", separator="asdf"), 400, "INVALID_SEPARATOR")
     http_fetch_json("/get", dict(key="test_missing", separator=""), 400, "INVALID_SEPARATOR")
     http_fetch("/get", dict(format="txt", key="test_missing", separator=""), 400)
     http_fetch_json("/mput", dict(), 400, "MISSING_ARG_VALUE", body=".")
     http_fetch_json("/mput", dict(), 400, "MALFORMED_CSV", body="vvvvvvvvvv")
     http_fetch_json("/mput", dict(separator="|"), 400, "MALFORMED_CSV", body="test_missing,val1\n")
     http_fetch_json("/mget", dict(separator=";;"), 400, "INVALID_SEPARATOR")
     http_fetch_json("/mget", dict(), 400, "MISSING_ARG_KEY")
     http_fetch("/mget", dict(format="txt"), 400)
     http_fetch_json("/fwmatch", dict(), 400, "MISSING_ARG_KEY")
     http_fetch_json("/range_match", dict(), 400, "MISSING_ARG_KEY")
     http_fetch_json("/range_match", dict(start="a"), 400, "MISSING_ARG_KEY")
     http_fetch_json("/range_match", dict(end="b"), 400, "MISSING_ARG_KEY")
     http_fetch_json("/range_match", dict(start="b", end="a"), 400, "INVALID_START_KEY")
Esempio n. 13
0
    def test_basic(self):
        # put/get in order
        http_fetch('/put', dict(data='12345'))
        http_fetch('/put', dict(data='23456'))
        data = json.loads(http_fetch('/stats', dict(format="json")))
        assert data['depth'] == 2
        assert data['bytes'] == 10
        data = http_fetch('/get')
        assert data == "12345"
        data = http_fetch('/get')
        assert data == "23456"
        data = http_fetch('/get')
        assert data == ''

        data = json.loads(http_fetch('/stats', dict(format="json")))
        assert data['depth'] == 0
        assert data['bytes'] == 0
        
        # mget
        http_fetch('/put', dict(data='12345'))
        http_fetch('/put', dict(data='23456'))
        http_fetch('/put', dict(data='34567'))
        http_fetch('/put', dict(data='45678'))
        data = http_fetch('/mget', dict(items=5))
        assert data == '12345\n23456\n34567\n45678\n'
        
        # mput GET req
        http_fetch('/mput', dict(data='test1\ntest2\ntest3'))
        data = http_fetch('/get')
        assert data == 'test1'
        data = http_fetch('/get')
        assert data == 'test2'
        data = http_fetch('/get')
        assert data == 'test3'

        # mput POST req
        http_fetch('/mput', body='test1\ntest2\ntest3')
        data = http_fetch('/get')
        assert data == 'test1'
        data = http_fetch('/get')
        assert data == 'test2'
        data = http_fetch('/get')
        assert data == 'test3'
 def test_missing(self):
     http_fetch_json("/put", dict(), 400, 'MISSING_ARG_KEY')
     http_fetch_json("/put", dict(key='test_missing'), 400,
                     'MISSING_ARG_VALUE')
     http_fetch_json("/get", dict(), 400, 'MISSING_ARG_KEY')
     http_fetch_json("/del", dict(), 400, 'MISSING_ARG_KEY')
     http_fetch_json("/fwmatch", dict(), 400, 'MISSING_ARG_KEY')
     http_fetch("/put", dict(format="txt"), 400)
     http_fetch("/put", dict(format='txt', key='test_missing'), 400)
     http_fetch("/get", dict(format='txt'), 400)
     http_fetch("/del", dict(format='txt'), 400)
     http_fetch_json("/get", dict(key="test_missing", separator="asdf"),
                     400, 'INVALID_SEPARATOR')
     http_fetch_json("/get", dict(key="test_missing", separator=""), 400,
                     'INVALID_SEPARATOR')
     http_fetch("/get", dict(format="txt", key="test_missing",
                             separator=""), 400)
     http_fetch_json('/mput', dict(), 400, 'MISSING_ARG_VALUE', body='.')
     http_fetch_json('/mput',
                     dict(),
                     400,
                     'MALFORMED_CSV',
                     body='vvvvvvvvvv')
     http_fetch_json('/mput',
                     dict(separator='|'),
                     400,
                     'MALFORMED_CSV',
                     body='test_missing,val1\n')
     http_fetch_json('/mget', dict(separator=';;'), 400,
                     'INVALID_SEPARATOR')
     http_fetch_json('/mget', dict(), 400, 'MISSING_ARG_KEY')
     http_fetch('/mget', dict(format="txt"), 400)
     http_fetch_json('/fwmatch', dict(), 400, 'MISSING_ARG_KEY')
     http_fetch_json('/range_match', dict(), 400, 'MISSING_ARG_KEY')
     http_fetch_json('/range_match', dict(start="a"), 400,
                     'MISSING_ARG_KEY')
     http_fetch_json('/range_match', dict(end="b"), 400, 'MISSING_ARG_KEY')
     http_fetch_json('/range_match', dict(start="b", end="a"), 400,
                     'INVALID_START_KEY')