Last change
on this file was
8903c68,
checked in by OpenGnSys Support Team <soporte-og@…>, 6 years ago
|
#915 adds tests for a non existent method
This test adds four new error test cases:
- Non existent method with POST.
- Non existent method with GET.
- Non existent method with POST but with wrong API token.
- Non existent method with POST but without json.
|
-
Property mode set to
100644
|
File size:
1.1 KB
|
Line | |
---|
1 | import requests |
---|
2 | import unittest |
---|
3 | |
---|
4 | class TestPostNonexistentMethods(unittest.TestCase): |
---|
5 | |
---|
6 | def setUp(self): |
---|
7 | self.url = 'http://localhost:8888/nonexistent' |
---|
8 | self.headers = {'Authorization' : '07b3bfe728954619b58f0107ad73acc1'} |
---|
9 | self.wrong_headers = {'Authorization' : |
---|
10 | 'WrongWrongWrongWrongWrongWrongWr'} |
---|
11 | self.json = { 'clients' : [ '192.168.2.1', '192.168.2.2' ] } |
---|
12 | |
---|
13 | def test_post(self): |
---|
14 | returned = requests.post(self.url, headers=self.headers, json=self.json) |
---|
15 | self.assertEqual(returned.status_code, 404) |
---|
16 | |
---|
17 | def test_get(self): |
---|
18 | returned = requests.get(self.url, headers=self.headers) |
---|
19 | self.assertEqual(returned.status_code, 404) |
---|
20 | |
---|
21 | def test_post_unauthenticated(self): |
---|
22 | returned = requests.post(self.url, headers=self.wrong_headers) |
---|
23 | self.assertEqual(returned.status_code, 401) |
---|
24 | |
---|
25 | def test_post_without_json(self): |
---|
26 | returned = requests.post(self.url, headers=self.headers) |
---|
27 | self.assertEqual(returned.status_code, 404) |
---|
28 | |
---|
29 | if __name__ == '__main__': |
---|
30 | unittest.main() |
---|
Note: See
TracBrowser
for help on using the repository browser.