-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunit_test.py
177 lines (146 loc) · 4.29 KB
/
unit_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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import pytest
from pathlib import Path
from flask import Flask
from . import create_app
from .config import const
user_id = "CYCLONE4WEB-USER-cedcd31c-1578-47fe-b23e-98acab94d6e2"
@pytest.fixture()
def app():
app = create_app()
yield app
@pytest.fixture()
def client(app):
app.config['TESTING'] = True
client = app.test_client()
yield client
def test_entry(client):
'''
URL: / to /editor
'''
response = client.get('/', follow_redirects=True)
# Check that there was one redirect response.
assert len(response.history) == 2
# Check that the second request was to the editor/index page.
assert response.request.path == "/editor/"
def test_about(client):
'''
URL: /about
'''
response = client.get('/about')
assert response.status_code == 200
def test_error_405(client):
'''
URL: /about
'''
response = client.post('/about')
assert response.status_code == 200
assert b"405 Error" in response.data
def test_error_404(client):
'''
URL: /mirror
'''
response = client.get('/mirror')
assert response.status_code == 200
assert b"404 Error" in response.data
def test_error_page(client):
'''
URL: /error
'''
response = client.get('/error', data={
"code": 500,
"des": "Internal Error"
})
assert response.status_code == 200
def test_runCode(client):
'''
URL: /editor/run
'''
response = client.post('/editor/run',
data={
"code": """graph G {
abstract start node S1 {}
abstract node S2 {}
edge t1 { S1 -> S1 }
edge t2 { S1 -> S2 }
edge t3 { S2 -> S1 }
edge t4 { S2 -> S2 }
goal {
check for 5 condition (!(S1->S1) && !(S2->S2)) reach (S2)
}
}""",
"unique_user_id": user_id
})
assert response.status_code == 200
assert response.json["status"] == 0
assert response.json["msg"] == const.SUCCESS_REQ
def test_send_trace_file(client):
'''
URL: /editor/file
'''
response = client.get('/editor/file?path=/Users/chenchristian/Development/PycharmProjects/Cyclone4Web/Cyclone/trace/G.trace',
data={
"unique_user_id": user_id
}
)
assert response.status_code == 200
def test_upload(client):
'''
URL: /editor/upload
'''
resources = Path(__file__).parent.parent / "tmp"
response = client.post('/editor/upload',
data={
"unique_user_id": user_id,
"file": ( resources / "Main.cyclone").open("rb")
}
)
assert response.status_code == 200
assert response.json["status"] == 0
assert response.json["msg"] == const.SUCCESS_REQ_UPDATE
def test_downLoadFile(client):
'''
URL: /editor/save2LocalFile
'''
response = client.post('/editor/save2LocalFile',
data={
"unique_user_id": user_id,
"code": """graph G {
abstract start node S1 {}
abstract node S2 {}
edge t1 { S1 -> S1 }
edge t2 { S1 -> S2 }
edge t3 { S2 -> S1 }
edge t4 { S2 -> S2 }
goal {
check for 5 condition (!(S1->S1) && !(S2->S2)) reach (S2)
}
}""",
}
)
assert response.status_code == 200
def test_getExamplesList(client):
'''
URL: /editor/examples
'''
response = client.post('/editor/examples',
data={
"unique_user_id": user_id
}
)
assert response.status_code == 200
assert response.json["status"] == 0
assert response.json["msg"] == const.SUCCESS_REQ
def test_getExample(client):
'''
URL: /editor/example
'''
response = client.post('/editor/example',
data={
"unique_user_id": user_id,
"file": "example6.cyclone",
"folder": "chapter1"
}
)
assert response.status_code == 200
assert response.json["status"] == 0
assert response.json["msg"] == const.SUCCESS_REQ