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