-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathepic_comments_test.py
65 lines (61 loc) · 2.34 KB
/
epic_comments_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import re
import tempfile
from epic_comments import csv_file_name, write_epic_comments
def test_write_epic_comments():
with tempfile.NamedTemporaryFile(mode="w") as fp:
print(f"fp {fp.name}")
write_epic_comments(
fp,
[
{
"id": 1234,
"text": "Test comment one",
"author_id": "test-author-id-1",
"comments": [],
},
{
"id": 2345,
"text": "Test comment two",
"author_id": "test-author-id-2",
"comments": [
{
"id": 3456,
"text": "Test comment nested one",
"author_id": "test-author-id-1",
"comments": [
{
"id": 4567,
"text": "Test comment nested one one",
"author_id": "test-author-id-2",
"comments": [],
}
],
},
{
"id": 5678,
"text": "Test comment nested two",
"author_id": "test-author-id-3",
"comments": [],
},
],
},
],
)
fp.flush()
with open(fp.name, "r") as f:
lines = f.readlines()
assert len(lines) == 6
assert lines[0] == "id,author_id,text,parent_id\n"
assert lines[1] == "1234,test-author-id-1,Test comment one,\n"
assert lines[2] == "2345,test-author-id-2,Test comment two,\n"
assert lines[3] == "3456,test-author-id-1,Test comment nested one,2345\n"
assert (
lines[4] == "4567,test-author-id-2,Test comment nested one one,3456\n"
)
assert lines[5] == "5678,test-author-id-3,Test comment nested two,2345\n"
fp.close()
def test_csv_file_name():
assert re.match(
r"epic-1234-comments_\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.csv",
csv_file_name(1234),
)