Ejemplo n.º 1
0
    def test_fill_obj_extarq_fields_with_dep_id(self, mock_get_devprof,
                                                mock_get_ah, mock_get_obj_dep,
                                                mock_obj_devprof):
        in_db_extarq = self.fake_db_extarqs[0]
        # Since state is not 'Bound', attach_handle_get_by_id is not called.
        in_db_extarq['state'] = 'Initial'
        in_db_extarq['deployable_id'] = '1'
        db_devprof = fake_device_profile.get_db_devprofs()[0]
        obj_devprof = fake_device_profile.get_obj_devprofs()[0]

        mock_get_devprof.return_value = db_devprof
        mock_obj_devprof.return_value = obj_devprof
        mock_get_obj_dep.return_value = \
            fake_deployable.fake_deployable_obj(self.context,
                                                uuid=self.deployable_uuids[0])

        out_db_extarq = objects.ExtARQ._fill_obj_extarq_fields(
            self.context, in_db_extarq)

        self.assertEqual(out_db_extarq['device_profile_name'],
                         db_devprof['name'])
        self.assertEqual(out_db_extarq['attach_handle_type'], '')
        self.assertEqual(out_db_extarq['attach_handle_info'], '')
        devprof_group_id = out_db_extarq['device_profile_group_id']
        self.assertEqual(out_db_extarq['device_profile_group'],
                         obj_devprof['groups'][devprof_group_id])
Ejemplo n.º 2
0
 def test_create(self):
     api_devprofs = fake_device_profile.get_api_devprofs()
     api_devprof = api_devprofs[0]
     db_devprofs = fake_device_profile.get_db_devprofs()
     db_devprof = db_devprofs[0]
     with mock.patch.object(self.dbapi,
                            'device_profile_create',
                            autospec=True) as mock_db_devprof_create:
         mock_db_devprof_create.return_value = self.fake_device_profile
         obj_devprof = objects.DeviceProfile(**api_devprof)
         obj_devprof.create(self.context)
         mock_db_devprof_create.assert_called_once_with(
             self.context, db_devprof)
Ejemplo n.º 3
0
 def test_update(self):
     fake_db_devprofs = fake_device_profile.get_db_devprofs()
     fake_obj_devprofs = fake_device_profile.get_obj_devprofs()
     db_devprof = fake_db_devprofs[0]
     db_devprof['created_at'] = None
     db_devprof['updated_at'] = None
     with mock.patch.object(self.dbapi,
                            'device_profile_get_by_uuid',
                            autospec=True) as mock_dp_get:
         mock_dp_get.return_value = db_devprof
         uuid = fake_db_devprofs[0]['uuid']
         # Start with db_devprofs[0], corr. to fake_obj_devprofs[0]
         obj_devprof = objects.DeviceProfile.get_by_uuid(self.context, uuid)
         # Change contents to fake_obj_devprofs[1] except uuid
         obj_devprof = fake_obj_devprofs[1]
         obj_devprof['uuid'] = uuid
         with mock.patch.object(self.dbapi,
                                'device_profile_update',
                                autospec=True) as mock_dp_update:
             mock_dp_update.return_value = db_devprof
             obj_devprof.save(self.context)
             mock_dp_get.assert_called_once_with(self.context, uuid)
             mock_dp_update.assert_called_once()