Beispiel #1
0
 def test_search_by_sent_to(self):
     target_email = self.emails[1]
     criteria = SearchCriteria()
     criteria.sent_to = target_email.to[0].email
     results = self.client.messages.search(self.server, criteria).items
     self.assertEqual(1, len(results))
     self.assertEqual(target_email.to[0].email, results[0].to[0].email)
     self.assertEqual(target_email.subject, results[0].subject)
Beispiel #2
0
 def test_search_timeout_errors_suppressed(self):
     criteria = SearchCriteria()
     criteria.sent_from = "*****@*****.**"
     results = self.client.messages.search(self.server,
                                           criteria,
                                           timeout=1,
                                           error_on_timeout=False).items
     self.assertEqual(0, len(results))
Beispiel #3
0
 def test_search_by_subject(self):
     target_email = self.emails[1]
     unique_string = target_email.subject[0:10]
     criteria = SearchCriteria()
     criteria.subject = unique_string
     results = self.client.messages.search(self.server, criteria).items
     self.assertEqual(1, len(results))
     self.assertEqual(target_email.to[0].email, results[0].to[0].email)
     self.assertEqual(target_email.subject, results[0].subject)
Beispiel #4
0
 def test_search_with_match_any(self):
     target_email = self.emails[1]
     unique_string = target_email.subject[0:10]
     criteria = SearchCriteria()
     criteria.subject = unique_string
     criteria.body = "this is a link"
     criteria.match = "ANY"
     results = self.client.messages.search(self.server, criteria).items
     self.assertEqual(4, len(results))
Beispiel #5
0
    def test_get(self):
        host = os.getenv('MAILOSAUR_SMTP_HOST', 'mailosaur.io')
        test_email_address = "wait_for_test.%s@%s" % (self.server, host)

        Mailer.send_email(self.client, self.server, test_email_address)

        criteria = SearchCriteria()
        criteria.sent_to = test_email_address
        email = self.client.messages.get(self.server, criteria)
        self.validate_email(email)
    def setUpClass(cls):
        api_key = os.getenv('MAILOSAUR_API_KEY')
        base_url = os.getenv('MAILOSAUR_BASE_URL')
        cls.server = os.getenv('MAILOSAUR_SERVER')

        if (api_key or cls.server) is None:
            raise Exception(
                "Missing necessary environment variables - refer to README.md")

        cls.client = MailosaurClient(api_key, base_url)

        cls.client.messages.delete_all(cls.server)

        host = os.getenv('MAILOSAUR_SMTP_HOST', 'mailosaur.io')
        test_email_address = "files_test.%s@%s" % (cls.server, host)

        Mailer.send_email(cls.client, cls.server, test_email_address)

        criteria = SearchCriteria()
        criteria.sent_to = test_email_address
        cls.email = cls.client.messages.get(cls.server, criteria)
def check_emails_arrives(customer_email, recipient_email):
    # Build search criteria to find the email you have sent
    criteria_for_customer = SearchCriteria()
    criteria_for_recipient = SearchCriteria()

    criteria_for_customer.sent_to = customer_email
    criteria_for_recipient.sent_to = recipient_email

    # Wait for the message (by default only looks for messages received in the last hour)
    # prvnbtvf is the mailing server name for the costumer emails
    # ylz3dti2 is the mailing server name for the recipient emails
    test_email = client.messages.get("prvnbtvf", criteria_for_customer)
    test_email_recipient = client.messages.get("ylz3dti2",
                                               criteria_for_recipient)

    # Wait for the email to be arrived
    sleep(10)

    # Assert that the email subject is what we expect
    logging.info("Receipt email subject: " + test_email.subject)
    logging.info("Gift card email subject: " + test_email_recipient.subject)
    assert "Your Receipt for Arden Courts" == test_email.subject
    assert "You've been sent a $256 gift card for Demo US!" == test_email_recipient.subject
Beispiel #8
0
 def find_email(self, server_id, email_address):
     criteria = SearchCriteria()
     criteria.sent_to = email_address
     return self.client.messages.get(server_id, criteria)
Beispiel #9
0
    def test_search_by_sent_to_invalid_email(self):
        criteria = SearchCriteria()
        criteria.sent_to = ".not_an_email_address"

        with self.assertRaises(MailosaurException):
            self.client.messages.search(self.server, criteria)
Beispiel #10
0
 def test_search_no_criteria_error(self):
     with self.assertRaises(MailosaurException):
         self.client.messages.search(self.server, SearchCriteria())
Beispiel #11
0
 def test_search_with_special_characters(self):
     criteria = SearchCriteria()
     criteria.subject = "Search with ellipsis … and emoji 👨🏿‍🚒"
     results = self.client.messages.search(self.server, criteria).items
     self.assertEqual(0, len(results))
def read_email(email):
    client = MailosaurClient(API_KEY)
    criteria = SearchCriteria()
    criteria.sent_to = email + "." + SERVER_ID + "@mailosaur.io"
    message = client.messages.get(SERVER_ID, criteria)
    return message.text.body
Beispiel #13
0
from mailosaur import MailosaurClient
from mailosaur.models import SearchCriteria

# Available in the API tab of a server
api_key = "SmIuZgmXdRKsBdmj"
server_id = "om8bz7cc"
server_domain = "om8bz7cc.mailosaur.net"

mailosaur = MailosaurClient(api_key)

criteria = SearchCriteria()
criteria.sent_to = "somkiat@" + server_domain

email = mailosaur.messages.get(server_id, criteria)

print("Subject: " + email.subject)
print("Body: " + email.text.body)
Beispiel #14
0
 def get_email_list(self, server_id, email_address):
     criteria = SearchCriteria()
     criteria.sent_to = email_address
     self.email_list = self.client.messages.search(server=server_id, criteria=criteria, timeout=100000)
     logger.info("Email list found")
    def test_notifications(self):
        global token
        token = self.getToken()
        global service_token
        service_token = self.getServiceToken()
        global base_tenant_id
        base_tenant_id = self.getBaseTenantId()
        global roleIdMap
        roleIdMap = self.getRoleIdMap()
        seconds_since_epoch = datetime.now().timestamp()
        user_ids = []
        usernames = []

        for i in range(NO_OF_SUBSCRIBERS):
            # Create User
            username = self.mailosaur.servers.generate_email_address(
                MAILOSAUR_SERVER_NAME)
            user_id = self.createUser(username)
            print("created user-id: " + user_id)
            user_ids.append(user_id)
            usernames.append(username)

        # Create tenant
        tenant_id = self.createTenant(tenant_name, usernames)
        print("created tenant-id: " + tenant_id)

        # Create subscription
        self.createSubscription(SERVICE_NAME, tenant_id, user_ids)

        body = "This is Sample Event one sent - " + str(seconds_since_epoch)
        execptionRaised = False
        try:
            # Generate and send notification
            ws = create_connection(
                ws_url + '/audit/ws/audit-ingest',
                header={"Authorization": "Bearer " + service_token},
                sslopt={"cert_reqs": ssl.CERT_NONE})
            # Start thread to listen to audit logs
            auditLogWatcher = CommandWatch(
                cmd='kubectl -n rainier logs -f --tail 0 rainier-audit-0',
                countdown=NO_OF_NOTIFICATIONS * NO_OF_SUBSCRIBERS,
                end_pattern=".*(Email Sent Successfully for:).*",
                start_pattern=
                ".*(Size of notification queue is:)\s*\d+\s+(Size of event queue is:)\s*\d+"
            )
            audit_run_task = auditLogWatcher.submit(TIMEOUT)
            print("Sending " + str(NO_OF_NOTIFICATIONS) +
                  " notification, Body: " + body)
            msg = stomper.Frame()
            msg.cmd = 'SEND'
            msg.headers = {
                'destination': '/events/post',
                'content_type': 'application/json',
                'receipt': 'new-receipt'
            }

            msg.body = json.dumps({
                "tenant-id": tenant_id,
                "severity": "CRITICAL",
                "event-message": body,
                "event-name": SERVICE_NAME + "Asset",
                "time": int(round(time.time() * 1000)),
                "event-type": SERVICE_NAME + "down",
                "elementId": "oldvalue1",
                "neId": "newvalue1",
                "ne-kind": "userid6"
            })
            for i in range(NO_OF_NOTIFICATIONS):
                ws.send(msg.pack())
            ws.close()
        except Exception as err:
            print(
                "-----Exception while trying to send notification via websocket-----"
            )
            print(err)
            print(traceback.print_exc())
            print(
                "-------------------------------------------------------------------"
            )
            execptionRaised = True
            exit(1)
        finally:
            if not execptionRaised:
                # Wait till all notifications are read from queue
                print("Checking audit logs .....")
                runtime = audit_run_task.result()
                print("Notifications processing time taken: " + str(runtime) +
                      " s")

            # Delete subscription
            self.deleteSubscription(tenant_id)

            # Delete tenant
            self.deleteTenant(tenant_id)

            # Delete user
            self.deleteUser(user_ids)

        if validate:
            # Verify email notifications
            print("Waiting for emails to be sent .....")
            time.sleep(10)
            print("Done waiting")

            for user in usernames:
                # 2. Build search criteria to find the email you have sent
                print("Checking for user: "******"INFO Alert"
                criteria.sent_from = "*****@*****.**"
                criteria.body = body
                try:
                    # 3. Wait for the message (by default only looks for messages received in the last hour)
                    messages = self.mailosaur.messages.search(
                        MAILOSAUR_SERVER_NAME, criteria)
                    message_list = {}
                    if len(messages.items) > 0:
                        for message in messages.items:
                            if message.id not in message_list:
                                message_list[message.id] = message
                    t_end = time.time() + 60 * 2  # wait for 2 mins
                    i = 1
                    while time.time() < t_end and len(
                            messages.items) < NO_OF_NOTIFICATIONS:
                        time.sleep(10 * i)
                        messages = self.mailosaur.messages.search(
                            MAILOSAUR_SERVER_NAME, criteria)
                        if len(messages.items) > 0:
                            for message in messages.items:
                                if message.id not in message_list:
                                    message_list[message.id] = message
                except MailosaurException as err:
                    print(err.error_type)
                    print(err.message)
                    print("Response code: " + err.http_status_code +
                          ", body: " + err.http_response_body)
                    print(traceback.print_exc())

                # 4. Assert that the email subject is what we expect
                self.assertEqual(NO_OF_NOTIFICATIONS, len(messages.items))

                for key in message_list:
                    message = self.mailosaur.messages.get_by_id(key)
                    print("To: " + ",".join(str(p.email) for p in message.to))
                    print("Bcc: " +
                          ",".join(str(p.email) for p in message.bcc))
                    print("Text Content: " + str(message.text.body))
                    print("HTML Content: " + str(message.html.body))

                for message in messages.items:
                    self.mailosaur.messages.delete(message.id)