source: ogServer-Git/tests/units/test_0017_post_image_restore.py @ 772811e

Last change on this file since 772811e was abd2b91, checked in by OpenGnSys Support Team <soporte-og@…>, 5 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.5 KB
Line 
1import requests
2import unittest
3
4class TestPostRestoreImageMethods(unittest.TestCase):
5
6    def setUp(self):
7        self.url = 'http://localhost:8888/image/restore'
8        self.headers = {'Authorization' : '07b3bfe728954619b58f0107ad73acc1'}
9        self.json = { 'clients' : [ '192.168.2.1', '192.168.2.2' ],
10                      'disk' : '1',
11                      'partition' : '1',
12                      'name' : 'test',
13                      'repository' : '192.168.56.10',
14                      'type' : 'UNICAST',
15                      'profile': '1',
16                      'id': '1' }
17
18    def test_post(self):
19        returned = requests.post(self.url, headers=self.headers, json=self.json)
20        self.assertEqual(returned.status_code, 200)
21
22    def test_no_payload(self):
23        returned = requests.post(self.url, headers=self.headers, json=None)
24        self.assertEqual(returned.status_code, 400)
25
26    def test_malformed_payload(self):
27        for parameter in self.json:
28            malformed_payload = self.json.copy()
29            malformed_payload.pop(parameter)
30            returned = requests.post(self.url,
31                                     headers=self.headers,
32                                     json=malformed_payload)
33            self.assertEqual(returned.status_code, 400)
34
35    def test_get(self):
36        returned = requests.get(self.url, headers=self.headers)
37        self.assertEqual(returned.status_code, 405)
38
39if __name__ == '__main__':
40    unittest.main()
Note: See TracBrowser for help on using the repository browser.