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.

139 lines
3.4 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. # provoj
  2. Simple library to test the endpoints of an RESTful API.
  3. Check values, integrated with requests python library.
  4. For python version>3
  5. ## Installation
  6. Requires to have installed 'requests' library.
  7. Install provoj by:
  8. ```
  9. pip install provoj
  10. ```
  11. ### Usage
  12. Import the provoj library, and the requests library
  13. ```python
  14. import provoj
  15. import requests
  16. ```
  17. Define a new test
  18. ```python
  19. test = provoj.NewTest("Testing some websites")
  20. ```
  21. Check if two variables are equal
  22. ```python
  23. a = "hello"
  24. b = "world"
  25. test.equal("comparing a and b", a, b)# test.equal(check description, variable1, variable2)
  26. ```
  27. Check if two variables are not equal
  28. ```python
  29. a = "hello"
  30. b = "world"
  31. test.notequal("comparing a and b", a, b)# test.notequal(check description, variable1, variable2)
  32. ```
  33. Check if first variable is bigger than the second
  34. ```python
  35. a = 2
  36. b = 3
  37. test.bigger("comparing a and b", a, b)# test.bigger(check description, variable1, variable2)
  38. ```
  39. Check if first variable is smaller than the second
  40. ```python
  41. a = 2
  42. b = 3
  43. test.smaller("comparing a and b", a, b)# test.smaller(check description, variable1, variable2)
  44. ```
  45. Check if the length of a variable
  46. ```python
  47. animals = ["cat", "dog", "racoon"]
  48. test.length("checking the length of the array animals", animals, 3)# test.length(check description, variable1, length)
  49. ```
  50. Check for request status
  51. ```python
  52. r = requests.get("https://api.github.com/users/arnaucode/repos")
  53. test.rStatus("get api.github.com/users/arnaucode/repos", r)# test.rStatus(check description, request_response)
  54. ```
  55. ### Full example
  56. ```python
  57. import provoj
  58. import requests
  59. test1 = provoj.NewTest("testing some function")
  60. a = "hello"
  61. b = "world"
  62. c = "hello"
  63. test1.equal("comparing a and b", a, b)
  64. test1.notequal("comparing a and b", a, b)
  65. test1.equal("comparing a and c", a, c)
  66. x = 2
  67. y = 3
  68. test1.bigger("comparing x and y", x, y)
  69. test1.smaller("comparing x and y", x, y)
  70. test1.length("checking length", a, 2)
  71. test1.length("checking length", a, 5)
  72. animals = ["cat", "dog", "racoon"]
  73. test1.length("checking the length of the array animals", animals, 3)
  74. test1.printScores()
  75. t2 = provoj.NewTest("Testing some websites")
  76. r = requests.get("https://www.github.com")
  77. t2.rStatus("get github", r)
  78. r = requests.get("https://arnaucode.com")
  79. t2.rStatus("get arnaucode.com", r)
  80. r = requests.get("https://arnaucode.com/fake")
  81. t2.rStatus("get arnaucode.com/fake_path", r)
  82. r = requests.get("https://arnaucode.com/blog")
  83. t2.rStatus("get arnaucode.com/blog", r)
  84. t2.printScores()
  85. tGithub = provoj.NewTest("Github API tests")
  86. r = requests.get("https://api.github.com")
  87. tGithub.rStatus("get api.github", r)
  88. r = requests.get("https://api.github.com/users/arnaucode")
  89. tGithub.rStatus("get https://api.github.com/users/arnaucode", r)
  90. jsonResp = r.json()
  91. tGithub.equal("checking quantity of followers", jsonResp["followers"], 100)
  92. tGithub.equal("checking quantity of public_repos", jsonResp["public_repos"], 77)
  93. r = requests.get("https://api.github.com/users/arnaucode/repos")
  94. tGithub.rStatus("get https://api.github.com/users/arnaucode/repos", r)
  95. jsonResp = r.json()
  96. tGithub.length("checking length of repos", jsonResp, 30)
  97. tGithub.equal("checking first repo", jsonResp[0]["name"], "argos")
  98. tGithub.equal("checking second repo", jsonResp[1]["name"], "coffeeminer")
  99. tGithub.equal("checking third repo", jsonResp[2]["name"], "bc")
  100. tGithub.printScores()
  101. ```
  102. Output example:
  103. ![provoj](https://raw.githubusercontent.com/arnaucode/provoj/master/provoj-example.gif "provoj")