source: ogServer-Git/tests/units/test_0019_post_image_create_basic.py @ 24c8b94

Last change on this file since 24c8b94 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.8 KB
Line 
1import requests
2import unittest
3
4class TestPostCreateBasicImageMethods(unittest.TestCase):
5
6    def setUp(self):
7        self.url = 'http://localhost:8888/image/create/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                      'code': '131',
13                      'id': '8',
14                      'name': 'debianbasica',
15                      'repository': '192.168.56.10',
16                      'sync_params':{'sync': '1',
17                                     'diff': '0',
18                                     'remove': '1',
19                                     'compress': '0',
20                                     'cleanup': '0',
21                                     'cache': '0',
22                                     'cleanup_cache': '0',
23                                     'remove_dst': '0'} }
24
25    def test_post(self):
26        returned = requests.post(self.url, headers=self.headers, json=self.json)
27        self.assertEqual(returned.status_code, 200)
28
29    def test_no_payload(self):
30        returned = requests.post(self.url, headers=self.headers, json=None)
31        self.assertEqual(returned.status_code, 400)
32
33    def test_malformed_payload(self):
34        for parameter in self.json:
35            malformed_payload = self.json.copy()
36            malformed_payload.pop(parameter)
37            returned = requests.post(self.url,
38                                     headers=self.headers,
39                                     json=malformed_payload)
40            self.assertEqual(returned.status_code, 400)
41
42    def test_get(self):
43        returned = requests.get(self.url, headers=self.headers)
44        self.assertEqual(returned.status_code, 405)
45
46if __name__ == '__main__':
47    unittest.main()
Note: See TracBrowser for help on using the repository browser.