gogame-old/test/test.py
test/test.pyRaw
1#!/usr/bin/env python3
2"""Test endpoints for gogame
3"""
4
5import json
6import requests
7import provoj
8import time
9
10import os
11os.system("mongo gogame --eval 'db.dropDatabase()'")
12
13
14URL = "http://127.0.0.1:5000"
15
16t = provoj.NewTest("gogame")
17
18registerData = {
19 "name": "user00",
20 "password": "user00password",
21 "email": "user00@email.com",
22}
23r = requests.post(URL + "/register", json=registerData)
24t.rStatus("post /register", r)
25jsonR = r.json()
26print(jsonR)
27
28
29loginData = {
30 "email": "user00@email.com",
31 "password": "user00password",
32}
33r = requests.post(URL + "/login", json=loginData)
34t.rStatus("post /login", r)
35jsonR = r.json()
36print(jsonR)
37
38token = jsonR["token"]
39headers = {"Authorization": "Bearer " + token}
40
41r = requests.get(URL + "/", headers=headers)
42t.rStatus("get /", r)
43jsonR = r.json()
44print(jsonR)
45
46userid = jsonR["user"]["id"]
47r = requests.get(URL + "/resources", headers=headers)
48t.rStatus("get /resources", r)
49jsonR = r.json()
50print(jsonR)
51
52time.sleep(1)
53r = requests.get(URL + "/resources", headers=headers)
54t.rStatus("get /resources", r)
55jsonR = r.json()
56print(jsonR)
57
58r = requests.get(URL + "/planets", headers=headers)
59t.rStatus("post /planets/:userid", r)
60jsonR = r.json()
61print(jsonR)
62print(jsonR["planets"][0])
63planetid = jsonR["planets"][0]["id"]
64
65d = {
66 "planetid": planetid,
67 "building": "metalplant",
68}
69r = requests.post(URL + "/buildings", json=d, headers=headers)
70t.rStatus("post /building/:userid", r)
71jsonR = r.json()
72print(jsonR)
73
74d = {
75 "planetid": planetid,
76 "building": "ressearchlab",
77}
78r = requests.post(URL + "/buildings", json=d, headers=headers)
79t.rStatus("post /building/:userid", r)
80jsonR = r.json()
81print(jsonR)
82
83t.printScores()
84