Exemplo n.º 1
0
 def test_create_x509keypair_with_non_existent_bay_uuid(self):
     cdict = apiutils.x509keypair_post_data(
         bay_uuid=uuidutils.generate_uuid())
     response = self.post_json('/x509keypairs', cdict, expect_errors=True)
     self.assertEqual('application/json', response.content_type)
     self.assertEqual(400, response.status_int)
     self.assertTrue(response.json['errors'])
Exemplo n.º 2
0
 def test_create_x509keypair_with_non_existent_bay_uuid(self):
     cdict = apiutils.x509keypair_post_data(
         bay_uuid=uuidutils.generate_uuid())
     response = self.post_json('/x509keypairs', cdict, expect_errors=True)
     self.assertEqual('application/json', response.content_type)
     self.assertEqual(400, response.status_int)
     self.assertTrue(response.json['errors'])
Exemplo n.º 3
0
    def test_create_x509keypair_generate_uuid(self):
        cdict = apiutils.x509keypair_post_data()
        del cdict['uuid']

        response = self.post_json('/x509keypairs', cdict)
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(201, response.status_int)
        self.assertEqual(cdict['name'], response.json['name'])
        self.assertTrue(uuidutils.is_uuid_like(response.json['uuid']))
Exemplo n.º 4
0
    def test_create_x509keypair_generate_uuid(self):
        cdict = apiutils.x509keypair_post_data()
        del cdict['uuid']

        response = self.post_json('/x509keypairs', cdict)
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(201, response.status_int)
        self.assertEqual(cdict['name'], response.json['name'])
        self.assertTrue(utils.is_uuid_like(response.json['uuid']))
Exemplo n.º 5
0
 def test_create_x509keypair_doesnt_contain_id(self):
     with mock.patch.object(self.dbapi, 'create_x509keypair',
                            wraps=self.dbapi.create_x509keypair) as cc_mock:
         cdict = apiutils.x509keypair_post_data(
             name='x509keypair_example_A')
         response = self.post_json('/x509keypairs', cdict)
         self.assertEqual(cdict['name'], response.json['name'])
         cc_mock.assert_called_once_with(mock.ANY)
         # Check that 'id' is not in first arg of positional args
         self.assertNotIn('id', cc_mock.call_args[0][0])
Exemplo n.º 6
0
 def test_create_x509keypair_doesnt_contain_id(self):
     with mock.patch.object(self.dbapi, 'create_x509keypair',
                            wraps=self.dbapi.create_x509keypair) as cc_mock:
         cdict = apiutils.x509keypair_post_data(
             name='x509keypair_example_A')
         response = self.post_json('/x509keypairs', cdict)
         self.assertEqual(cdict['name'], response.json['name'])
         cc_mock.assert_called_once_with(mock.ANY)
         # Check that 'id' is not in first arg of positional args
         self.assertNotIn('id', cc_mock.call_args[0][0])
Exemplo n.º 7
0
    def test_create_x509keypair_set_project_id_and_user_id(self):
        cdict = apiutils.x509keypair_post_data()

        def _simulate_keypair_create(x509keypair):
            self.assertEqual(self.context.project_id, x509keypair.project_id)
            self.assertEqual(self.context.user_id, x509keypair.user_id)
            x509keypair.create()
            return x509keypair
        self.mock_x509keypair_create.side_effect = _simulate_keypair_create

        self.post_json('/x509keypairs', cdict)
Exemplo n.º 8
0
    def test_create_x509keypair_set_project_id_and_user_id(self):
        cdict = apiutils.x509keypair_post_data()

        def _simulate_keypair_create(x509keypair):
            self.assertEqual(self.context.project_id, x509keypair.project_id)
            self.assertEqual(self.context.user_id, x509keypair.user_id)
            x509keypair.create()
            return x509keypair
        self.mock_x509keypair_create.side_effect = _simulate_keypair_create

        self.post_json('/x509keypairs', cdict)
Exemplo n.º 9
0
    def test_create_x509keypair(self, mock_utcnow):
        cdict = apiutils.x509keypair_post_data()
        test_time = datetime.datetime(2000, 1, 1, 0, 0)
        mock_utcnow.return_value = test_time

        response = self.post_json('/x509keypairs', cdict)
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(201, response.status_int)
        # Check location header
        self.assertIsNotNone(response.location)
        expected_location = '/v1/x509keypairs/%s' % cdict['uuid']
        self.assertEqual(expected_location,
                         urlparse.urlparse(response.location).path)
        self.assertEqual(cdict['uuid'], response.json['uuid'])
        self.assertNotIn('updated_at', response.json.keys)
        return_created_at = timeutils.parse_isotime(
            response.json['created_at']).replace(tzinfo=None)
        self.assertEqual(test_time, return_created_at)
Exemplo n.º 10
0
    def test_create_x509keypair(self, mock_utcnow):
        cdict = apiutils.x509keypair_post_data()
        test_time = datetime.datetime(2000, 1, 1, 0, 0)
        mock_utcnow.return_value = test_time

        response = self.post_json('/x509keypairs', cdict)
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(201, response.status_int)
        # Check location header
        self.assertIsNotNone(response.location)
        expected_location = '/v1/x509keypairs/%s' % cdict['uuid']
        self.assertEqual(
            urlparse.urlparse(response.location).path, expected_location)
        self.assertEqual(cdict['uuid'], response.json['uuid'])
        self.assertNotIn('updated_at', response.json.keys)
        return_created_at = timeutils.parse_isotime(
            response.json['created_at']).replace(tzinfo=None)
        self.assertEqual(test_time, return_created_at)
Exemplo n.º 11
0
 def test_x509keypair_init(self):
     x509keypair_dict = apiutils.x509keypair_post_data(bay_uuid=None)
     x509keypair = api_x509keypair.X509KeyPair(**x509keypair_dict)
     self.assertEqual('certificate', x509keypair.certificate)
Exemplo n.º 12
0
 def test_create_x509keypair_with_bay_name(self):
     cdict = apiutils.x509keypair_post_data(bay_uuid=self.bay.name)
     response = self.post_json('/x509keypairs', cdict, expect_errors=True)
     self.assertEqual('application/json', response.content_type)
     self.assertEqual(201, response.status_int)
Exemplo n.º 13
0
 def test_create_x509keypair_no_bay_uuid(self):
     cdict = apiutils.x509keypair_post_data()
     del cdict['bay_uuid']
     response = self.post_json('/x509keypairs', cdict, expect_errors=True)
     self.assertEqual('application/json', response.content_type)
     self.assertEqual(400, response.status_int)
Exemplo n.º 14
0
 def test_x509keypair_init(self):
     x509keypair_dict = apiutils.x509keypair_post_data(bay_uuid=None)
     x509keypair = api_x509keypair.X509KeyPair(**x509keypair_dict)
     self.assertEqual('certificate', x509keypair.certificate)
Exemplo n.º 15
0
 def test_create_x509keypair_with_bay_name(self):
     cdict = apiutils.x509keypair_post_data(bay_uuid=self.bay.name)
     response = self.post_json('/x509keypairs', cdict, expect_errors=True)
     self.assertEqual('application/json', response.content_type)
     self.assertEqual(201, response.status_int)
Exemplo n.º 16
0
 def test_create_x509keypair_no_bay_uuid(self):
     cdict = apiutils.x509keypair_post_data()
     del cdict['bay_uuid']
     response = self.post_json('/x509keypairs', cdict, expect_errors=True)
     self.assertEqual('application/json', response.content_type)
     self.assertEqual(400, response.status_int)