def test_count_aggregate_with_zeros(self): assets_num = 2 DataCenterAssetFactory.create_batch(assets_num) graph = GraphFactory( aggregate_type=AggregateType.aggregate_count.id, params=self._get_graph_params({ 'aggregate_expression': 'scmstatuscheck', 'filters': {}, 'labels': 'id', 'series': 'id', }) ) qs = graph.build_queryset() self.assertEqual(qs.count(), assets_num) for item in qs.all(): self.assertEqual(item['series'], 0)
def test_label_works_when_year_grouping(self): self.a_2016 = DataCenterAssetFactory.create_batch( 2, delivery_date='2015-01-01', ) expected = DataCenterAssetFactory.create_batch( 1, delivery_date='2016-01-01', ) self.a_2015 = DataCenterAssetFactory.create_batch( 3, delivery_date='2017-01-01', ) graph = GraphFactory( aggregate_type=AggregateType.aggregate_count.id, params=self._get_graph_params({ 'labels': 'delivery_date|year', }) ) qs = graph.build_queryset() self.assertEqual(qs.get()['series'], len(expected)) self.assertIn('year', qs.get())
def test_should_add_physical_hosts_to_dictionary(self): physical_server = ContentType.objects.get_for_model(DataCenterAsset) self.view.object.children.add(*DataCenterAssetFactory.create_batch(4)) related_objects = {} self.view._add_physical_hosts(related_objects) content_type = { c_t.content_type for c_t in related_objects['physical_hosts'] } self.assertEqual(4, len(related_objects['physical_hosts'])) self.assertEqual(1, len(content_type)) self.assertEqual(physical_server, content_type.pop())
def test_count_aggregate_sum_bool_values(self): assets_num = 2 a, b = DataCenterAssetFactory.create_batch(assets_num) SCMStatusCheckFactory( base_object=a, check_result=SCMCheckResult.scm_ok.id ) SCMStatusCheckFactory( base_object=b, check_result=SCMCheckResult.scm_error.id ) graph = GraphFactory( aggregate_type=AggregateType.aggregate_sum_bool_values.id, params=self._get_graph_params({ 'filters': {}, 'labels': 'id', 'series': 'scmstatuscheck__ok', }) ) qs = graph.build_queryset() self.assertTrue(qs.get(id=a.id)['series'] == 1) self.assertTrue(qs.get(id=b.id)['series'] == 0)
def setUp(self): DataCenterAssetFactory.create_batch(10)