Esempio n. 1
0
 def setUpClass(cls):
     super().setUpClass()
     cls.back_office_assets = BackOfficeAssetFactory.create_batch(4)
     cls.users = [UserFactory() for i in range(4)]
     cls.delete_users = UserFactory.create_batch(2)
     cls.licence = LicenceFactory()
     cls.licence2 = LicenceFactory()
Esempio n. 2
0
    def test_operation_create(self):
        assignee = UserFactory()
        reporter = UserFactory()

        op_data = {
            'title': 'deadbeef-title',
            'description': 'deadbeef-description',
            'status': 'Open',
            'type': 'Change',
            'ticket_id': 'DEADBEEF-42',
            'assignee': assignee.username,
            'reporter': reporter.username
        }

        resp = self.client.post(
            reverse('operation-list'),
            data=op_data,
            format='json',
        )

        self.assertEqual(resp.status_code, 201)

        op = Operation.objects.get(ticket_id=op_data['ticket_id'])

        self.assertEqual(op_data['title'], op.title)
        self.assertEqual(op_data['description'], op.description)
        self.assertEqual(op_data['assignee'], op.assignee.username)
        self.assertEqual(op_data['reporter'], op.reporter.username)
        self.assertEqual(op_data['type'], op.type.name)
        self.assertEqual(op_data['status'], op.status.name)
Esempio n. 3
0
    def test_if_mail_notification_is_send_when_dca_is_updated_through_gui(
            self):
        old_service = ServiceFactory(name='test')
        new_service = ServiceFactory(name='prod')
        old_service.business_owners.add(UserFactory(email='*****@*****.**'))
        new_service.business_owners.add(UserFactory(email='*****@*****.**'))
        old_service_env = ServiceEnvironmentFactory(service=old_service)
        new_service_env = ServiceEnvironmentFactory(service=new_service)
        # update without triggering signals
        DataCenterAsset.objects.filter(pk=self.dca.pk).update(
            service_env=old_service_env)

        data_custom_fields = {
            'TOTAL_FORMS': 3,
            'INITIAL_FORMS': 0,
        }
        self._update_dca(dca_data={'service_env': new_service_env.id},
                         inline_data=data_custom_fields)

        self.dca.refresh_from_db()

        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(
            'Device has been assigned to Service: {} ({})'.format(
                new_service, self.dca), mail.outbox[0].subject)
        self.assertCountEqual(mail.outbox[0].to,
                              ['*****@*****.**', '*****@*****.**'])
 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')
Esempio n. 5
0
    def setUp(self):
        super().setUp()
        self.warehouse_1 = WarehouseFactory(name='api_test')
        self.user = UserFactory()
        self.officeinfrastructure = OfficeInfrastructureFactory()
        self.bo = BackOfficeAssetFactory(status=BackOfficeAssetStatus.new,
                                         user=UserFactory(),
                                         owner=UserFactory())
        self.licence_1 = LicenceFactory()
        self.licence_2 = LicenceFactory()
        actions = [
            'assign_user', 'assign_licence', 'assign_owner',
            'assign_loan_end_date', 'assign_warehouse',
            'assign_office_infrastructure', 'add_remarks', 'assign_task_url',
            'change_hostname'
        ]
        self.transition_1 = self._create_transition(
            BackOfficeAsset, 'BackOffice', actions, 'status',
            [BackOfficeAssetStatus.new.id],
            BackOfficeAssetStatus.in_progress.id)[1]
        self.transition_2 = self._create_transition(
            BackOfficeAsset,
            'BackOffice_Async',
            actions,
            'status', [BackOfficeAssetStatus.new.id],
            BackOfficeAssetStatus.in_progress.id,
            run_asynchronously=True)[1]
        self.superuser = get_user_model().objects.create_superuser(
            'test', '*****@*****.**', 'test')
        self.api_client = APIClient()
        self.api_client.login(username='******', password='******')

        self.client = Client()
        self.client.login(username='******', password='******')
Esempio n. 6
0
 def test_create_from_file_path_file_name(self):
     with TemporaryDirectory() as tmp_dir_name:
         file_path = os.path.join(tmp_dir_name, 'łóźć.pdf')
         with open(file_path, 'w+') as f:
             f.write('content')
         attachment = Attachment.objects.create_from_file_path(
             file_path, UserFactory()
         )
         attachment.save()
         self.assertEqual(attachment.original_filename, 'lozc.pdf')
Esempio n. 7
0
    def test_is_autocomplete(self):
        request = RequestFactory().get('/')
        request.user = UserFactory(is_superuser=True, is_staff=True)
        self.add_session_to_request(request)
        car_admin = Car2Admin(Car2, ralph_site)
        change_list = car_admin.changelist_view(request)
        filters = change_list.context_data['cl'].get_filters(request)

        self.assertTrue(
            isinstance(filters[0][0], RelatedAutocompleteFieldListFilter))
Esempio n. 8
0
    def test_if_notification_is_send_when_data_center_asset_is_saved(self):
        old_service = ServiceFactory(name='test')
        new_service = ServiceFactory(name='prod')
        old_service.business_owners.add(UserFactory(email='*****@*****.**'))
        new_service.business_owners.add(UserFactory(email='*****@*****.**'))
        self.dca = DataCenterAssetFactory(
            service_env=ServiceEnvironmentFactory(service=old_service))

        # fetch DCA to start with clean state in post_commit signals
        # (ex. invalidate call to notification handler during creating of DCA)
        self.dca = DataCenterAsset.objects.get(pk=self.dca.pk)
        self.dca.service_env = ServiceEnvironmentFactory(service=new_service)
        with transaction.atomic():
            self.dca.save()

        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(
            'Device has been assigned to Service: {} ({})'.format(
                new_service, self.dca), mail.outbox[0].subject)
        self.assertCountEqual(mail.outbox[0].to,
                              ['*****@*****.**', '*****@*****.**'])
Esempio n. 9
0
 def test_update_service_when_service_exist(self):
     service = ServiceFactory(
         business_segment__name='existing area',
         profit_center__name='existing PC',
     )
     service.business_owners.add(UserFactory(username='******'))
     service.technical_owners.add(UserFactory(username='******'))
     ServiceEnvironmentFactory(
         service=service, environment__name='prod'
     )
     data = {
         'uid': service.uid,
         'name': 'New name',
         'status': 'Active',
         'isActive': True,
         'environments': ['dev'],
         'businessOwners': [{'username': '******'}],
         'technicalOwners': [{'username': '******'}],
         'area': {'name': 'new area', 'profitCenter': 'new-PC'},
     }
     response = self._make_request(
         data, settings.HERMES_SERVICE_TOPICS['UPDATE']
     )
     self.assertEqual(response.status_code, 204)
     service.refresh_from_db()
     self.assertEqual(service.name, 'New name')
     self.assertEqual(service.business_segment.name, 'new area')
     self.assertEqual(service.profit_center.name, 'new-PC')
     self.assertCountEqual(
         ['dev'],
         [env.name for env in service.environments.all()]
     )
     self.assertCountEqual(
         ['business_user3'],
         [user.username for user in service.business_owners.all()]
     )
     self.assertCountEqual(
         ['technical_user3'],
         [user.username for user in service.technical_owners.all()]
     )
Esempio n. 10
0
    def handle(self, *args, **options):
        apps = options.get('apps').split(',')
        if 'all' in apps:
            apps = self.all_apps

        if options.get('flush', False):
            self.stdout.write('Flush database..')
            call_command('flush', interactive=False)
            self.stdout.write('Flush finished.')

        self.generate_users_and_groups()

        if 'backoffice' in apps:
            self.generate_back_office()
        if 'datacenter' in apps:
            self.generate_data_center()
        if 'supports' in apps:
            self.generate_support()
        if 'licences' in apps:
            self.generate_licence()
        if 'transitions' in apps:
            self.generate_transitions()

        # Create super user
        root = UserFactory(username='******', is_superuser=True, is_staff=True)
        root.set_password('ralph')
        root.save()

        if options.get('flush', False):
            call_command('sitetree_resync_apps', interactive=False)
        self.stdout.write('done')
Esempio n. 11
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()
Esempio n. 12
0
 def setUp(self):
     super().setUp()
     user = UserFactory()
     back_office = BackOfficeAssetFactory()
     content_type = ContentType.objects.get_for_model(BackOfficeAsset)
     content = str.encode(str(random.random()))
     attachment = Attachment.objects.create(
         file=SimpleUploadedFile('test', content),
         uploaded_by=user,
     )
     self.history = TransitionsHistory.objects.create(
         transition_name='test',
         content_type=content_type,
         source='new',
         target='used',
         object_id=back_office.pk,
         logged_user=user,
         attachment=attachment)
Esempio n. 13
0
    def test_users_through_field(self):
        field = ThroughField(
            through_model=LicenceUser,
            through_from_field_name='licence',
            through_to_field_name='user',
            attribute='users',
            column_name='users',
            widget=UserManyToManyWidget(model=get_user_model()))

        self.assertEqual(self.licence.users.all().count(), 3)
        # Make sure it doesn't touch other licences
        self.assertEqual(self.licence2.users.all().count(), 3)

        # Add and remove
        with self.assertNumQueries(4):
            field.save(self.licence,
                       {'users': ','.join([i.username for i in self.users])})

        self.assertEqual(self.licence.users.all().count(), 4)

        # Not remove
        users = self.users + [UserFactory()]
        with self.assertNumQueries(3):
            field.save(self.licence,
                       {'users': ','.join([i.username for i in users])})

        self.assertEqual(self.licence.users.all().count(), 5)

        # Remove
        with self.assertNumQueries(3):
            field.save(self.licence,
                       {'users': ','.join([i.username for i in users[:4]])})

        self.assertEqual(self.licence.users.all().count(), 4)

        # Update
        with self.assertNumQueries(2):
            field.save(self.licence,
                       {'users': ','.join([i.username for i in users[:4]])})

        self.assertEqual(self.licence.users.all().count(), 4)

        # Make sure it doesn't touch other licences
        self.assertEqual(self.licence2.users.all().count(), 3)
Esempio n. 14
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()
Esempio n. 15
0
 def generate_users(self):
     for i in range(self.object_limit):
         UserFactory()
     return RalphUser.objects.all()
Esempio n. 16
0
 def setUp(self):
     super().setUp()
     self.licence_1 = LicenceFactory(number_bought=3)
     self.licence_2 = LicenceFactory(number_bought=1)
     self.user_1 = UserFactory()
     self.bo_asset = BackOfficeAssetFactory()
Esempio n. 17
0
 def setUpClass(cls):
     super().setUpClass()
     cls.user = UserFactory(is_superuser=True, is_staff=True)
Esempio n. 18
0
 def setUp(self):
     super().setUp()
     for i in range(1, 4):
         UserFactory(username='******'.format(i))
         UserFactory(username='******'.format(i))