source: ogServer-Git/tests/units/test_0013_nonexistent.py

Last change on this file was 8903c68, checked in by OpenGnSys Support Team <soporte-og@…>, 5 years ago

#915 adds tests for a non existent method

This test adds four new error test cases:

  1. Non existent method with POST.
  2. Non existent method with GET.
  3. Non existent method with POST but with wrong API token.
  4. Non existent method with POST but without json.
  • Property mode set to 100644
File size: 1.1 KB
Line 
1import requests
2import unittest
3
4class 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
29if __name__ == '__main__':
30    unittest.main()
Note: See TracBrowser for help on using the repository browser.