Exemplo n.º 1
0
 def setUp(self):
     super().setUp()
     self.user = UserFactory(first_name='first_name_1',
                             last_name='last_name_1')
     UserFactory(first_name='first_name_2', last_name='last_name_2')
     self.region = RegionFactory(name='pl')
     RegionFactory(name='de')
Exemplo n.º 2
0
 def setUpClass(cls):
     super().setUpClass()
     cls.user_pl = UserFactory(country=Country.pl)
     cls.region_pl = RegionFactory(name='PL', country=Country.pl)
     cls.region_us = RegionFactory(name='US', country=Country.us)
     cls.region_us_2 = RegionFactory(name='US', country=Country.us)
     cls.category = CategoryFactory(code='PC')
     cls.model = BackOfficeAssetModelFactory(category=cls.category)
Exemplo n.º 3
0
 def setUp(self):  # noqa
     super().setUp()
     self.login_as_user()
     region_pl = RegionFactory(name='pl')
     region_de = RegionFactory(name='de')
     self.licence = LicenceFactory(region=region_pl)
     self.bo_1 = BackOfficeAssetFactory(region=region_pl)
     self.bo_2 = BackOfficeAssetFactory(region=region_de)
Exemplo n.º 4
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.º 5
0
 def create_users(self, region):
     user_model = get_user_model()
     user, _ = user_model.objects.get_or_create(username='******',
                                                is_staff=True,
                                                is_superuser=True)
     user.regions.add(RegionFactory(name=region))
     user.set_password('admin')
     user.save()
Exemplo n.º 6
0
        def add_user_and_group(username, password, group_name, permissions):
            group = GroupFactory(name=group_name)
            for codename in permissions:
                group.permissions.add(
                    Permission.objects.get(codename=codename))

            user = UserFactory(username=username, is_staff=True)
            user.regions.add(RegionFactory())
            user.set_password(password)
            user.groups.add(group)
            user.save()
Exemplo n.º 7
0
 def setUp(self):
     super().setUp()
     self.licence1, self.licence2 = LicenceFactory.create_batch(2)
     region_pl = RegionFactory(name='pl')
     self.licence3 = LicenceFactory(region=region_pl)
     self.base_object = BackOfficeAssetFactory()
     self.base_object2 = BackOfficeAssetFactory(region=region_pl)
     LicenceUser.objects.create(licence=self.licence1, user=self.user1)
     BaseObjectLicence.objects.create(
         licence=self.licence2, base_object=self.base_object
     )
Exemplo n.º 8
0
        def add_user_and_group(username, password, group_name,
                               permission_models):
            group = GroupFactory(name=group_name)
            for permision_model in permission_models:
                for perm in Permission.objects.filter(
                        content_type=ContentType.objects.get_by_natural_key(
                            *permision_model.split('.'))):
                    group.permissions.add(perm)

            user = UserFactory(username=username, is_staff=True)
            user.regions.add(RegionFactory())
            user.set_password(password)
            user.groups.add(group)
            user.save()
Exemplo n.º 9
0
 def test_convert_to_backoffice_asset(self):
     dc_asset = DataCenterAssetFactory()
     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
     )
     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.º 10
0
    def test_class_access_card_test_case(self):
        region = RegionFactory()

        access_card = {
            'status': "in use",
            'visual_number': '654321',
            'system_number': 'F9876DSGV',
            'notes': 'test note',
            'issue_date': '2020-01-02',
            'region': region.id
        }
        url = reverse('accesscard-list')
        response = self.client.post(url, data=access_card)
        self.assertEqual(status.HTTP_201_CREATED, response.status_code)

        for field in access_card:
            self.assertEqual(response.data[field], access_card[field])
Exemplo n.º 11
0
 def test_reversion_history_for_intermediary_model(self):
     region_pl = RegionFactory()
     bo_asset = BackOfficeAssetFactory(region=region_pl)
     licence = LicenceFactory(region=region_pl)
     url = reverse('baseobjectlicence-list')
     response  = self.client.post(url, data={
         'base_object': bo_asset.id,
         'licence': licence.id
     })
     base_object_licence = BaseObjectLicence.objects.get(
         pk=response.data['id']
     )
     history = reversion.get_for_object(base_object_licence)
     self.assertEqual(len(history), 1)
     self.assertIn(
         '"licence": {}'.format(licence.id), history[0].serialized_data
     )
Exemplo n.º 12
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.º 13
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.º 14
0
 def setUp(self):
     super().setUp()
     self.region_pl = RegionFactory(name='pl')
     self.region_de = RegionFactory(name='de')
     self.licence_de = LicenceFactory(region=self.region_de)
     self.bo_asset = BackOfficeAssetFactory(region=self.region_pl)
Exemplo n.º 15
0
 def setUpClass(cls):
     super().setUpClass()
     cls.region_pl = RegionFactory(name='PL', country=Country.pl)
     cls.region_pl.country = Country.pl
     cls.region_pl.save()