This is the 23rd 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 last video, we made a cache using Redis. But there are problems with it, and I’ll talk about that.

Let’s implement the simplest email notification function.

The results show

To apply for a mailbox

My email is precious. Don’t use it. You can apply for email 126 or 163 and enable POP3/SMTP.

Generally in the mailbox -> Settings, see POP3/SMTP click in there will be guidance.

Because you can’t just use a password.

Write the Notification Notification class

This notification class is actually a dummy class and an abstract class. Because there are many ways of notification, including email, SMS, nail, enterprise wechat, flying books and so on. So we give him an empty shell and implement the specific method when it comes to the specific email or something.

Unified acceptance of subject, content, attachment, email, recipient.

Write a method to get mailboxes in batches by userId

Since we store user ids in the receiver field of the test plan, we need to convert:

Have you found a problem, when the user is not fixed (test plan recipients will not always be fixed), if we give it a cache method, then other test plan execution will fetch the data of the dead key, this is not reasonable!!

So the cache we wrote for fixed arguments doesn’t work well for mutable arguments because your key has to follow it.

This is the disadvantage I mentioned above

Write Email

import yagmail

from app.core.configuration import SystemConfiguration
from app.core.msg.notification import Notification


class Email(Notification) :

    @staticmethod
    def get_mail_client() :
        configuration = SystemConfiguration.get_config()
        data = configuration.get("email")
        return yagmail.SMTP(user=data.get("sender"), password=data.get("password"), host=data.get("host"))

    @staticmethod
    def send_msg(subject, content, attachment=None, *receiver) :
        client = Email.get_mail_client()
        client.send(receiver, subject=subject, contents=content, attachments=attachment)

Copy the code

First get the data from the configuration, then call the YagMail library, get the mail client, and finally send the mail according to the incoming subject, message content and other information.

Complete the test plan notification section

We get the message type, if there is an email type, we get the user’s mailbox. Then call the send_msg method.

But there is a very serious problem here. We can only get the information of the test plan, but not the detailed data of the test report.

In this way, we don’t even know whether the report is right or wrong. We write down a title and content first.

Then run the test plan, and the end result looks like the beginning of this article. So I immediately deleted the damn test plan.

Therefore, we still need to improve the content of the email in the future. This content has a lot of work, so we may not be able to perfect it. We may need to pay attention to putting a link of test result + test report.

As for what the next lecture is about, I’m a little stiff. We’ll see later