Skip to content

Commit 6d871ff

Browse files
committed
added tests
1 parent 26b223a commit 6d871ff

File tree

4 files changed

+86
-52
lines changed

4 files changed

+86
-52
lines changed

db/sqlite.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,9 @@ def get_subscriptions_by_publisher(self, conn, publisher_id):
164164
rows = c.fetchall()
165165
return [dict(row) for row in rows]
166166

167-
def add_subscription(self, conn, email, topic, publisher_id, joined_time=None, operation=""):
167+
def add_subscription(self, conn, email, topic, publisher_id, joined_time=None, operation="", frequency=3):
168168
c = conn.cursor()
169-
logger.info(f"Adding subscription for email: {email}, topic: {topic}, publisher_id: {publisher_id}, joined_time: {joined_time}")
169+
logger.info(f"Adding subscription for email: {email}, topic: {topic}, publisher_id: {publisher_id}, joined_time: {joined_time}, frequency: {frequency}")
170170

171171
sub = self.get_subscriptions_by_email_and_topic_and_publisher_id(conn, email, topic, publisher_id);
172172

@@ -185,14 +185,14 @@ def add_subscription(self, conn, email, topic, publisher_id, joined_time=None, o
185185
if joined_time is None:
186186
# Let SQLite fill in the default CURRENT_TIMESTAMP
187187
c.execute("""
188-
INSERT INTO subscriptions (email, topic, publisher_id)
189-
VALUES (?, ?, ?)
190-
""", (email, topic, publisher_id))
188+
INSERT INTO subscriptions (email, topic, publisher_id, frequency_in_days)
189+
VALUES (?, ?, ?, ?)
190+
""", (email, topic, publisher_id, frequency))
191191
else:
192192
c.execute("""
193193
INSERT INTO subscriptions (email, topic, publisher_id, joined_time)
194-
VALUES (?, ?, ?, ?)
195-
""", (email, topic, publisher_id, joined_time))
194+
VALUES (?, ?, ?, ?, ?)
195+
""", (email, topic, publisher_id, joined_time, frequency))
196196

197197
logger.info(f"Subscription for {email} addeed successfully")
198198

pytest.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[pytest]
22
markers =
33
notifications: mark tests that check notifications
4-
e2etests: for end to end tests
4+
e2e: for end to end tests
55
pubs: for scape_pubs cron
66
real: send email in real

tests/e2e/e2etests.py

Lines changed: 0 additions & 44 deletions
This file was deleted.

tests/e2e/test_e2e.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import pytest
2+
from db import enums
3+
import os
4+
from datetime import datetime
5+
from scrape_pubs import scrape_pubs
6+
from notify import notify
7+
from send_notifications import process_notifications
8+
9+
@pytest.mark.e2e
10+
def test_scrape_pubs_techteams(db, dummy_smtp):
11+
conn = db.get_connection()
12+
assert 0 == 0
13+
14+
db.add_publisher(conn, "aws", "techteam")
15+
db.add_subscription(conn, "newemail@gmail.com", enums.PublisherCategory.SOFTWARE_ENGINEERING.value, 1)
16+
17+
scrape_pubs(db, conn)
18+
19+
posts = db.get_posts(conn)
20+
21+
assert len(posts) > 10
22+
23+
notify(db, conn)
24+
25+
notifications = db.get_notifications_by_email(conn, "newemail@gmail.com")
26+
27+
assert len(notifications) == 0
28+
29+
post = posts[0]
30+
31+
db.update_post_label(conn, post['id'], enums.PublisherCategory.SOFTWARE_ENGINEERING.value)
32+
conn.commit()
33+
34+
notify(db, conn)
35+
36+
notifications = db.get_notifications_by_email(conn, "newemail@gmail.com")
37+
38+
assert len(notifications) == 1
39+
notification = notifications[0]
40+
assert notification['email'] == "newemail@gmail.com"
41+
assert notification['post_url'] == post['url']
42+
assert notification['post_title'] == post['title']
43+
assert notification['deleted'] == 0
44+
45+
process_notifications(db, conn)
46+
assert len(dummy_smtp.sent) == 0
47+
48+
db.add_subscription(conn, "newemail2@gmail.com", enums.PublisherCategory.SOFTWARE_ENGINEERING.value, 1, frequency=0)
49+
conn.commit()
50+
51+
notify(db, conn)
52+
53+
notifications = db.get_notifications_by_email(conn, "newemail2@gmail.com")
54+
55+
assert len(notifications) == 1
56+
notification = notifications[0]
57+
assert notification['email'] == "newemail2@gmail.com"
58+
assert notification['post_url'] == post['url']
59+
assert notification['post_title'] == post['title']
60+
assert notification['deleted'] == 0
61+
62+
process_notifications(db, conn)
63+
assert len(dummy_smtp.sent) == 1
64+
65+
66+
67+
68+
69+
70+
71+
72+
73+
74+
75+
76+
77+
78+

0 commit comments

Comments
 (0)