import os,sys,shutil import httplib2 # import simplejson, even though it uses the deprecated sre module import warnings warnings.filterwarnings('ignore', category=DeprecationWarning) from simplejson import dumps as tojson, loads as fromjson warnings.filterwarnings('default', category=DeprecationWarning) db = sys.argv[1] + "test_suite_db/" id = db + "test_doc" # create two empty caches if os.path.exists(".cache1"): shutil.rmtree(".cache1") if os.path.exists(".cache2"): shutil.rmtree(".cache2") http1 = httplib2.Http(".cache1") http2 = httplib2.Http(".cache2") # create a database http1.request(db, 'DELETE') response, content = http1.request(db, 'PUT') assert response['status'] == '201' # create a document doc = {"hello": "world"} response, content = http1.request(id, 'PUT', tojson(doc)) assert response['status'] == '201' # fetch into cache1 response, content = http1.request(id, 'GET') assert response['status'] == '200' doc1 = fromjson(content) # fetch into cache2 response, content = http2.request(id, 'GET') assert response['status'] == '200' doc2 = fromjson(content) # verify that the cache is current response, content = http2.request(id, 'GET') assert response['status'] == '304' # update, first from cache1 doc1["hello"] += "!" response, content = http1.request(id, 'PUT', tojson(doc1)) assert response['status'] == '201' # now attempt to do the same from cache2 doc1["hello"] += "?" response, content = http2.request(id, 'PUT', tojson(doc2)) assert response['status'] == '409' # Note: this should be 412 per # clean up if os.path.exists(".cache1"): shutil.rmtree(".cache1") if os.path.exists(".cache2"): shutil.rmtree(".cache2") print "Test Passed."