Exemplo n.º 1
0
 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)
Exemplo n.º 2
0
 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)
Exemplo n.º 3
0
 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)
Exemplo n.º 4
0
 def test_convert_to_data_center_asset(self):
     bo_asset = BackOfficeAssetFactory()
     transition = Transition.objects.create(
         name='transition',
         model=TransitionModel.get_for_field(bo_asset, 'status'),
         source=0,
         target=0,
     )
     bo_asset_pk = bo_asset.pk
     hostname = bo_asset.hostname
     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)
     self.assertEqual(dc_asset.rack.id, rack.id)
     self.assertFalse(
         BackOfficeAsset.objects.filter(pk=bo_asset_pk).exists())
     self.assertEqual(dc_asset.hostname, hostname)
Exemplo n.º 5
0
 def test_run_transition_from_string(self):
     transition_name = 'send'
     order = Order.objects.create(status=OrderStatus.to_send.id)
     Transition.objects.create(
         name=transition_name,
         model=TransitionModel.get_for_field(order, 'status'),
         source=[OrderStatus.to_send.id],
         target=OrderStatus.sended.id,
     )
     self.assertTrue(
         run_field_transition(
             [order], transition_name, requester=self.request.user, field='status'
         )
     )
Exemplo n.º 6
0
    def test_forbidden_transition(self):
        order = Order.objects.create()
        transition = Transition.objects.create(
            name='send',
            model=TransitionModel.get_for_field(order, 'status'),
            source=[OrderStatus.to_send.id],
            target=OrderStatus.sended.id,
        )

        self.assertEqual(
            list(order.get_available_transitions_for_status()), []
        )
        with self.assertRaises(TransitionNotAllowedError):
            run_field_transition(
                [order], transition, requester=self.request.user, field='status'
            )
Exemplo n.º 7
0
    def test_available_transitions(self):
        order = Order.objects.create()
        transition = Transition.objects.create(
            name='send',
            model=TransitionModel.get_for_field(order, 'status'),
            source=[OrderStatus.new.id],
            target=OrderStatus.sended.id,
        )

        self.assertEqual(
            list(order.get_available_transitions_for_status()), [transition]
        )

        order.status = OrderStatus.sended.id
        self.assertEqual(
            list(order.get_available_transitions_for_status()), []
        )
Exemplo n.º 8
0
 def test_convert_to_backoffice_asset(self):
     dc_asset = DataCenterAssetFactory()
     transition = Transition.objects.create(
         name='transition',
         model=TransitionModel.get_for_field(dc_asset, 'status'),
         source=0,
         target=0,
     )
     dc_asset_pk = dc_asset.pk
     hostname = dc_asset.hostname
     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)
     self.assertFalse(
         DataCenterAsset.objects.filter(pk=dc_asset_pk).exists())
     self.assertEqual(bo_asset.hostname, hostname)
Exemplo n.º 9
0
 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)
Exemplo n.º 10
0
 def _create_transition(self,
                        model,
                        name,
                        actions=None,
                        field='status',
                        source=None,
                        target=None,
                        **kwargs):
     transition_model = TransitionModel.get_for_field(model, field)
     transition_kwargs = dict(name=name, model=transition_model, **kwargs)
     if source:
         transition_kwargs['source'] = source
     if target:
         transition_kwargs['target'] = target
     transition = Transition.objects.create(**transition_kwargs)
     order_ct = ContentType.objects.get_for_model(Order)
     actions_query_kwargs = {'content_type': order_ct}
     if actions:
         actions_query_kwargs = {'name__in': actions}
         actions = Action.objects.filter(**actions_query_kwargs)
     else:
         actions = Action.actions_for_model(model)
     transition.actions.add(*[x for x in actions])
     return transition_model, transition, actions