You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
1.8 KiB

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