Ejemplo n.º 1
0
    def test_cachemgr(self):
        """test cacher server functionality"""
        headers = {"Accept": "application/json"}
        query = "ip=137.138.141.145 | grep ip.City"
        idx = 0
        limit = 10
        expire = 60
        params = {'query': query, 'idx': idx, 'limit': limit, 'expire': expire}
        host = 'http://localhost:8211'

        # delete query
        request = 'DELETE'
        path = '/rest/delete'
        try:
            data = urllib2_request(request, host + path, params)
            expect = {"status": "success"}
            result = json.loads(data)
            self.assertEqual(expect["status"], result["status"])
        except urllib2.URLError as exp:
            pass

        # post request
        headers = {
            "Accept": "application/json",
            "Content-type": "application/json"
        }
        request = 'POST'
        path = '/rest/create'
        try:
            data = urllib2_request(request, host + path, params, headers)
            expect = {"status": "requested", "query": query, "expire": expire}
            result = json.loads(data)
            self.assertEqual(expect["status"], result["status"])
        except urllib2.URLError as exp:
            pass

        # get data
        request = 'GET'
        path = '/rest/request'
        try:
            data = urllib2_request(request, host + path, params)
            expect = {"status": "success"}
            result = json.loads(data)
            self.assertEqual(expect["status"], result["status"])
        except urllib2.URLError as exp:
            pass
Ejemplo n.º 2
0
    def test_cachemgr(self):
        """test cacher server functionality"""
        headers = {"Accept": "application/json"}
        query   = "ip=137.138.141.145 | grep ip.City"
        idx     = 0
        limit   = 10
        expire  = 60
        params  = {'query':query, 'idx':idx, 'limit':limit, 'expire':expire}
        host    = 'http://localhost:8211'

        # delete query
        request = 'DELETE'
        path    = '/rest/delete'
        try:
            data    = urllib2_request(request, host+path, params)
            expect  = {"status":"success"}
            result  = json.loads(data)
            self.assertEqual(expect["status"], result["status"])
        except URLError as exp:
            pass
        
        # post request
        headers = {"Accept": "application/json", "Content-type": "application/json"}
        request = 'POST'
        path    = '/rest/create'
        try:
            data    = urllib2_request(request, host+path, params, headers)
            expect  = {"status": "requested", "query": query, "expire":expire}
            result  = json.loads(data)
            self.assertEqual(expect["status"], result["status"])
        except URLError as exp:
            pass

        # get data
        request = 'GET'
        path    = '/rest/request'
        try:
            data    = urllib2_request(request, host+path, params)
            expect  = {"status": "success"}
            result  = json.loads(data)
            self.assertEqual(expect["status"], result["status"])
        except URLError as exp:
            pass
Ejemplo n.º 3
0
            pass
        
        # post request
        headers = {"Accept": "application/json", "Content-type": "application/json"}
        request = 'POST'
        path    = '/rest/create'
        try:
            data    = urllib2_request(request, host+path, params, headers)
            expect  = {"status": "requested", "query": query, "expire":expire}
            result  = json.loads(data)
            self.assertEqual(expect["status"], result["status"])
        except URLError, exp:
            pass

        # get data
        request = 'GET'
        path    = '/rest/request'
        try:
            data    = urllib2_request(request, host+path, params)
            expect  = {"status": "success"}
            result  = json.loads(data)
            self.assertEqual(expect["status"], result["status"])
        except URLError, exp:
            pass

#
# main
#
if __name__ == '__main__':
    unittest.main()