This is the 14th day of my participation in the November Gwen Challenge. Check out the event details: The last Gwen Challenge 2021

Hello ~ I’m Milo! I am building an open source interface testing platform from 0 to 1, and I am also writing a complete tutorial corresponding to it. I hope you can support it. Welcome to pay attention to my public number test development pit goods, get the latest article tutorial!

review

In the previous section, we wrote test plan-related functionality. Since our data constructors (preconditions) are still a bit incomplete, we’ll start working on redis for a while.

If we regard Redis as a database, we also need to write the corresponding connection configuration page, after writing we need access to the preconditions, but also to be able to execute the redis command online on the page. These will be the tasks for the next few days.

Design the Redis configuration table

Redis and mysql are similar in some ways:

  • host

  • port

  • username

  • password

  • database

    In Redis, it is a piece of DB, usually 0-15. Mysql is a concrete library.

    Otherwise, the differences are small. Mainly present:

  • Redis is divided into cluster mode and singleton mode, the cluster can not enter the user password

  • Generally, redis connection string will combine host and port together to facilitate our cluster management

    So in summary, we can basically copy the MySQL configuration table.

from sqlalchemy import Column, INT, String, Boolean, UniqueConstraint

from app.models.basic import PityBase


class PityRedis(PityBase) :
    __tablename__ = "pity_redis_info"
    __table_args__ = (
        UniqueConstraint('env'.'name'.'deleted_at'),
    )

    env = Column(INT, nullable=False)  # Indicates the environment ID
    name = Column(String(24), nullable=False)  # redis description name
    addr = Column(String(128), nullable=False)
    username = Column(String(36), nullable=False)
    password = Column(String(64), nullable=False)
    db = Column(INT, nullable=False)
    The default value is false
    cluster = Column(Boolean, default=False, nullable=False)

    def __init__(self, env, name, addr, username, password, db, cluster, user) :
        super().__init__(user)
        self.env = env
        self.name = name
        self.addr = addr
        self.password = password
        self.username = username
        self.db = db
        self.cluster = cluster

Copy the code

As you can see, it’s almost like MySQL. Then we write add, delete, change and check interface according to management.

Write the Dao layer

In fact, as usual, I probably copied the code from dbConfigdao.py and changed it.

But I am not going to do so this time, because in fact, every time I write the code, although not exactly the same, but very similar ah!!

So if there was a way to omit these operations, a back-end interface could be written pretty quickly

For us such a simple interface test platform, is twice the result with half the effort.


In fact, the idea comes from Mybatis Plus, the advantage of this framework is to encapsulate the selectList, selectById and other commonly used API, resulting in brothers do not need to write specific select method, directly pass in the query conditions can be.

Update is even more outrageous, passing in a new object.

Therefore, it can be seen that the specific Mapper is inherited from BaseMapper, and the corresponding operations can be completed.

Maybe you don’t have a specific concept, let me show you the next semi-finished product:

use

As you can see, if you want an exact lookup, you pass it in, and if you want a fuzzy query, you add like.

It looks very nice, interested friends can test it.

That’s it for today, and in the next section we’ll continue to refine the methods in the Mapper base class and implement a full demo to simplify development.

Although the idea is original, it is hard to avoid meeting with others. In fact, the idea of the test platform we do is generally the same, so if we encounter a high degree of similarity, it is really pure coincidence.