source: ogServer-Git/tests/units/test_0021_post_image_restore_basic.py @ 696c5bb

Last change on this file since 696c5bb 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: 2.0 KB
Line 
1import requests
2import unittest
3
4class TestPostRestoreBasicImageMethods(unittest.TestCase):
5
6    def setUp(self):
7        self.url = 'http://localhost:8888/image/restore/basic'
8        self.headers = {'Authorization' : '07b3bfe728954619b58f0107ad73acc1'}
9        self.json = { 'clients' : [ '192.168.2.1', '192.168.2.2' ],
10                      'disk': '1',
11                      'partition': '1',
12                      'id': '9',
13                      'name': 'test',
14                      'repository': '192.168.56.10',
15                      'profile': '17',
16                      'type': 'UNICAST',
17                      'sync_params':{'path': '',
18                                     'method': '1',
19                                     'sync': '1',
20                                     'diff': '0',
21                                     'remove': '1',
22                                     'compress': '0',
23                                     'cleanup': '0',
24                                     'cache': '0',
25                                     'cleanup_cache': '0',
26                                     'remove_dst': '0'} }
27
28    def test_post(self):
29        returned = requests.post(self.url, headers=self.headers, json=self.json)
30        self.assertEqual(returned.status_code, 200)
31
32    def test_no_payload(self):
33        returned = requests.post(self.url, headers=self.headers, json=None)
34        self.assertEqual(returned.status_code, 400)
35
36    def test_malformed_payload(self):
37        for parameter in self.json:
38            malformed_payload = self.json.copy()
39            malformed_payload.pop(parameter)
40            returned = requests.post(self.url,
41                                     headers=self.headers,
42                                     json=malformed_payload)
43            self.assertEqual(returned.status_code, 400)
44
45    def test_get(self):
46        returned = requests.get(self.url, headers=self.headers)
47        self.assertEqual(returned.status_code, 405)
48
49if __name__ == '__main__':
50    unittest.main()
Note: See TracBrowser for help on using the repository browser.