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.

81 lines
1.6 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. userid = jsonR["user"]["id"]
  30. r = requests.get(URL + "/resources/"+ userid)
  31. t.rStatus("get /resources", r)
  32. jsonR = r.json()
  33. print(jsonR)
  34. time.sleep(1)
  35. r = requests.get(URL + "/resources/"+ userid)
  36. t.rStatus("get /resources", r)
  37. jsonR = r.json()
  38. print(jsonR)
  39. r = requests.get(URL + "/resources/"+ userid)
  40. t.rStatus("get /resources", r)
  41. jsonR = r.json()
  42. print(jsonR)
  43. r = requests.get(URL + "/planets/"+userid)
  44. t.rStatus("post /planets/:userid", r)
  45. jsonR = r.json()
  46. print(jsonR)
  47. print(jsonR["planets"][0])
  48. planetid = jsonR["planets"][0]["id"]
  49. d = {
  50. "planetid": planetid,
  51. "building": "metalplant",
  52. }
  53. r = requests.post(URL + "/buildings/"+userid, json=d)
  54. t.rStatus("post /building/:userid", r)
  55. jsonR = r.json()
  56. print(jsonR)
  57. d = {
  58. "planetid": planetid,
  59. "building": "ressearchlab",
  60. }
  61. r = requests.post(URL + "/buildings/"+userid, json=d)
  62. t.rStatus("post /building/:userid", r)
  63. jsonR = r.json()
  64. print(jsonR)
  65. t.printScores()