Revision 4cf8adf8 api/tests.py
b/api/tests.py | ||
---|---|---|
694 | 694 |
data = json.dumps({'metadata': {'Key1': 'A Value'}}) |
695 | 695 |
response = self.client.post(path, data, content_type='application/json') |
696 | 696 |
self.assertItemNotFound(response) |
697 |
|
|
698 |
|
|
699 |
class ServerVNCConsole(BaseTestCase): |
|
700 |
SERVERS = 1 |
|
701 |
|
|
702 |
def test_not_active_server(self): |
|
703 |
"""Test console req for server not in ACTIVE state returns badRequest""" |
|
704 |
server_id = choice(VirtualMachine.objects.all()).id |
|
705 |
path = '/api/v1.1/servers/%d/action' % server_id |
|
706 |
data = json.dumps({'console': {'type': 'vnc'}}) |
|
707 |
response = self.client.post(path, data, content_type='application/json') |
|
708 |
self.assertBadRequest(response) |
|
709 |
|
|
710 |
def test_active_server(self): |
|
711 |
"""Test console req for ACTIVE server""" |
|
712 |
server_id = choice(VirtualMachine.objects.all()).id |
|
713 |
# FIXME: Start the server properly, instead of tampering with the DB |
|
714 |
vm = choice(VirtualMachine.objects.all()) |
|
715 |
vm.operstate = 'STARTED' |
|
716 |
vm.save() |
|
717 |
server_id = vm.id |
|
718 |
|
|
719 |
path = '/api/v1.1/servers/%d/action' % server_id |
|
720 |
data = json.dumps({'console': {'type': 'vnc'}}) |
|
721 |
response = self.client.post(path, data, content_type='application/json') |
|
722 |
self.assertEqual(response.status_code, 200) |
|
723 |
reply = json.loads(response.content) |
|
724 |
self.assertEqual(reply.keys(), ['vnc']) |
|
725 |
self.assertEqual(set(reply['vnc'].keys()), set(['host', 'port', 'password'])) |
|
726 |
|
Also available in: Unified diff