def test_filters_for_longrunning_experiments(self): exp_1 = ExperimentFactory.create( name="Experiment 1", firefox_min_version="67.0b", firefox_max_version="70.0b", ) exp_2 = ExperimentFactory.create( name="Experiment 2", firefox_min_version="64.0", firefox_max_version="69.0", ) ExperimentFactory.create( name="Experiment 3", firefox_min_version="64.0", firefox_max_version="", ) ExperimentFactory.create( name="Experiment 4", firefox_min_version="64.0", firefox_max_version="65.0", ) filter = ExperimentFilterset( {"longrunning": "on"}, request=self.request, queryset=Experiment.objects.all(), ) self.assertEqual(set(filter.qs), set([exp_1, exp_2]))
def test_filters_by_firefox_version(self): exp_1 = ExperimentFactory.create_with_variants( name="Experiment 1", firefox_min_version="58.0", firefox_max_version="62.0", ) exp_2 = ExperimentFactory.create_with_variants( name="Experiment 2", firefox_min_version="59.0", firefox_max_version="60.0", ) ExperimentFactory.create_with_variants( name="Experiment 4", firefox_min_version="62.0", firefox_max_version="68.0", ) exp_3 = ExperimentFactory.create_with_variants( name="Experiment 3", firefox_min_version="59.0", firefox_max_version="", ) ExperimentFactory.create_with_variants( name="Experiment 5", firefox_min_version="54.0", firefox_max_version="56.0", ) filter = ExperimentFilterset({"firefox_version": "59.0"}, queryset=Experiment.objects.all()) self.assertEqual(set(filter.qs), set([exp_1, exp_2, exp_3]))
def test_filters_experiments_with_surveys(self): exp_1 = ExperimentFactory.create_with_variants(survey_required=True) exp_2 = ExperimentFactory.create_with_variants(survey_required=True, review_qa=False) ExperimentFactory.create_with_variants(survey_required=False) filter = ExperimentFilterset({"surveys": "on"}, queryset=Experiment.objects.all()) self.assertEqual(set(filter.qs), set([exp_1, exp_2]))
def test_filters_by_review_in_qa(self): exp_1 = ExperimentFactory.create_with_variants( review_qa_requested=True, review_qa=False) ExperimentFactory.create_with_variants(review_qa_requested=False, review_qa=False) ExperimentFactory.create_with_variants(review_qa_requested=True, review_qa=True) filter = ExperimentFilterset({"in_qa": "on"}, queryset=Experiment.objects.all()) self.assertEqual(set(filter.qs), set([exp_1]))
def test_filters_by_owner(self): owner = UserFactory.create() for i in range(3): ExperimentFactory.create_with_status(Experiment.STATUS_DRAFT, owner=owner) ExperimentFactory.create_with_status(Experiment.STATUS_DRAFT) filter = ExperimentFilterset({"owner": owner.id}, queryset=Experiment.objects.all()) self.assertEqual(set(filter.qs), set(Experiment.objects.filter(owner=owner)))
def test_filters_by_project(self): project = ProjectFactory.create() for i in range(3): ExperimentFactory.create_with_status(Experiment.STATUS_DRAFT, project=project) ExperimentFactory.create_with_status(Experiment.STATUS_DRAFT) filter = ExperimentFilterset({"project": project.id}, queryset=Experiment.objects.all()) self.assertEqual(set(filter.qs), set(Experiment.objects.filter(project=project)))
def test_allows_archived_if_True(self): for i in range(3): ExperimentFactory.create_with_status(Experiment.STATUS_DRAFT, archived=False) for i in range(3): ExperimentFactory.create_with_status(Experiment.STATUS_DRAFT, archived=True) filter = ExperimentFilterset(data={"archived": True}, queryset=Experiment.objects.all()) self.assertEqual(set(filter.qs), set(Experiment.objects.all()))
def test_filters_out_archived_by_default(self): for i in range(3): ExperimentFactory.create_with_status(Experiment.STATUS_DRAFT, archived=False) for i in range(3): ExperimentFactory.create_with_status(Experiment.STATUS_DRAFT, archived=True) filter = ExperimentFilterset(data={}, queryset=Experiment.objects.all()) self.assertEqual(set(filter.qs), set(Experiment.objects.filter(archived=False)))
def test_filters_by_status(self): for i in range(3): ExperimentFactory.create_with_status(Experiment.STATUS_DRAFT) ExperimentFactory.create_with_status(Experiment.STATUS_REVIEW) filter = ExperimentFilterset( {"status": Experiment.STATUS_DRAFT}, queryset=Experiment.objects.all(), ) self.assertEqual( set(filter.qs), set(Experiment.objects.filter(status=Experiment.STATUS_DRAFT)), )
def test_filters_for_paused_experiments(self): exp_1 = ExperimentFactory.create(name="Experiment", is_paused=True, status=Experiment.STATUS_LIVE) ExperimentFactory.create() ExperimentFactory.create() pause_filter = ExperimentFilterset( {"is_paused": "on"}, request=self.request, queryset=Experiment.objects.all(), ) self.assertEqual(list(pause_filter.qs), [exp_1])
def test_filters_for_subscribed_experiments(self): exp_1 = ExperimentFactory.create(name="Experiment", slug="experiment") ExperimentFactory.create() ExperimentFactory.create() exp_1.subscribers.add(self.user) subscribed_filter = ExperimentFilterset( {"subscribed": "on"}, request=self.request, queryset=Experiment.objects.all(), ) self.assertEqual(list(subscribed_filter.qs), [exp_1])
def test_filters_by_firefox_channel(self): include_channel = Experiment.CHANNEL_CHOICES[1][0] exclude_channel = Experiment.CHANNEL_CHOICES[2][0] for i in range(3): ExperimentFactory.create_with_variants( firefox_channel=include_channel) ExperimentFactory.create_with_variants( firefox_channel=exclude_channel) filter = ExperimentFilterset( {"firefox_channel": include_channel}, queryset=Experiment.objects.all(), ) self.assertEqual( set(filter.qs), set(Experiment.objects.filter(firefox_channel=include_channel)), )
def test_filters_by_firefox_version(self): include_version = Experiment.VERSION_CHOICES[1][0] exclude_version = Experiment.VERSION_CHOICES[2][0] for i in range(3): ExperimentFactory.create_with_variants( firefox_version=include_version) ExperimentFactory.create_with_variants( firefox_version=exclude_version) filter = ExperimentFilterset( {"firefox_version": include_version}, queryset=Experiment.objects.all(), ) self.assertEqual( set(filter.qs), set(Experiment.objects.filter(firefox_version=include_version)), )