|
| 1 | +import time |
1 | 2 | import pytest
|
2 |
| - |
3 | 3 | import polyclash.server as server
|
4 | 4 |
|
5 | 5 | from flask_socketio import SocketIO
|
@@ -110,7 +110,7 @@ def test_game_ready(storage, test_client, socketio_client):
|
110 | 110 | assert result6.json['status']['black']
|
111 | 111 |
|
112 | 112 |
|
113 |
| -def test_play_game(storage, test_client, socketio_client): |
| 113 | +def test_game_ready2(storage, test_client, socketio_client): |
114 | 114 | result0 = test_client.post('/sphgo/new', json={'key': server_token})
|
115 | 115 | assert result0.status_code == 200
|
116 | 116 | assert result0.json['black_key']
|
@@ -152,5 +152,223 @@ def test_play_game(storage, test_client, socketio_client):
|
152 | 152 | assert result8.json['status']['white']
|
153 | 153 |
|
154 | 154 |
|
| 155 | +def test_game_play(storage, test_client, socketio_client): |
| 156 | + result0 = test_client.post('/sphgo/new', json={'key': server_token}) |
| 157 | + assert result0.status_code == 200 |
| 158 | + assert result0.json['black_key'] |
| 159 | + assert result0.json['white_key'] |
| 160 | + |
| 161 | + result1 = test_client.post('/sphgo/join', json={'token': result0.json['black_key']}) |
| 162 | + assert result1.status_code == 200 |
| 163 | + assert result1.json['status']['black'] |
| 164 | + |
| 165 | + result3 = test_client.post('/sphgo/join', json={'token': result0.json['white_key']}) |
| 166 | + assert result3.status_code == 200 |
| 167 | + assert result3.json['status']['white'] |
| 168 | + |
| 169 | + result5 = test_client.post('/sphgo/ready', json={'token': result0.json['black_key']}) |
| 170 | + assert result5.status_code == 200 |
| 171 | + assert result5.json['status']['black'] |
| 172 | + |
| 173 | + result7 = test_client.post('/sphgo/ready', json={'token': result0.json['white_key']}) |
| 174 | + assert result7.status_code == 200 |
| 175 | + assert result7.json['status']['black'] |
| 176 | + |
| 177 | + result9 = test_client.post('/sphgo/play', json={'token': result0.json['black_key'], 'role': 'black', 'steps': 0, 'play': [5, 6, 7, 8, 9]}) |
| 178 | + assert result9.status_code == 200 |
| 179 | + |
| 180 | + result10 = test_client.post('/sphgo/play', json={'token': result0.json['white_key'], 'role': 'white', 'steps': 1, 'play': [0, 1, 2, 3, 4]}) |
| 181 | + assert result10.status_code == 200 |
| 182 | + |
| 183 | + |
| 184 | +def test_game_play_wrong_turn1(storage, test_client, socketio_client): |
| 185 | + result0 = test_client.post('/sphgo/new', json={'key': server_token}) |
| 186 | + assert result0.status_code == 200 |
| 187 | + assert result0.json['black_key'] |
| 188 | + assert result0.json['white_key'] |
| 189 | + |
| 190 | + result1 = test_client.post('/sphgo/join', json={'token': result0.json['black_key']}) |
| 191 | + assert result1.status_code == 200 |
| 192 | + assert result1.json['status']['black'] |
| 193 | + |
| 194 | + result3 = test_client.post('/sphgo/join', json={'token': result0.json['white_key']}) |
| 195 | + assert result3.status_code == 200 |
| 196 | + assert result3.json['status']['white'] |
| 197 | + |
| 198 | + result5 = test_client.post('/sphgo/ready', json={'token': result0.json['black_key']}) |
| 199 | + assert result5.status_code == 200 |
| 200 | + assert result5.json['status']['black'] |
| 201 | + |
| 202 | + result7 = test_client.post('/sphgo/ready', json={'token': result0.json['white_key']}) |
| 203 | + assert result7.status_code == 200 |
| 204 | + assert result7.json['status']['black'] |
| 205 | + |
| 206 | + result9 = test_client.post('/sphgo/play', json={'token': result0.json['black_key'], 'role': 'black', 'steps': 0, 'play': [5, 6, 7, 8, 9]}) |
| 207 | + assert result9.status_code == 200 |
| 208 | + |
| 209 | + result10 = test_client.post('/sphgo/play', json={'token': result0.json['black_key'], 'role': 'white', 'steps': 1, 'play': [0, 1, 2, 3, 4]}) |
| 210 | + assert result10.status_code == 400 |
| 211 | + |
| 212 | + |
| 213 | +def test_game_play_wrong_turn2(storage, test_client, socketio_client): |
| 214 | + result0 = test_client.post('/sphgo/new', json={'key': server_token}) |
| 215 | + assert result0.status_code == 200 |
| 216 | + assert result0.json['black_key'] |
| 217 | + assert result0.json['white_key'] |
| 218 | + |
| 219 | + result1 = test_client.post('/sphgo/join', json={'token': result0.json['black_key']}) |
| 220 | + assert result1.status_code == 200 |
| 221 | + assert result1.json['status']['black'] |
| 222 | + |
| 223 | + result3 = test_client.post('/sphgo/join', json={'token': result0.json['white_key']}) |
| 224 | + assert result3.status_code == 200 |
| 225 | + assert result3.json['status']['white'] |
| 226 | + |
| 227 | + result5 = test_client.post('/sphgo/ready', json={'token': result0.json['black_key']}) |
| 228 | + assert result5.status_code == 200 |
| 229 | + assert result5.json['status']['black'] |
| 230 | + |
| 231 | + result7 = test_client.post('/sphgo/ready', json={'token': result0.json['white_key']}) |
| 232 | + assert result7.status_code == 200 |
| 233 | + assert result7.json['status']['black'] |
| 234 | + |
| 235 | + result9 = test_client.post('/sphgo/play', json={'token': result0.json['black_key'], 'role': 'black', 'steps': 0, 'play': [5, 6, 7, 8, 9]}) |
| 236 | + assert result9.status_code == 200 |
| 237 | + |
| 238 | + result10 = test_client.post('/sphgo/play', json={'token': result0.json['white_key'], 'role': 'white', 'steps': 1, 'play': [0, 1, 2, 3, 4]}) |
| 239 | + assert result10.status_code == 200 |
| 240 | + |
| 241 | + result11 = test_client.post('/sphgo/play', json={'token': result0.json['white_key'], 'role': 'white', 'steps': 2, 'play': [10, 11, 12, 13, 14]}) |
| 242 | + assert result11.status_code == 400 |
| 243 | + |
| 244 | + |
| 245 | + |
| 246 | +def test_game_play_wrong_steps1(storage, test_client, socketio_client): |
| 247 | + result0 = test_client.post('/sphgo/new', json={'key': server_token}) |
| 248 | + assert result0.status_code == 200 |
| 249 | + assert result0.json['black_key'] |
| 250 | + assert result0.json['white_key'] |
| 251 | + |
| 252 | + result1 = test_client.post('/sphgo/join', json={'token': result0.json['black_key']}) |
| 253 | + assert result1.status_code == 200 |
| 254 | + assert result1.json['status']['black'] |
| 255 | + |
| 256 | + result3 = test_client.post('/sphgo/join', json={'token': result0.json['white_key']}) |
| 257 | + assert result3.status_code == 200 |
| 258 | + assert result3.json['status']['white'] |
| 259 | + |
| 260 | + result5 = test_client.post('/sphgo/ready', json={'token': result0.json['black_key']}) |
| 261 | + assert result5.status_code == 200 |
| 262 | + assert result5.json['status']['black'] |
| 263 | + |
| 264 | + result7 = test_client.post('/sphgo/ready', json={'token': result0.json['white_key']}) |
| 265 | + assert result7.status_code == 200 |
| 266 | + assert result7.json['status']['black'] |
| 267 | + |
| 268 | + result9 = test_client.post('/sphgo/play', json={'token': result0.json['black_key'], 'role': 'black', 'steps': 1, 'play': [5, 6, 7, 8, 9]}) |
| 269 | + assert result9.status_code == 400 |
| 270 | + |
| 271 | + |
| 272 | +def test_game_play_wrong_steps2(storage, test_client, socketio_client): |
| 273 | + result0 = test_client.post('/sphgo/new', json={'key': server_token}) |
| 274 | + assert result0.status_code == 200 |
| 275 | + assert result0.json['black_key'] |
| 276 | + assert result0.json['white_key'] |
| 277 | + |
| 278 | + result1 = test_client.post('/sphgo/join', json={'token': result0.json['black_key']}) |
| 279 | + assert result1.status_code == 200 |
| 280 | + assert result1.json['status']['black'] |
| 281 | + |
| 282 | + result3 = test_client.post('/sphgo/join', json={'token': result0.json['white_key']}) |
| 283 | + assert result3.status_code == 200 |
| 284 | + assert result3.json['status']['white'] |
| 285 | + |
| 286 | + result5 = test_client.post('/sphgo/ready', json={'token': result0.json['black_key']}) |
| 287 | + assert result5.status_code == 200 |
| 288 | + assert result5.json['status']['black'] |
| 289 | + |
| 290 | + result7 = test_client.post('/sphgo/ready', json={'token': result0.json['white_key']}) |
| 291 | + assert result7.status_code == 200 |
| 292 | + assert result7.json['status']['black'] |
| 293 | + |
| 294 | + result9 = test_client.post('/sphgo/play', json={'token': result0.json['black_key'], 'role': 'black', 'steps': 0, 'play': [5, 6, 7, 8, 9]}) |
| 295 | + assert result9.status_code == 200 |
| 296 | + |
| 297 | + result10 = test_client.post('/sphgo/play', json={'token': result0.json['white_key'], 'role': 'white', 'steps': 1, 'play': [0, 1, 2, 3, 4]}) |
| 298 | + assert result10.status_code == 200 |
| 299 | + |
| 300 | + result11 = test_client.post('/sphgo/play', json={'token': result0.json['black_key'], 'role': 'black', 'steps': 1, 'play': [10, 11, 12, 13, 14]}) |
| 301 | + assert result11.status_code == 400 |
| 302 | + |
| 303 | + |
| 304 | +def test_game_play_no_hang(storage, test_client, socketio_client): |
| 305 | + result0 = test_client.post('/sphgo/new', json={'key': server_token}) |
| 306 | + assert result0.status_code == 200 |
| 307 | + assert result0.json['black_key'] |
| 308 | + assert result0.json['white_key'] |
| 309 | + |
| 310 | + result1 = test_client.post('/sphgo/join', json={'token': result0.json['black_key']}) |
| 311 | + assert result1.status_code == 200 |
| 312 | + assert result1.json['status']['black'] |
| 313 | + |
| 314 | + result3 = test_client.post('/sphgo/join', json={'token': result0.json['white_key']}) |
| 315 | + assert result3.status_code == 200 |
| 316 | + assert result3.json['status']['white'] |
| 317 | + |
| 318 | + result5 = test_client.post('/sphgo/ready', json={'token': result0.json['black_key']}) |
| 319 | + assert result5.status_code == 200 |
| 320 | + assert result5.json['status']['black'] |
| 321 | + |
| 322 | + result7 = test_client.post('/sphgo/ready', json={'token': result0.json['white_key']}) |
| 323 | + assert result7.status_code == 200 |
| 324 | + assert result7.json['status']['black'] |
| 325 | + |
| 326 | + result9 = test_client.post('/sphgo/play', json={'token': result0.json['black_key'], 'role': 'black', 'steps': 0, 'play': [5, 6, 7, 8, 9]}) |
| 327 | + assert result9.status_code == 200 |
| 328 | + |
| 329 | + result10 = test_client.post('/sphgo/play', json={'token': result0.json['white_key'], 'role': 'white', 'steps': 1, 'play': [0, 1, 2, 3, 4]}) |
| 330 | + assert result10.status_code == 200 |
| 331 | + |
| 332 | + result11 = test_client.post('/sphgo/play', json={'token': result0.json['black_key'], 'role': 'black', 'steps': 1, 'play': [10, 11, 12, 13, 14]}) |
| 333 | + assert result11.status_code == 400 |
| 334 | + |
| 335 | + result12 = test_client.post('/sphgo/play', json={'token': result0.json['black_key'], 'role': 'black', 'steps': 2, 'play': [10, 11, 12, 13, 14]}) |
| 336 | + assert result12.status_code == 200 |
| 337 | + |
| 338 | + |
| 339 | +def test_game_close(storage, test_client, socketio_client): |
| 340 | + result0 = test_client.post('/sphgo/new', json={'key': server_token}) |
| 341 | + assert result0.status_code == 200 |
| 342 | + assert result0.json['black_key'] |
| 343 | + assert result0.json['white_key'] |
| 344 | + |
| 345 | + result1 = test_client.post('/sphgo/join', json={'token': result0.json['black_key']}) |
| 346 | + assert result1.status_code == 200 |
| 347 | + assert result1.json['status']['black'] |
| 348 | + |
| 349 | + result3 = test_client.post('/sphgo/join', json={'token': result0.json['white_key']}) |
| 350 | + assert result3.status_code == 200 |
| 351 | + assert result3.json['status']['white'] |
| 352 | + |
| 353 | + result5 = test_client.post('/sphgo/ready', json={'token': result0.json['black_key']}) |
| 354 | + assert result5.status_code == 200 |
| 355 | + assert result5.json['status']['black'] |
| 356 | + |
| 357 | + result7 = test_client.post('/sphgo/ready', json={'token': result0.json['white_key']}) |
| 358 | + assert result7.status_code == 200 |
| 359 | + assert result7.json['status']['black'] |
| 360 | + |
| 361 | + result9 = test_client.post('/sphgo/play', json={'token': result0.json['black_key'], 'role': 'black', 'steps': 0, 'play': [5, 6, 7, 8, 9]}) |
| 362 | + assert result9.status_code == 200 |
| 363 | + |
| 364 | + result10 = test_client.post('/sphgo/play', json={'token': result0.json['white_key'], 'role': 'white', 'steps': 1, 'play': [0, 1, 2, 3, 4]}) |
| 365 | + assert result10.status_code == 200 |
| 366 | + |
| 367 | + result11 = test_client.post('/sphgo/close', json={'token': result0.json['white_key']}) |
| 368 | + assert result11.status_code == 200 |
| 369 | + |
| 370 | + result12 = test_client.get('/sphgo/list') |
| 371 | + assert result0.json['game_id'] not in result12.json['rooms'] |
| 372 | + |
155 | 373 | if __name__ == '__main__':
|
156 | 374 | pytest.main()
|
0 commit comments