diff restful api result
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 28/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- python
- Domain
- api, testing-qa
Research direction
Start with the Python example in the issue, especially diff_api_service_resullt and the main entry point. Review how it submits requests to the test and expected hosts, writes JSON responses, and generates an HTML diff report; done means the two API versions can be compared and differences are reported reliably.
Written by the indexing model from the issue text.
Description
Case:
Need to compare different version of restful api to check if the result are identical.
-*- coding: utf-8
import os
import json
import requests
import traceback
try:
from urlparse import urlparse
except:
# Python 3x:
from urllib.parse import urlparse
test_api_host="xxx-test.com"
expected_api_host="xxx.com"
def generat_output_json_path(imageUrl, apiName, fileNamePostfix):
# it should not occur
if not imageUrl:
return "null_image_url.json"
path = urlparse(imageUrl).path
relative_url = path.lstrip("/").replace("/","_") + fileNamePostfix + ".json"
output_folder = "output/" + apiName.lower()
if not os.path.exists(output_folder):
os.makedirs(output_folder)
return output_folder + "/" + relative_url
def request_url_with_json(http_path, json):
headers = {"Content-Type": "application/json", "x-sdk-invoke-type":"common", "Accept":"application/json", "PK":"123456789"}
response = requests.post(http_path, data=json, headers=headers)
return response.json()
def submit_request_to_url(serviceUrl, serviceUrlPostfix, imageUrl, jsonTemplateFile):
if serviceUrl and not serviceUrl.startswith("http"):
serviceUrl = "http://" + serviceUrl
request_image_url = imageUrl
request_json_template = open(jsonTemplateFile).read()
request_json = request_json_template.replace("$IMAGE_URL", request_image_url)
response = None
httpCode = None
status = ""
message = ""
try:
response = request_url_with_json(serviceUrl + serviceUrlPostfix, request_json)
if not response:
print("Error request url: %s" % serviceUrl + serviceUrlPostfix)
return None
## ignore fields:
if "request_id" in response:
del response["request_id"]
except:
# printing stack trace
traceback.print_exc()
return response
def diff_api_service_resullt(serviceUrlPostfix, imageUrl, jsonTemplateFile):
test_api_response = submit_request_to_url(test_api_host, serviceUrlPostfix, imageUrl, jsonTemplateFile)
expected_api_response = submit_request_to_url(expected_api_host, serviceUrlPostfix, imageUrl, jsonTemplateFile)
test_json_file = generat_output_json_path(url, "detect", "_test")
expected_json_file = generat_output_json_path(url, "detect", "_expected")
diff_output_file = generat_output_json_path(url, "detect", "_diff")
outfile = open(test_json_file,"w")
output_json = json.dumps(test_api_response, indent=4, sort_keys=True, ensure_ascii=False)
outfile.write(output_json)
outfile.close()
outfile = open(expected_json_file,"w")
expected_json = json.dumps(expected_api_response, indent=4, sort_keys=True, ensure_ascii=False)
outfile.write(expected_json)
outfile.close()
if not expected_json == output_json:
# 保存差异到 diff 文件
cmd = "python3 ./diff2html %s %s" % (test_json_file, expected_json_file)
print("executing: %s" % cmd)
diff_stdout = os.popen(cmd, "r")
diff_output = diff_stdout.readlines()
diff_outputfile_path = "./report/" + diff_output_file.replace("/","_") + ".html"
dirname = os.path.dirname(diff_outputfile_path)
if not os.path.exists(dirname):
os.makedirs(dirname)
diff_outfile = open(diff_outputfile_path,"w")
diff_outfile.write("".join(diff_output))
diff_outfile.close()
diff_stdout.close()
if __name__ == "__main__":
url = "https://www.demo.com/a.jpeg"
diff_api_service_resullt("/api/face/detect", url, "./input/detect.json")
- Dominant language
- Python
- Stars
- 5
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from davideuler/programming-tips
-
Difficulty 2/5 1-3 hours Newbie friendliness 35/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 35/100
-
Difficulty 1/5 Under an hour Newbie friendliness 35/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 45/100
-
build milvus on MacOpen
Difficulty 3/5 1-2 days Newbie friendliness 35/100
All issues in davideuler/programming-tips
Similar issues
-
bug needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
debpalash/VoiceStudio#2624 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Make Catch2 optional when `RDK_BUILD_CPP_TESTS=OFF`Possibly taken @pechersky claimed this today. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 2 days
-
There are a few redundant calls to `fdesc._setCloseOnExec()`Possibly taken @gudnimg claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day