-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomment_thread_tester.py
104 lines (95 loc) · 3.23 KB
/
comment_thread_tester.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import json
import requests
# Get the data from the API
# {
# "error": null,
# "value": [
# {
# "text": "A",
# "replies": 5,
# "children": [
# {
# "text": "B",
# "replies": 2,
# "children": [
# {
# "text": "G",
# "replies": 2,
# "children": []
# }
# ]
# },
# {
# "parent_post": "EXi4jzwC8ABJAS-KcAzqjg",
# "text": "D",
# "replies": 2,
# "children": []
# },
# {
# "parent_post": "EXi4jzwC8ABJAS-KcAzqjg",
# "text": "R",
# "replies": 1,
# "children": []
# },
# {
# "parent_post": "EXi4jzwC8ABJAS-KcAzqjg",
# "text": "C",
# "replies": 0,
# "children": []
# },
# {
# "parent_post": "EXi4jzwC8ABJAS-KcAzqjg",
# "text": "T",
# "replies": 0,
# "children": []
# }
# ]
# }
# ]
# }
# A -> B or A -> c or A -> D or A-> R or A -> T
# B -> G or B -> E
# E -> F
# F -> H or F -> I
# H -> N or H -> O
# G -> J or G -> K
# J -> M
# K -> L
# D -> P or D -> Y
# P -> X or P -> U or P -> V or P -> W
# W -> T
# R -> S
def check_children_names(data_children: list, expected_children: list):
for data_child in data_children:
if data_child["text"] in expected_children:
continue
else:
return False
return True
def check_data(data1) -> bool:
for data in data1:
if (data["text"] == "A" and check_children_names(data["children"], ["B", "C", "D", "R", "T"])) or (data["text"] == "B" and check_children_names(data["children"], ["G", "E"])) or (data["text"] == "E" and check_children_names(data["children"], ["F"])) or (data["text"] == "F" and check_children_names(data["children"], ["H", "I"])) or (data["text"] == "H" and check_children_names(data["children"], ["N", "O"])) or (data["text"] == "G" and check_children_names(data["children"], ["J", "K"])) or (data["text"] == "J" and check_children_names(data["children"], ["M"])) or (data["text"] == "K" and check_children_names(data["children"], ["L"])) or (data["text"] == "D" and check_children_names(data["children"], ["P", "Y"])) or (data["text"] == "P" and check_children_names(data["children"], ["X", "U", "V", "W"])) or (data["text"] == "W" and check_children_names(data["children"], ["T"])) or (data["text"] == "R" and check_children_names(data["children"], ["S"])):
check_data(data['children'])
else:
return False
return True
payload = {
"kind": "root",
"sort": "best",
"parent": "X7lggPyFb7-ec3PrGd_kWw",
"seen": []
}
header = {
"Accept": "*/*",
"User-Agent": "Thunder Client (https://www.thunderclient.com)"
}
for i in range(1, 10):
url = "http://localhost:3000/comments/"
response = requests.get(url, json=payload)
data = response.json()["value"]
if check_data(data):
print("True")
else:
# print(data)
print("False")
pass