From c1c49ce51d25138a94a41a23452e078a660f1248 Mon Sep 17 00:00:00 2001 From: Andrew Lewis Date: Wed, 3 Aug 2016 11:38:45 +0100 Subject: [Test] Some basic tests for JSON sanity --- test/functional/lib/rspamd.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'test/functional/lib/rspamd.py') diff --git a/test/functional/lib/rspamd.py b/test/functional/lib/rspamd.py index c40ac588c..4da8712a3 100644 --- a/test/functional/lib/rspamd.py +++ b/test/functional/lib/rspamd.py @@ -1,3 +1,4 @@ +import demjson import grp import os import os.path @@ -17,6 +18,16 @@ try: from urllib.request import urlopen except: from urllib2 import urlopen +try: + import http.client as httplib +except: + import httplib + +def Check_JSON(j): + d = demjson.decode(j, strict=True) + assert len(d) > 0 + assert 'error' not in d + return d def cleanup_temporary_directory(directory): shutil.rmtree(directory) @@ -49,6 +60,15 @@ def get_rspamadm(): dname = get_top_dir() return dname + "/src/rspamadm/rspamadm" +def HTTP(method, host, port, path, data=None, headers={}): + c = httplib.HTTPConnection("%s:%s" % (host, port)) + c.request(method, path, data, headers) + r = c.getresponse() + t = r.read() + s = r.status + c.close() + return [s, t] + def make_temporary_directory(): return tempfile.mkdtemp() -- cgit v1.2.3