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

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

#915 Test malformed payload for POST commands

This patch includes tests for the remaining REST API commands:

POST /shell/output
POST /session
POST /poweroff
POST /reboot
POST /stop
POST /refresh
POST /hardware
POST /software
POST /image/create
POST /image/restore
POST /setup
POST /image/create/basic
POST /image/create/incremental
POST /image/restore/basic
POST /image/restore/incremental
POST /run/schedule

This test covers requests that are missing one of the parameters in its
payload.

  • Property mode set to 100644
File size: 969 bytes
Line 
1import requests
2import unittest
3
4class TestPostStopMethods(unittest.TestCase):
5
6    def setUp(self):
7        self.url = 'http://localhost:8888/stop'
8        self.headers = {'Authorization' : '07b3bfe728954619b58f0107ad73acc1'}
9        self.json = { 'clients' : [ '192.168.2.1', '192.168.2.2' ] }
10
11    def test_post(self):
12        returned = requests.post(self.url, headers=self.headers, json=self.json)
13        self.assertEqual(returned.status_code, 200)
14
15    def test_no_payload(self):
16        returned = requests.post(self.url, headers=self.headers, json=None)
17        self.assertEqual(returned.status_code, 400)
18
19    def test_malformed_payload(self):
20        returned = requests.post(self.url, headers=self.headers, json={})
21        self.assertEqual(returned.status_code, 400)
22
23    def test_get(self):
24        returned = requests.get(self.url, headers=self.headers)
25        self.assertEqual(returned.status_code, 405)
26
27if __name__ == '__main__':
28    unittest.main()
Note: See TracBrowser for help on using the repository browser.