Esempio n. 1
0
 def test_get_by_id_with_projects(self, volume_type_get):
     projects = [models.VolumeTypeProjects(project_id=fake.PROJECT_ID),
                 models.VolumeTypeProjects(project_id=fake.PROJECT2_ID)]
     db_volume_type = fake_volume.fake_db_volume_type(projects=projects)
     volume_type_get.return_value = db_volume_type
     volume_type = objects.VolumeType.get_by_id(self.context,
                                                fake.VOLUME_TYPE_ID)
     db_volume_type['projects'] = [p.project_id for p in projects]
     self._compare(self, db_volume_type, volume_type)
Esempio n. 2
0
    def test_lazy_loading_projects(self, get_mock, get_projects_mock):
        vol_type = fake_volume.fake_db_volume_type(
            qos_specs_id=fake.QOS_SPEC_ID)
        get_mock.return_value = vol_type

        projects = [models.VolumeTypeProjects(project_id=fake.PROJECT_ID),
                    models.VolumeTypeProjects(project_id=fake.PROJECT2_ID)]
        get_projects_mock.return_value = projects

        volume_type = objects.VolumeType.get_by_id(self.context,
                                                   vol_type['id'])
        # Simulate this type has been loaded by a volume get_all method
        del volume_type.projects

        self.assertEqual([p.project_id for p in projects],
                         volume_type.projects)
        get_projects_mock.assert_called_once_with(self.context, vol_type['id'])