functional_test.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #! /usr/bin/python3
  2. ## THIS IS A HOLISTIC TEST SUITE
  3. ## to exercise the fundamental, basic, essential functionality
  4. ## of this app and what it does, from the perspective of the api.
  5. import requests
  6. url = "http://localhost:4000/api/"
  7. def get_messages(fourletters):
  8. r = requests.get(url + fourletters)
  9. messages = r.json()['messages']
  10. return messages
  11. def clear_messages(fourletters):
  12. r = requests.delete(url + fourletters)
  13. def add_message(fourletters, message):
  14. r = requests.post(url + fourletters + f"?message={message}")
  15. ###################################################
  16. #
  17. # test for the page 'dumb'
  18. test_fourletters = "dumb"
  19. print(f"im going to test fourletters with 'dumb'")
  20. #
  21. # clear the slate
  22. clear_messages(test_fourletters)
  23. print(" clearing the messages")
  24. #
  25. # check that the state is clear
  26. messages = get_messages(test_fourletters)
  27. assert messages == []
  28. print(" messages are clear")
  29. #
  30. # add to the state
  31. add_message(test_fourletters, "yo")
  32. print(" sending a message: 'yo'")
  33. #
  34. # check that the state matches what i set
  35. messages = get_messages(test_fourletters)
  36. assert messages == ["yo"]
  37. print(f" messages are now {messages}")
  38. #
  39. # further add to the state
  40. add_message(test_fourletters, "mama")
  41. print(" sending a message: 'mama'")
  42. #
  43. # check that the state matches what i set
  44. messages = get_messages(test_fourletters)
  45. assert messages == ["yo", "mama"]
  46. print(f" messages are now {messages}")
  47. #
  48. # clear the slate
  49. clear_messages(test_fourletters)
  50. print(" clearing the messages")
  51. #
  52. # check that the state is clear
  53. messages = get_messages(test_fourletters)
  54. assert messages == []
  55. print(" messages are clear")
  56. print("test was a success!")