def test_update_cell_mapping(self):
     db_hm = create_mapping()
     db_cell = create_cell_mapping(id=42)
     cell = cell_mapping.CellMapping.get_by_uuid(self.context,
                                                 db_cell['uuid'])
     hm = host_mapping.HostMapping(self.context)
     hm.id = db_hm['id']
     hm.cell_mapping = cell
     hm.save()
     self.assertNotEqual(db_hm['cell_id'], hm.cell_mapping.id)
     for key in hm.fields.keys():
         if key in ('updated_at', 'cell_mapping'):
             continue
         model_field = getattr(hm, key)
         if key == 'created_at':
             model_field = model_field.replace(tzinfo=None)
         self.assertEqual(db_hm[key], model_field, 'field %s' % key)
     db_hm_new = host_mapping.HostMapping._get_by_host_from_db(
         self.context, db_hm['host'])
     self.assertNotEqual(db_hm['cell_id'], db_hm_new['cell_id'])
 def setUp(self):
     super(HostMappingTestCase, self).setUp()
     self.useFixture(fixtures.Database(database='api'))
     self.context = context.RequestContext('fake-user', 'fake-project')
     self.mapping_obj = host_mapping.HostMapping()
     self.cell_mapping_obj = cell_mapping.CellMapping()
def create_mapping_obj(context, **kwargs):
    mapping = create_mapping(**kwargs)
    return host_mapping.HostMapping._from_db_object(context,
                                                    host_mapping.HostMapping(),
                                                    mapping)