예제 #1
0
    def test_expand_conn_results(self):
        """Test view expand_conn_results."""
        scan_job = ScanJob(scan_type=ScanTask.SCAN_TYPE_CONNECT)
        scan_job.save()
        scan_job.sources.add(self.source)

        # Job in created state
        self.assertEqual(scan_job.status, ScanTask.CREATED)
        tasks = scan_job.tasks.all()
        self.assertEqual(len(tasks), 0)

        # Queue job to run
        scan_job.queue()

        conn_task = scan_job.tasks.first()

        conn_results = JobConnectionResult()
        conn_results.save()
        scan_job.connection_results = conn_results
        scan_job.save()

        conn_result = TaskConnectionResult(source=conn_task.source,
                                           scan_task=conn_task)
        conn_result.save()

        conn_results.results.add(conn_result)
        conn_results.save()

        sys_result = SystemConnectionResult(
            name='Foo',
            credential=self.cred,
            status=SystemConnectionResult.SUCCESS)
        sys_result.save()
        conn_result.systems.add(sys_result)
        conn_result.save()

        conn_results_json = {'results': [{}]}
        expand_conn_results(conn_results, conn_results_json)
        self.assertEqual(conn_results_json['results'][0]['systems'][0]['name'],
                         'Foo')
예제 #2
0
    def test_details(self, start_scan):
        """Get ScanJob result details by primary key."""
        scan_job = ScanJob(scan_type=ScanTask.SCAN_TYPE_INSPECT)
        scan_job.save()
        scan_job.sources.add(self.source)

        # Job in created state
        self.assertEqual(scan_job.status, ScanTask.CREATED)
        tasks = scan_job.tasks.all()
        self.assertEqual(len(tasks), 0)

        # Queue job to run
        scan_job.queue()

        conn_task = scan_job.tasks.first()

        conn_results = JobConnectionResult()
        conn_results.save()
        scan_job.connection_results = conn_results

        conn_result = TaskConnectionResult(source=conn_task.source,
                                           scan_task=conn_task)
        conn_result.save()

        conn_results.results.add(conn_result)
        conn_results.save()

        sys_result = SystemConnectionResult(
            name='Foo',
            credential=self.cred,
            status=SystemConnectionResult.SUCCESS)
        sys_result.save()
        conn_result.systems.add(sys_result)
        conn_result.save()

        inspect_task = scan_job.tasks.all()[1]

        inspect_results = JobInspectionResult()
        inspect_results.save()
        scan_job.inspection_results = inspect_results

        inspect_result = TaskInspectionResult(source=inspect_task.source,
                                              scan_task=inspect_task)
        inspect_result.save()

        inspect_results.results.add(inspect_result)
        inspect_results.save()

        sys_result = SystemInspectionResult(
            name='Foo', status=SystemConnectionResult.SUCCESS)
        sys_result.save()

        fact = RawFact(name='fact_key', value='"fact_value"')
        fact.save()
        sys_result.facts.add(fact)
        sys_result.save()

        inspect_result.systems.add(sys_result)
        inspect_result.save()
        scan_job.save()

        url = reverse('scanjob-detail', args=(scan_job.id, )) + 'results/'
        response = self.client.get(url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        json_response = response.json()
        self.assertIn('connection_results', json_response)
        self.assertIn('inspection_results', json_response)

        self.assertEqual(
            json_response, {
                'connection_results': {
                    'results': [{
                        'source': {
                            'id': 1,
                            'name': 'source1',
                            'source_type': 'network'
                        },
                        'systems': [{
                            'name': 'Foo',
                            'credential': {
                                'id': 1,
                                'name': 'cred1'
                            },
                            'status': 'success'
                        }]
                    }]
                },
                'inspection_results': {
                    'results': [{
                        'source': {
                            'id': 1,
                            'name': 'source1',
                            'source_type': 'network'
                        },
                        'systems': [{
                            'name':
                            'Foo',
                            'status':
                            'success',
                            'facts': [{
                                'name': 'fact_key',
                                'value': 'fact_value'
                            }]
                        }]
                    }]
                }
            })