def test_dataset_filter(self): # Add a 3rd metric we expect not to see. factories.MetricFactory(type='OtherHistogram') response = self.client.get(self.url, data={'ds': self.dataset.id}) metrics = [m['id'] for m in response.json()['metrics']] self.assertItemsEqual(metrics, [self.count_metric.id, self.flag_metric.id])
def setUpTestData(cls): # This will create 3 datasets (1 of which being hidden) with 2 # populations of 1 metric each. def create_collections(dataset, population, flag_metric, count_metric): kwargs = {'dataset': dataset} if population: kwargs['population'] = population count_collection = factories.CollectionFactory(metric=count_metric, **kwargs) factories.PointFactory.create_batch(3, collection=count_collection) flag_collection = factories.CollectionFactory(metric=flag_metric, **kwargs) factories.PointFactory.create_batch(3, collection=flag_collection) count_metric = factories.MetricFactory(type='CountHistogram') flag_metric = factories.MetricFactory(type='FlagHistogram') # Create 2 viewable datasets. dataset_older = factories.DataSetFactory() create_collections(dataset_older, 'control', flag_metric, count_metric) create_collections(dataset_older, None, flag_metric, count_metric) dataset = factories.DataSetFactory() create_collections(dataset, 'control', flag_metric, count_metric) create_collections(dataset, None, flag_metric, count_metric) # Create 1 non-viewable dataset. dataset_hidden = factories.DataSetFactory(display=False) create_collections(dataset_hidden, 'control', flag_metric, count_metric) create_collections(dataset_hidden, None, flag_metric, count_metric) # Save these for use in tests. cls.dataset = dataset cls.dataset_older = dataset_older cls.dataset_hidden = dataset_hidden cls.flag_metric = flag_metric cls.count_metric = count_metric
def test_metric_not_in_collection(self): metric = factories.MetricFactory() url = reverse('metric', args=[metric.id]) response = self.client.get(url) self.assertEqual(response.status_code, 404)
def setUpTestData(cls): # This will create 3 datasets (1 of which being hidden) with 2 # populations of 1 metric each. def collections_and_points(metric, **kwargs): coll = factories.CollectionFactory(metric=metric, **kwargs) factories.PointFactory.create_batch(3, collection=coll) return coll def create_collections(dataset, population, flag_metric, count_metric, create_subgroups=True): kwargs = {'dataset': dataset} if population: kwargs['population'] = population coll = collections_and_points(count_metric, **kwargs) if create_subgroups: kwargs.pop('population', None) for sg in SUBGROUPS: collections_and_points(count_metric, population=coll.population, subgroup=sg, **kwargs) if population: kwargs['population'] = population coll = collections_and_points(flag_metric, **kwargs) if create_subgroups: kwargs.pop('population', None) for sg in SUBGROUPS: collections_and_points(flag_metric, population=coll.population, subgroup=sg, **kwargs) count_metric = factories.MetricFactory(type='CountHistogram') flag_metric = factories.MetricFactory(type='FlagHistogram') # Create 2 viewable datasets. dataset_older = factories.DataSetFactory() create_collections(dataset_older, 'control', flag_metric, count_metric) create_collections(dataset_older, 'chaos', flag_metric, count_metric) dataset = factories.DataSetFactory() create_collections(dataset, 'control', flag_metric, count_metric) create_collections(dataset, 'chaos', flag_metric, count_metric) # Create 1 non-viewable dataset. dataset_hidden = factories.DataSetFactory(display=False) create_collections(dataset_hidden, 'control', flag_metric, count_metric, create_subgroups=False) create_collections(dataset_hidden, 'chaos', flag_metric, count_metric, create_subgroups=False) # Create some stats tied to datasets. for pop in ('control', 'chaos'): factories.StatsFactory(dataset=dataset, metric=None, population=pop) factories.StatsFactory(dataset=dataset, metric=None, population=pop) # Save these for use in tests. cls.dataset = dataset cls.dataset_older = dataset_older cls.dataset_hidden = dataset_hidden cls.flag_metric = flag_metric cls.count_metric = count_metric
def setUpTestData(cls): scalar_metric = factories.MetricFactory(source_name='scalar_metric', type='UintScalar', description='scalar metric') dataset = factories.DataSetFactory() coll = factories.CollectionFactory(metric=scalar_metric, dataset=dataset, population='control') total = 3053.0 data = { 1: 100, 2: 500, 3: 300, 4: 200, 5: 190, 6: 180, 7: 170, 8: 160, 9: 150, 10: 140, 11: 130, 12: 120, 13: 110, 14: 100, 15: 90, 16: 80, 17: 70, 18: 60, 19: 50, 20: 40, 21: 30, 22: 20, 23: 10, 24: 9, 25: 8, 26: 7, 27: 6, 28: 5, 29: 4, 30: 3, 31: 2, 32: 1, 33: 1, 34: 1, 35: 1, 36: 1, 37: 1, 38: 1, 39: 1, 40: 1 } for rank, bucket in enumerate(sorted(data.keys()), 1): count = data[bucket] factories.PointFactory(collection=coll, bucket=bucket, proportion=count / total, count=count, rank=rank) cls.dataset = dataset cls.metric = scalar_metric