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