def test_convert_to_backoffice_asset_uses_default_from_transition(self): target_status_id = BackOfficeAssetStatus.from_name( "new" # status name common for dc_asset and bo_asset ).id dc_asset = DataCenterAssetFactory( status=DataCenterAssetStatus.from_name('damaged')) transition = Transition.objects.create( name='transition', model=TransitionModel.get_for_field(dc_asset, 'status'), source=0, target=target_status_id, ) dc_asset_pk = dc_asset.pk target_status_name = DataCenterAssetStatus.from_id( target_status_id).name DataCenterAsset.convert_to_backoffice_asset( instances=[dc_asset], region=RegionFactory().id, warehouse=WarehouseFactory().id, request=None, transition_id=transition.pk) bo_asset = BackOfficeAsset.objects.get(pk=dc_asset_pk) bo_asset_status_name = BackOfficeAssetStatus.from_id( bo_asset.status).name self.assertEqual(target_status_name, bo_asset_status_name)
def test_convert_to_data_center_asset_uses_default_from_settings(self): target_status_id = DataCenterAssetStatus.from_id( settings.CONVERT_TO_DATACENTER_ASSET_DEFAULT_STATUS_ID).id bo_asset = BackOfficeAssetFactory( status=BackOfficeAssetStatus.from_name('damaged')) transition = Transition.objects.create( name='transition', model=TransitionModel.get_for_field(bo_asset, 'status'), source=0, target=target_status_id, ) bo_asset_pk = bo_asset.pk target_status_name = BackOfficeAssetStatus.from_id( target_status_id).name rack = RackFactory() BackOfficeAsset.convert_to_data_center_asset( instances=[bo_asset], rack=rack.id, service_env=ServiceEnvironmentFactory().id, position=1, model=DataCenterAssetModelFactory().id, request=None, transition_id=transition.pk, ) dc_asset = DataCenterAsset.objects.get(pk=bo_asset_pk) dc_asset_status_name = DataCenterAssetStatus.from_id( dc_asset.status).name self.assertEqual(target_status_name, dc_asset_status_name)
def test_convert_to_data_center_asset_preserves_status_name(self): bo_asset = BackOfficeAssetFactory( status=BackOfficeAssetStatus.from_name('damaged')) transition = Transition.objects.create( name='transition', model=TransitionModel.get_for_field(bo_asset, 'status'), source=0, target=0, ) bo_asset_pk = bo_asset.pk bo_asset_status_name = BackOfficeAssetStatus.from_id( bo_asset.status).name rack = RackFactory() BackOfficeAsset.convert_to_data_center_asset( instances=[bo_asset], rack=rack.id, service_env=ServiceEnvironmentFactory().id, position=1, model=DataCenterAssetModelFactory().id, request=None, transition_id=transition.pk, ) dc_asset = DataCenterAsset.objects.get(pk=bo_asset_pk) dc_asset_status_name = DataCenterAssetStatus.from_id( dc_asset.status).name self.assertEqual(bo_asset_status_name, dc_asset_status_name)
def test_convert_to_backoffice_asset_uses_default_from_settings(self): target_status_id = BackOfficeAssetStatus.from_id( settings.CONVERT_TO_BACKOFFICE_ASSET_DEFAULT_STATUS_ID).id dc_asset = DataCenterAssetFactory( status=DataCenterAssetStatus.from_name('pre_liquidated')) transition = Transition.objects.create( name='transition', model=TransitionModel.get_for_field(dc_asset, 'status'), source=0, target=0, ) dc_asset_pk = dc_asset.pk target_status_name = DataCenterAssetStatus.from_id( target_status_id).name DataCenterAsset.convert_to_backoffice_asset( instances=[dc_asset], region=RegionFactory().id, warehouse=WarehouseFactory().id, request=None, transition_id=transition.pk) bo_asset = BackOfficeAsset.objects.get(pk=dc_asset_pk) bo_asset_status_name = BackOfficeAssetStatus.from_id( bo_asset.status).name self.assertEqual(target_status_name, bo_asset_status_name)