source: ogServer-Git/tests/units/test_0016_post_image_create.py @ ba3b1ad

Last change on this file since ba3b1ad was b4d2890, checked in by OpenGnSys Support Team <soporte-og@…>, 5 years ago

#915 Add test for POST /image/create REST API

This test covers 3 scenarios:

  1. Correct usage.
  2. Incorrect usage, without payload.
  3. Incorrect usage, use this command with GET.
  • Property mode set to 100644
File size: 1.0 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_get(self):
26        returned = requests.get(self.url, headers=self.headers)
27        self.assertEqual(returned.status_code, 405)
28
29if __name__ == '__main__':
30    unittest.main()
Note: See TracBrowser for help on using the repository browser.