source: ogServer-Git/tests/units/test_0016_post_image_create.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: 1.4 KB
Line 
1import requests
2import unittest
3
4class TestPostCreateImageMethods(unittest.TestCase):
5
6    def setUp(self):
7        self.url = 'http://localhost:8888/image/create'
8        self.headers = {'Authorization' : '07b3bfe728954619b58f0107ad73acc1'}
9        self.json = { 'clients' : [ '192.168.2.1', '192.168.2.2' ],
10                      'disk' : '1',
11                      'partition' : '1',
12                      'code' : '1',
13                      'id' : '1',
14                      'name' : 'test',
15                      'repository' : '192.168.2.4' }
16
17    def test_post(self):
18        returned = requests.post(self.url, headers=self.headers, json=self.json)
19        self.assertEqual(returned.status_code, 200)
20
21    def test_no_payload(self):
22        returned = requests.post(self.url, headers=self.headers, json=None)
23        self.assertEqual(returned.status_code, 400)
24
25    def test_malformed_payload(self):
26        for parameter in self.json:
27            malformed_payload = self.json.copy()
28            malformed_payload.pop(parameter)
29            returned = requests.post(self.url,
30                                     headers=self.headers,
31                                     json=malformed_payload)
32            self.assertEqual(returned.status_code, 400)
33
34    def test_get(self):
35        returned = requests.get(self.url, headers=self.headers)
36        self.assertEqual(returned.status_code, 405)
37
38if __name__ == '__main__':
39    unittest.main()
Note: See TracBrowser for help on using the repository browser.