Esempio n. 1
0
def allocation_post_data(**kw):
    """Return an Allocation object without internal attributes."""
    allocation = db_utils.get_test_allocation(**kw)
    return {
        key: value
        for key, value in allocation.items() if key in _ALLOCATION_POST_FIELDS
    }
Esempio n. 2
0
def allocation_post_data(node=None, **kw):
    """Return an Allocation object without internal attributes."""
    allocation = db_utils.get_test_allocation(**kw)
    if node:
        # This is not a database field, so it has to be handled explicitly
        allocation['node'] = node
    return remove_other_fields(allocation,
                               al_controller.ALLOCATION_SCHEMA['properties'])
Esempio n. 3
0
def allocation_post_data(node=None, **kw):
    """Return an Allocation object without internal attributes."""
    allocation = db_utils.get_test_allocation(**kw)
    if node:
        # This is not a database field, so it has to be handled explicitly
        allocation['node'] = node
    return {key: value for key, value in allocation.items()
            if key in _ALLOCATION_POST_FIELDS}
Esempio n. 4
0
    def test_create(self):
        allocation = objects.Allocation(self.context, **self.fake_allocation)
        with mock.patch.object(self.dbapi, 'create_allocation',
                               autospec=True) as mock_create_allocation:
            mock_create_allocation.return_value = (
                db_utils.get_test_allocation())

            allocation.create()

            args, _kwargs = mock_create_allocation.call_args
            self.assertEqual(objects.Allocation.VERSION, args[0]['version'])
Esempio n. 5
0
    def test_refresh(self):
        uuid = self.fake_allocation['uuid']
        returns = [self.fake_allocation,
                   db_utils.get_test_allocation(name='newname')]
        expected = [mock.call(uuid), mock.call(uuid)]
        with mock.patch.object(self.dbapi, 'get_allocation_by_uuid',
                               side_effect=returns,
                               autospec=True) as mock_get_allocation:
            p = objects.Allocation.get_by_uuid(self.context, uuid)
            self.assertEqual(self.fake_allocation['name'], p.name)
            p.refresh()
            self.assertEqual('newname', p.name)

            self.assertEqual(expected, mock_get_allocation.call_args_list)
            self.assertEqual(self.context, p._context)
Esempio n. 6
0
    def test_save(self):
        uuid = self.fake_allocation['uuid']
        test_time = datetime.datetime(2000, 1, 1, 0, 0)
        with mock.patch.object(self.dbapi, 'get_allocation_by_uuid',
                               autospec=True) as mock_get_allocation:
            mock_get_allocation.return_value = self.fake_allocation
            with mock.patch.object(self.dbapi, 'update_allocation',
                                   autospec=True) as mock_update_allocation:
                mock_update_allocation.return_value = (
                    db_utils.get_test_allocation(name='newname',
                                                 updated_at=test_time))
                p = objects.Allocation.get_by_uuid(self.context, uuid)
                p.name = 'newname'
                p.save()

                mock_get_allocation.assert_called_once_with(uuid)
                mock_update_allocation.assert_called_once_with(
                    uuid, {'version': objects.Allocation.VERSION,
                           'name': 'newname'})
                self.assertEqual(self.context, p._context)
                res_updated_at = (p.updated_at).replace(tzinfo=None)
                self.assertEqual(test_time, res_updated_at)
Esempio n. 7
0
def allocation_post_data(**kw):
    """Return an Allocation object without internal attributes."""
    allocation = db_utils.get_test_allocation(**kw)
    return {key: value for key, value in allocation.items()
            if key in _ALLOCATION_POST_FIELDS}
Esempio n. 8
0
 def setUp(self):
     super(TestAllocationObject, self).setUp()
     self.fake_allocation = db_utils.get_test_allocation(name='host1')
Esempio n. 9
0
 def setUp(self):
     super(TestConvertToVersion, self).setUp()
     self.fake_allocation = db_utils.get_test_allocation()