mirror of
https://github.com/foss42/apidash.git
synced 2025-05-23 09:17:04 +08:00
Update Python requests codegen
This commit is contained in:
@ -26,8 +26,8 @@ print('Response Body:', response.text)
|
||||
url = 'https://api.apidash.dev/country/data'
|
||||
|
||||
params = {
|
||||
"code": "US"
|
||||
}
|
||||
"code": "US"
|
||||
}
|
||||
|
||||
response = requests.get(url, params=params)
|
||||
|
||||
@ -44,8 +44,8 @@ print('Response Body:', response.text)
|
||||
url = 'https://api.apidash.dev/country/data'
|
||||
|
||||
params = {
|
||||
"code": "IND"
|
||||
}
|
||||
"code": "IND"
|
||||
}
|
||||
|
||||
response = requests.get(url, params=params)
|
||||
|
||||
@ -62,12 +62,12 @@ print('Response Body:', response.text)
|
||||
url = 'https://api.apidash.dev/humanize/social'
|
||||
|
||||
params = {
|
||||
"num": "8700000",
|
||||
"digits": "3",
|
||||
"system": "SS",
|
||||
"add_space": "true",
|
||||
"trailing_zeros": "true"
|
||||
}
|
||||
"num": "8700000",
|
||||
"digits": "3",
|
||||
"system": "SS",
|
||||
"add_space": "true",
|
||||
"trailing_zeros": "true"
|
||||
}
|
||||
|
||||
response = requests.get(url, params=params)
|
||||
|
||||
@ -84,8 +84,8 @@ print('Response Body:', response.text)
|
||||
url = 'https://api.github.com/repos/foss42/apidash'
|
||||
|
||||
headers = {
|
||||
"User-Agent": "Test Agent"
|
||||
}
|
||||
"User-Agent": "Test Agent"
|
||||
}
|
||||
|
||||
response = requests.get(url, headers=headers)
|
||||
|
||||
@ -102,12 +102,12 @@ print('Response Body:', response.text)
|
||||
url = 'https://api.github.com/repos/foss42/apidash'
|
||||
|
||||
params = {
|
||||
"raw": "true"
|
||||
}
|
||||
"raw": "true"
|
||||
}
|
||||
|
||||
headers = {
|
||||
"User-Agent": "Test Agent"
|
||||
}
|
||||
"User-Agent": "Test Agent"
|
||||
}
|
||||
|
||||
response = requests.get(url, params=params, headers=headers)
|
||||
|
||||
@ -138,12 +138,12 @@ print('Response Body:', response.text)
|
||||
url = 'https://api.github.com/repos/foss42/apidash'
|
||||
|
||||
params = {
|
||||
"raw": "true"
|
||||
}
|
||||
"raw": "true"
|
||||
}
|
||||
|
||||
headers = {
|
||||
"User-Agent": "Test Agent"
|
||||
}
|
||||
"User-Agent": "Test Agent"
|
||||
}
|
||||
|
||||
response = requests.get(url, params=params, headers=headers)
|
||||
|
||||
@ -160,9 +160,9 @@ print('Response Body:', response.text)
|
||||
url = 'https://api.apidash.dev/humanize/social'
|
||||
|
||||
params = {
|
||||
"num": "8700000",
|
||||
"add_space": "true"
|
||||
}
|
||||
"num": "8700000",
|
||||
"add_space": "true"
|
||||
}
|
||||
|
||||
response = requests.get(url, params=params)
|
||||
|
||||
@ -179,8 +179,8 @@ print('Response Body:', response.text)
|
||||
url = 'https://api.apidash.dev/humanize/social'
|
||||
|
||||
headers = {
|
||||
"User-Agent": "Test Agent"
|
||||
}
|
||||
"User-Agent": "Test Agent"
|
||||
}
|
||||
|
||||
response = requests.get(url, headers=headers)
|
||||
|
||||
@ -201,13 +201,13 @@ print('Response Body:', response.text)
|
||||
url = 'https://api.apidash.dev/humanize/social'
|
||||
|
||||
params = {
|
||||
"num": "8700000",
|
||||
"digits": "3"
|
||||
}
|
||||
"num": "8700000",
|
||||
"digits": "3"
|
||||
}
|
||||
|
||||
headers = {
|
||||
"User-Agent": "Test Agent"
|
||||
}
|
||||
"User-Agent": "Test Agent"
|
||||
}
|
||||
|
||||
response = requests.get(url, params=params, headers=headers)
|
||||
|
||||
@ -274,8 +274,8 @@ payload = r'''{
|
||||
}'''
|
||||
|
||||
headers = {
|
||||
"content-type": "text/plain"
|
||||
}
|
||||
"content-type": "text/plain"
|
||||
}
|
||||
|
||||
response = requests.post(url, data=payload, headers=headers)
|
||||
|
||||
@ -292,7 +292,12 @@ print('Response Body:', response.text)
|
||||
url = 'https://api.apidash.dev/case/lower'
|
||||
|
||||
payload = {
|
||||
"text": "I LOVE Flutter"
|
||||
"text": "I LOVE Flutter",
|
||||
"flag": None,
|
||||
"male": True,
|
||||
"female": False,
|
||||
"no": 1.2,
|
||||
"arr": ["null", "true", "false", None]
|
||||
}
|
||||
|
||||
response = requests.post(url, json=payload)
|
||||
@ -314,8 +319,8 @@ payload = {
|
||||
}
|
||||
|
||||
headers = {
|
||||
"User-Agent": "Test Agent"
|
||||
}
|
||||
"User-Agent": "Test Agent"
|
||||
}
|
||||
|
||||
response = requests.post(url, json=payload, headers=headers)
|
||||
|
||||
@ -325,6 +330,166 @@ print('Response Body:', response.text)
|
||||
expect(pythonRequestsCodeGen.getCode(requestModelPost3, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 4', () {
|
||||
const expectedCode = r"""import requests
|
||||
from requests_toolbelt.multipart.encoder import MultipartEncoder
|
||||
|
||||
url = 'https://api.apidash.dev/io/form'
|
||||
|
||||
payload = MultipartEncoder({
|
||||
"text": "API",
|
||||
"sep": "|",
|
||||
"times": "3",
|
||||
})
|
||||
|
||||
headers = {
|
||||
"content-type": payload.content_type
|
||||
}
|
||||
|
||||
response = requests.post(url, data=payload, headers=headers)
|
||||
|
||||
print('Status Code:', response.status_code)
|
||||
print('Response Body:', response.text)
|
||||
""";
|
||||
expect(pythonRequestsCodeGen.getCode(requestModelPost4, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 5', () {
|
||||
const expectedCode = r"""import requests
|
||||
from requests_toolbelt.multipart.encoder import MultipartEncoder
|
||||
|
||||
url = 'https://api.apidash.dev/io/form'
|
||||
|
||||
payload = MultipartEncoder({
|
||||
"text": "API",
|
||||
"sep": "|",
|
||||
"times": "3",
|
||||
})
|
||||
|
||||
headers = {
|
||||
"User-Agent": "Test Agent",
|
||||
"content-type": payload.content_type
|
||||
}
|
||||
|
||||
response = requests.post(url, data=payload, headers=headers)
|
||||
|
||||
print('Status Code:', response.status_code)
|
||||
print('Response Body:', response.text)
|
||||
""";
|
||||
expect(pythonRequestsCodeGen.getCode(requestModelPost5, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 6', () {
|
||||
const expectedCode = r"""import requests
|
||||
from requests_toolbelt.multipart.encoder import MultipartEncoder
|
||||
|
||||
url = 'https://api.apidash.dev/io/img'
|
||||
|
||||
payload = MultipartEncoder({
|
||||
"token": "xyz",
|
||||
"imfile": ("1.png", open("/Documents/up/1.png", "rb")),
|
||||
})
|
||||
|
||||
headers = {
|
||||
"content-type": payload.content_type
|
||||
}
|
||||
|
||||
response = requests.post(url, data=payload, headers=headers)
|
||||
|
||||
print('Status Code:', response.status_code)
|
||||
print('Response Body:', response.text)
|
||||
""";
|
||||
expect(pythonRequestsCodeGen.getCode(requestModelPost6, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 7', () {
|
||||
const expectedCode = r"""import requests
|
||||
from requests_toolbelt.multipart.encoder import MultipartEncoder
|
||||
|
||||
url = 'https://api.apidash.dev/io/img'
|
||||
|
||||
payload = MultipartEncoder({
|
||||
"token": "xyz",
|
||||
"imfile": ("1.png", open("/Documents/up/1.png", "rb")),
|
||||
})
|
||||
|
||||
headers = {
|
||||
"content-type": payload.content_type
|
||||
}
|
||||
|
||||
response = requests.post(url, data=payload, headers=headers)
|
||||
|
||||
print('Status Code:', response.status_code)
|
||||
print('Response Body:', response.text)
|
||||
""";
|
||||
expect(pythonRequestsCodeGen.getCode(requestModelPost7, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 8', () {
|
||||
const expectedCode = r"""import requests
|
||||
from requests_toolbelt.multipart.encoder import MultipartEncoder
|
||||
|
||||
url = 'https://api.apidash.dev/io/form'
|
||||
|
||||
params = {
|
||||
"size": "2",
|
||||
"len": "3"
|
||||
}
|
||||
|
||||
payload = MultipartEncoder({
|
||||
"text": "API",
|
||||
"sep": "|",
|
||||
"times": "3",
|
||||
})
|
||||
|
||||
headers = {
|
||||
"content-type": payload.content_type
|
||||
}
|
||||
|
||||
response = requests.post(url, params=params, data=payload, headers=headers)
|
||||
|
||||
print('Status Code:', response.status_code)
|
||||
print('Response Body:', response.text)
|
||||
""";
|
||||
expect(pythonRequestsCodeGen.getCode(requestModelPost8, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
|
||||
test('POST 9', () {
|
||||
const expectedCode = r"""import requests
|
||||
from requests_toolbelt.multipart.encoder import MultipartEncoder
|
||||
|
||||
url = 'https://api.apidash.dev/io/img'
|
||||
|
||||
params = {
|
||||
"size": "2",
|
||||
"len": "3"
|
||||
}
|
||||
|
||||
payload = MultipartEncoder({
|
||||
"token": "xyz",
|
||||
"imfile": ("1.png", open("/Documents/up/1.png", "rb")),
|
||||
})
|
||||
|
||||
headers = {
|
||||
"User-Agent": "Test Agent",
|
||||
"Keep-Alive": "true",
|
||||
"content-type": payload.content_type
|
||||
}
|
||||
|
||||
response = requests.post(url, params=params, data=payload, headers=headers)
|
||||
|
||||
print('Status Code:', response.status_code)
|
||||
print('Response Body:', response.text)
|
||||
""";
|
||||
expect(pythonRequestsCodeGen.getCode(requestModelPost9, "https"),
|
||||
expectedCode);
|
||||
});
|
||||
});
|
||||
|
||||
group('PUT Request', () {
|
||||
|
Reference in New Issue
Block a user