Python Interface Test mock (ix)

Source: Internet
Author: User

In the http://www.cnblogs.com/weke/articles/6859021.html, the Mock-server has done

The preliminary introduction, which continues here today to proceed before the introduction, we first look at the previous Mock-server section before writing

A login mock, specific JSON file see the following:

[
  {"
    request":
    {
      "method": "Post",
      "uri": "/login",
      "JSON":
      {
        "username": "admin" , "
        password": "admin",
        "Roleid": "
    }",
    "response":
    {
      "json":
      {
        " Username ":" Wuya ","
        UserID ":"
        token ":" ASDGFHH32456ASFGRSFSS "}}
]

Looking at the above, we can see that such a way is not so friendly, in the UI or interface Automation test, we know

In the mode of TDD, the data is separated, which is also for the convenience of maintenance, for the purpose of the later automation test case extensibility,

And it's easy to maintain, then come down we're going to make a change to the JSON file above, separate the data from the response section and put it

In a file so that we can separate it out, we separate the contents of the response from the Login.json to the Login_response.json

Remember that Login.json and Login_response.json must remain in the same directory, see Login.json content:

[
  {"
    request":
    {
      "method": "Post",
      "uri": "/login",
      "JSON":
      {
        "username": "admin" , "
        password": "admin",
        "Roleid": "
    }",
    "response":
    {
      "file": "Login_ Response.json "
    }
  }
]

See the contents of the Login_response.json file:

{"
  username": "Wuya",
  "UserID": "
  token": "ASDGFHH32456ASFGRSFSS"
}

After executing the Login.json file, access the interface to see if OK, see the command to execute the Login.json file:

Use Postman to view the interface, see whether OK, see the following screenshot:

Below we carry on a business, is to enter a license plate number, inquire the car brand to show the length, and its parking expenses, direct in Loginjson

The document is perfect, see the perfect content:

[
  {"
    request":
    {
      "method": "Post",
      "uri": "/login",
      "JSON":
      {
        "username": "admin" , "
        password": "admin",
        "Roleid": "
    }",
    "response":
    {
      "file": "Login_ Response.json "
    }
  },

  {"
    request ":
    {
      " method ":" Post ",
      " uri ":"/parkinside ",
      "JSON":
      {
        "token": "ASDGFHH32456ASFGRSFSS",
        "VPL": "AJ3585"
      }
    },
    "response":
    {"
      file" : "Parkinside.json"
    }
  }
]

See the contents of the Parkinside.json file:

{"
  vplinfo":
  {"
    UserID": "
    username": "Wuya",
    "VPL":

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.