review

In the last section we wrote a prototype of the use-case tree, but the actual use-case page has not been written yet, and the progress has been even slower since I stopped for a few days.

But before we do that, let’s change the global configuration of ANTD Pro, that is: fonts.

Change the font

< span style = “font-size: 14px” style = “box-sizing: border-box; color: RGB (50, 50, 50); line-height: 22px; font-size: 14px; white-space: normal; white-space: normal; word-break: break-all;

Write the back-end portion of the use case

Write parameter verification method

Before that, we need to add a decorator to verify the parameters. We are not going to use pydantic, we are going to use jsonschema, although I feel the former is better, but I just want to use this interface, frankly, just for fun!

And the reason why we need this method is because we’re going to have too much trouble verifying every parameter on a TestCase object, so I can’t stand it here.

app/utils/decorator.py

If it doesn’t get the json data, it throws an exception. Otherwise, it calls the VALIDATE method of the JsonSchema library, which validates the parameter.

One drawback of this method, however, is that it only validates JSON data, which is true! What if there’s a URL argument, that’s not supported, but I’ll talk about that later, because that’s not what I’m dealing with right now.

pip3 install jsonschema
Copy the code

Don’t forget to install the new library, if you are new, just follow requirements.txt.

Methods for writing new use cases

  • Modify the use-case Model

Since we added directory and priority fields, we need to add these fields to the __init__ method.

  • New insert method

If the project id and name are the same, the use case is considered to exist and the user is not allowed to add further.

Here, the permission restriction is not very strict, and there is no verification whether users can add use cases for the project.

  • Add an interface

    Edit the app/controllers/testcase/testcase. Py

Note that we introduced the jSON_validate decorator, which validates our JSON parameters.

  • The testcase data
testcase = {
    "type": "object"."properties": {
        "id": {
            "type": "integer",},"name": {
            "type": "string",},"request_type": {
            "type": "integer",},"url": {
            "type": "string",},"request_method": {
            "type": "string",},"request_header": {
            "type": "string",},"params": {
            "type": "string",},"body": {
            "type": "string",},"project_id": {
            "type": "integer",},"tag": {
            "type": "string",},"status": {
            "type": "integer",},"priority": {
            "type": "string",},"catalogue": {
            "type": "string",},"expected": {
            "type": "string",}},"required": ["expected"."catalogue"."priority"."status"."project_id"."request_type"."url"."name"]}Copy the code

Json_schema is a string of JSON data structures that describes json data structures. This may be tricky, but as you can see from the diagram:

  • type

    Type is the type of a JSON string, and object is an object. Json is called json because its full name is JavaScript Object Notation. In addition, there are integers, strings and so on.

  • properities

    These are the properties in this object, the fields.

  • required

    An array containing the required fields of the array.

Test the

  • Cut off a required field

Json Schema and control number range validation, I won’t talk about it here, you can look it up if you are interested.

Today’s content is not much, more for fear of indigestion. Someday maybe study Httprunner, after all, this is the industry mainstream project, if appropriate to the compatible bar, so that the platform will be more popular.