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 generate_back_office(self): self.stdout.write('Generating Back Office assets') back_office_status = BackOfficeAssetStatus() status_count = len(back_office_status) per_page = self.object_limit / status_count parent_category = CategoryFactory(name='BACK OFFICE', imei_required=False) for i in range(3): ProfitCenterFactory() for status_id, name in back_office_status: for i in range(int(per_page)): BackOfficeAssetFactory( status=status_id, user=self.get_user(), owner=self.get_user(), model=BackOfficeAssetModelFactory(category=CategoryFactory( parent=parent_category))) BackOfficeAssetFactory(status=status_id, user=self.get_user(), owner=self.get_user(), model=BackOfficeAssetModelFactory( category=CategoryFactory( name='Mobile Phone', imei_required=True, parent=parent_category), name='Phone'), imei=get_imei(15))
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)
def generate_transitions(self): self.stdout.write('Generating Transitions') def add_transition(content_type, name, source, target, actions): transition, _ = Transition.objects.get_or_create( model=TransitionModel.objects.get(content_type=content_type), name=name, source=source, target=target) for action in actions: transition.actions.add( Action.objects.get(name=action, content_type=content_type)) report = Report.objects.create(name='release') language = ReportLanguage.objects.create(name='en', default=True) report_template = ReportTemplate.objects.create(language=language, default=True, report=report) with open( os.path.join(settings.BASE_DIR, 'data_importer/data/release.odt'), 'rb') as f: report_template.template.save('release.odt', File(f)) bo_content_type = ContentType.objects.get_for_model(BackOfficeAsset) add_transition(bo_content_type, 'Deploy', [ BackOfficeAssetStatus.new.id, BackOfficeAssetStatus.in_progress.id, BackOfficeAssetStatus.waiting_for_release.id, BackOfficeAssetStatus.used.id, BackOfficeAssetStatus.loan.id, BackOfficeAssetStatus.damaged.id, BackOfficeAssetStatus.in_service.id, BackOfficeAssetStatus.installed.id, BackOfficeAssetStatus.free.id, BackOfficeAssetStatus.reserved.id ], BackOfficeAssetStatus.in_progress.id, ['assign_licence', 'assign_user', 'assign_owner']) add_transition(bo_content_type, 'Release asset', [ BackOfficeAssetStatus.new.id, BackOfficeAssetStatus.in_progress.id, BackOfficeAssetStatus.waiting_for_release.id, BackOfficeAssetStatus.free.id, BackOfficeAssetStatus.reserved.id ], BackOfficeAssetStatus.used.id, [ 'assign_user', 'assign_owner', 'assign_warehouse', 'release_report' ]) add_transition(bo_content_type, 'Loan asset', [ BackOfficeAssetStatus.new.id, BackOfficeAssetStatus.in_progress.id, BackOfficeAssetStatus.waiting_for_release.id, BackOfficeAssetStatus.free.id, BackOfficeAssetStatus.reserved.id ], BackOfficeAssetStatus.loan.id, [ 'assign_loan_end_date', 'assign_user', 'assign_owner', 'assign_warehouse', 'assign_task_url' ]) add_transition(bo_content_type, 'Buyout', [i[0] for i in BackOfficeAssetStatus()], BackOfficeAssetStatus.liquidated.id, [ 'assign_task_url', 'assign_warehouse', 'assign_warehouse', 'unassign_licences', 'unassign_loan_end_date', 'unassign_owner', ]) dc_content_type = ContentType.objects.get_for_model(DataCenterAsset) add_transition(dc_content_type, 'Change rack', [ DataCenterAssetStatus.free.id, DataCenterAssetStatus.new.id, DataCenterAssetStatus.to_deploy.id, ], DataCenterAssetStatus.used.id, ['change_rack'])