X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Ftest%2Fresources%2Fhttp-cache%2Fthird_party_proxy.py;fp=src%2Ftest%2Fresources%2Fhttp-cache%2Fthird_party_proxy.py;h=5432ab8e563380873f6deab85e1ce68c6879ff87;hb=c76aea9d08f82651783d0f2cc76c4152c0be9d7b;hp=0db977bb432d85e2ad637a068af73a430a24129f;hpb=60d8a197a65db5b53bae5ea6950cb9af559b643f;p=clamp.git diff --git a/src/test/resources/http-cache/third_party_proxy.py b/src/test/resources/http-cache/third_party_proxy.py index 0db977bb..5432ab8e 100755 --- a/src/test/resources/http-cache/third_party_proxy.py +++ b/src/test/resources/http-cache/third_party_proxy.py @@ -180,7 +180,7 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler): with open(cached_file_content, 'w+') as f: f.write(self.data_string) return True - elif self.path.startswith("/policy/api/v1/policyTypes/") and http_type == "POST": + elif self.path.startswith("/policy/api/v1/policytypes/") and http_type == "POST": print "self.path start with POST new policy API /pdp/api/, copying body to response ..." if not os.path.exists(cached_file_folder): os.makedirs(cached_file_folder, 0777) @@ -189,8 +189,8 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler): with open(cached_file_content, 'w+') as f: f.write(self.data_string) return True - elif self.path.startswith("/policy/api/v1/policyTypes/") and http_type == "DELETE": - print "self.path start with DELETE new policy API /policy/api/v1/policyTypes/ ..." + elif self.path.startswith("/policy/api/v1/policytypes/") and http_type == "DELETE": + print "self.path start with DELETE new policy API /policy/api/v1/policytypes/ ..." if not os.path.exists(cached_file_folder): os.makedirs(cached_file_folder, 0777) @@ -199,6 +199,15 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler): with open(cached_file_content, 'w+') as f: f.write(self.data_string) return True + elif self.path.startswith("/policy/pap/v1/pdps/policies") and http_type == "POST": + print "self.path start with POST new policy API /policy/pap/v1/pdps/ ..." + if not os.path.exists(cached_file_folder): + os.makedirs(cached_file_folder, 0777) + with open(cached_file_header, 'w+') as f: + f.write("{\"Content-Length\": \"" + str(len("")) + "\", \"Content-Type\": \""+str("")+"\"}") + with open(cached_file_content, 'w+') as f: + f.write(self.data_string) + return True elif self.path.startswith("/policy/api/v1/policytypes/") and http_type == "GET": print "self.path start with /policy/api/v1/policytypes/, generating response json..." jsonGenerated = "{\"policyTypeId\": \"onap.policies.controlloop.operational\",\"policyTypeVersion\": \"1.0.0\",\"policyId\": \"OPERATIONAL_z711F_v1_0_ResourceInstanceName1_tca\"}" @@ -241,7 +250,9 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler): if not HOST: self.send_response(404) - return "404 Not found" + self.end_headers() + self.wfile.write('404 Not found, no remote HOST specified on the emulator !!!') + return "404 Not found, no remote HOST specified on the emulator !!!" url = '%s%s' % (HOST, self.path) response = requests.get(url, auth=AUTH, headers=HEADERS, stream=True) @@ -254,6 +265,8 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler): print('Status code : %s' % (response.status_code,)) print('Content : %s' % (response.content,)) self.send_response(response.status_code) + self.end_headers() + self.wfile.write('404 Not found, nothing found on the remote server !!!') return response.content else: print("Request for data currently present in cache: %s" % (cached_file_folder,)) @@ -292,7 +305,9 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler): if not HOST: self.send_response(404) - return "404 Not found" + self.end_headers() + self.wfile.write('404 Not found, no remote HOST specified on the emulator !!!') + return "404 Not found, no remote HOST specified on the emulator !!!" print("Request for data currently not present in cache: %s" % (cached_file_folder,)) @@ -308,6 +323,8 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler): print('Status code : %s' % (response.status_code,)) print('Content : %s' % (response.content,)) self.send_response(response.status_code) + self.end_headers() + self.wfile.write('404 Not found, nothing found on the remote server !!!') return response.content else: print("Request for data present in cache: %s" % (cached_file_folder,)) @@ -339,7 +356,9 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler): if not _file_available: if not HOST: self.send_response(404) - return "404 Not found" + self.end_headers() + self.wfile.write('404 Not found, no remote HOST specified on the emulator !!!') + return "404 Not found, no remote HOST specified on the emulator !!!" print("Request for data currently not present in cache: %s" % (cached_file_folder,)) @@ -355,6 +374,8 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler): print('Status code : %s' % (response.status_code,)) print('Content : %s' % (response.content,)) self.send_response(response.status_code) + self.end_headers() + self.wfile.write('404 Not found, nothing found on the remote server !!!') return response.content else: print("Request for data present in cache: %s" % (cached_file_folder,)) @@ -389,7 +410,9 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler): if not _file_available: if not HOST: self.send_response(404) - return "404 Not found" + self.end_headers() + self.wfile.write('404 Not found, no remote HOST specified on the emulator !!!') + return "404 Not found, no remote HOST specified on the emulator !!!" print("Request for data currently not present in cache: %s" % (cached_file_folder,)) @@ -405,6 +428,8 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler): print('Status code : %s' % (response.status_code,)) print('Content : %s' % (response.content,)) self.send_response(response.status_code) + self.end_headers() + self.wfile.write('404 Not found, nothing found on the remote server !!!') return response.content else: print("Request for data present in cache: %s" % (cached_file_folder,))