|
1 | 1 | import pytest |
2 | 2 | from db import enums |
3 | | -import os |
4 | | -from datetime import datetime |
| 3 | +import time |
| 4 | +from datetime import datetime, timezone |
5 | 5 | from scrape_pubs import scrape_pubs |
6 | 6 | from notify import notify |
7 | 7 | from send_notifications import process_notifications |
@@ -59,7 +59,47 @@ def test_scrape_pubs_techteams(db, dummy_smtp): |
59 | 59 | assert notification['post_title'] == post['title'] |
60 | 60 | assert notification['deleted'] == 0 |
61 | 61 |
|
| 62 | + beforeprocesstime = datetime.now(timezone.utc) |
| 63 | + |
| 64 | + time.sleep(1) |
| 65 | + |
62 | 66 | process_notifications(db, conn) |
| 67 | + |
| 68 | + notifications = db.get_notifications_by_email(conn, "newemail2@gmail.com") |
| 69 | + |
| 70 | + assert len(notifications) == 1 |
| 71 | + notification = notifications[0] |
| 72 | + assert notification['email'] == "newemail2@gmail.com" |
| 73 | + assert notification['post_url'] == post['url'] |
| 74 | + assert notification['post_title'] == post['title'] |
| 75 | + assert notification['deleted'] == 1 |
| 76 | + |
| 77 | + assert len(dummy_smtp.sent) == 1 |
| 78 | + |
| 79 | + subcriptions = db.get_subscriptions_by_email(conn, "newemail2@gmail.com") |
| 80 | + subs = subcriptions[0] # in this case only one sub is expected |
| 81 | + last_notify = subs['last_notified_at'] |
| 82 | + |
| 83 | + assert last_notify |
| 84 | + |
| 85 | + last_notify_at = datetime.fromisoformat(last_notify) |
| 86 | + |
| 87 | + if last_notify_at.tzinfo is None: |
| 88 | + last_notify_at = last_notify_at.replace(tzinfo=timezone.utc) |
| 89 | + |
| 90 | + assert last_notify_at and last_notify_at > beforeprocesstime |
| 91 | + |
| 92 | + notify(db, conn) |
| 93 | + |
| 94 | + notifications = db.get_notifications_by_email(conn, "newemail2@gmail.com") |
| 95 | + |
| 96 | + assert len(notifications) == 1 |
| 97 | + notification = notifications[0] |
| 98 | + assert notification['email'] == "newemail2@gmail.com" |
| 99 | + assert notification['post_url'] == post['url'] |
| 100 | + assert notification['post_title'] == post['title'] |
| 101 | + assert notification['deleted'] == 1 |
| 102 | + |
63 | 103 | assert len(dummy_smtp.sent) == 1 |
64 | 104 |
|
65 | 105 | conn.close() |
|
0 commit comments