def test_keypair_get(self, nc):
     request = self.mock_rest_request()
     nc.keypair_list.return_value = [
         mock.Mock(**{'to_dict.return_value': {'id': 'one'}}),
         mock.Mock(**{'to_dict.return_value': {'id': 'two'}}),
     ]
     response = nova.Keypairs().get(request)
     self.assertStatusCode(response, 200)
     self.assertEqual(response.content,
                      '{"items": [{"id": "one"}, {"id": "two"}]}')
     nc.keypair_list.assert_called_once_with(request)
 def test_keypair_create(self, nc):
     request = self.mock_rest_request(body='''{"name": "Ni!"}''')
     new = nc.keypair_create.return_value
     new.to_dict.return_value = {'name': 'Ni!', 'public_key': 'sekrit'}
     new.name = 'Ni!'
     with mock.patch.object(settings, 'DEBUG', True):
         response = nova.Keypairs().post(request)
     self.assertStatusCode(response, 201)
     self.assertEqual(response.content,
                      '{"name": "Ni!", "public_key": "sekrit"}')
     self.assertEqual(response['location'], '/api/nova/keypairs/Ni%21')
     nc.keypair_create.assert_called_once_with(request, 'Ni!')
Esempio n. 3
0
 def test_keypair_import(self, nc):
     request = self.mock_rest_request(body='''
         {"name": "Ni!", "public_key": "hi"}
     ''')
     new = nc.keypair_import.return_value
     new.to_dict.return_value = {'name': 'Ni!', 'public_key': 'hi'}
     new.name = 'Ni!'
     with mock.patch.object(settings, 'DEBUG', True):
         response = nova.Keypairs().post(request)
     self.assertStatusCode(response, 201)
     self.assertEqual({"name": "Ni!", "public_key": "hi"}, response.json)
     self.assertEqual('/api/nova/keypairs/Ni%21', response['location'])
     nc.keypair_import.assert_called_once_with(request, 'Ni!', 'hi')