在 Postman 上测试 JSON 中的大型响应

问题描述

我在 Postman 上有一个正文回复,为我返回了这个:

[
{
    "key": "Dateline Standard Time","value": "(UTC-12:00) International Date Line West"
},{
    "key": "UTC-11","value": "(UTC-11:00) Coordinated Universal Time-11"
},{
    "key": "Aleutian Standard Time","value": "(UTC-10:00) Aleutian Islands"
}]

那么,在“测试”选项卡内,我应该写什么来测试响应是否完全相同?

我尝试过这样的事情:

    pm.test("Body is correct",function(){
      pm.response.to.have.body("
     [
    {
        "key": "Dateline Standard Time","value": "(UTC-12:00) International Date Line West"
    },{
        "key": "UTC-11","value": "(UTC-11:00) Coordinated Universal Time-11"
    },{
        "key": "Aleutian Standard Time","value": "(UTC-10:00) Aleutian Islands"
    }]
    ");

但还是不行。

谢谢!

解决方法

#! python3
# Takes multiple text files as CLI arguments and writes
# each line to consecutive rows in a column
import openpyxl
import sys

# Open a blank workbook to populate.
wb = openpyxl.Workbook()
sheet = wb.active

# Loop through the text files.
for arg in range(1,len(sys.argv)):
    text_file = open(sys.argv[arg],'r')
    text = text_file.readlines()
    for line in range(len(text)):
        sheet.cell(row=line+1,column=arg,value=text[line])

# Write spreadsheet file
wb.save('text_to_spreadsheet.xlsx')
print('DONE')`

使用深度相等