Skip to content

Commit 605eaa9

Browse files
committed
feat: test comments
1 parent 860502e commit 605eaa9

2 files changed

Lines changed: 69 additions & 1 deletion

File tree

tests/test_auth.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
def test_import():
66
sys.path.insert(0, ".")
77
import util
8+
sess = util.session()
89

910
assert "FERNET_KEY" in os.environ
1011
assert len(os.environ["FERNET_KEY"]) == 32
11-
assert util.session().username == "ScratchAttachV2"
12+
assert sess.username == "ScratchAttachV2"

tests/test_comment.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import sys
2+
from datetime import datetime, timedelta, timezone
3+
4+
5+
def test_comment():
6+
sys.path.insert(0, ".")
7+
import scratchattach as sa
8+
import util
9+
sess = util.session()
10+
11+
user = sess.connect_linked_user()
12+
proj = sess.connect_project(1108326850)
13+
studio = sess.connect_studio(50809872)
14+
15+
comment = user.comments(limit=1)[0]
16+
17+
assert comment.id == "387076703"
18+
assert comment.source is sa.CommentSource.USER_PROFILE
19+
assert comment.source_id == "ScratchAttachV2"
20+
assert comment.parent_id is None
21+
assert comment.content == "Sample comment"
22+
assert datetime.fromisoformat(comment.datetime_created) - datetime(2025, 8, 25, tzinfo=timezone.utc) < timedelta(days=1)
23+
assert comment.reply_count == 0
24+
assert comment.text == "Sample comment"
25+
26+
comment = proj.comments(limit=1)[0]
27+
28+
assert comment.id == 494890468
29+
assert comment.source in [sa.CommentSource.PROJECT, 'project']
30+
assert comment.source_id == 1108326850
31+
assert comment.parent_id is None
32+
assert comment.content == ("&lt;&amp;;&apos;!\n"
33+
"newline\n"
34+
"testing escaping")
35+
assert datetime.fromisoformat(comment.datetime_created) - datetime(2025, 9, 20, tzinfo=timezone.utc) < timedelta(days=1)
36+
assert comment.reply_count == 0
37+
assert comment.text == ("<&;'!\n"
38+
"newline\n"
39+
"testing escaping")
40+
41+
comment = studio.comments(limit=1)[0]
42+
43+
assert comment.id == 302129887
44+
assert comment.source in [sa.CommentSource.STUDIO, 'studio']
45+
assert comment.source_id == 50809872
46+
assert comment.parent_id is None
47+
assert comment.content == "Sample"
48+
assert datetime.fromisoformat(comment.datetime_created) - datetime(2025, 8, 26, tzinfo=timezone.utc) < timedelta(days=1)
49+
assert comment.reply_count == 1
50+
assert not comment.written_by_scratchteam
51+
assert comment.text == "Sample"
52+
53+
comment = comment.replies(limit=1)[0]
54+
55+
assert comment.id == 302129910
56+
assert comment.source in [sa.CommentSource.STUDIO, 'studio']
57+
assert comment.source_id == 50809872
58+
assert comment.parent_id == 302129887
59+
assert comment.commentee_id == 58743127
60+
assert comment.content == "text"
61+
assert datetime.fromisoformat(comment.datetime_created) - datetime(2025, 8, 26, tzinfo=timezone.utc) < timedelta(days=1)
62+
assert comment.reply_count == 0
63+
assert not comment.written_by_scratchteam
64+
assert comment.text == "text"
65+
66+
if __name__ == "__main__":
67+
test_comment()

0 commit comments

Comments
 (0)