예제 #1
0
    def test_ratio_aggregation(self):
        service_env = ServiceEnvironmentFactory(service__name='sample-service')
        vulnerability = VulnerabilityFactory(
            patch_deadline=datetime.date(2015, 1, 1)
        )
        for is_patched in [True, False]:
            for _ in range(3):
                dca = DataCenterAssetFactory(service_env=service_env)
                if is_patched:
                    ss = SecurityScanFactory(vulnerabilities=[])
                else:
                    ss = SecurityScanFactory(vulnerabilities=[vulnerability])
                dca.securityscan = ss
                ss.save()
                dca.save()
        graph = GraphFactory(
            aggregate_type=AggregateType.aggregate_ratio.id,
            params={
                'series': ['securityscan__is_patched', 'id'],
                'labels': 'service_env__service__name',
                'filters': {
                    'series__gt': 0,
                }
            }
        )

        qs = graph.build_queryset()
        self.assertEqual(qs.get(), {
            'series': 50,
            'service_env__service__name': 'sample-service'
        })
예제 #2
0
 def _genenrate_dca_with_scan(self, count, date_str):
     gen = []
     for _ in range(count):
         dca = DataCenterAssetFactory()
         sc = SecurityScanFactory(
             last_scan_date=date_str,
         )
         dca.securityscan = sc
         sc.save()
         gen.append(dca)
     return gen