Exemple #1
0
    def test_list_view_filters_by_status(self):
        pending_experiments = []

        # new experiments should be excluded
        for i in range(2):
            ExperimentFactory.create_with_variants()

        # pending experiments should be included
        for i in range(3):
            experiment = ExperimentFactory.create_with_variants()
            experiment.status = experiment.STATUS_REVIEW
            experiment.save()
            pending_experiments.append(experiment)

        response = self.client.get(reverse("experiments-api-list"),
                                   {"status": Experiment.STATUS_REVIEW})
        self.assertEqual(response.status_code, 200)

        json_data = json.loads(response.content)

        serialized_experiments = ExperimentSerializer(
            Experiment.objects.filter(status=Experiment.STATUS_REVIEW),
            many=True).data

        self.assertEqual(serialized_experiments, json_data)
Exemple #2
0
    def test_serializer_outputs_expected_schema(self):
        experiment = ExperimentFactory.create_with_status(
            Experiment.STATUS_COMPLETE, countries=[], locales=[]
        )

        # ensure expected_data has "string" if pref_type is json string
        pref_type = PrefTypeField().to_representation(experiment.pref_type)
        serializer = ExperimentSerializer(experiment)
        expected_data = {
            "analysis": experiment.analysis,
            "analysis_owner": experiment.analysis_owner,
            "client_matching": experiment.client_matching,
            "platform": experiment.platform,
            "end_date": JSTimestampField().to_representation(
                experiment.end_date
            ),
            "experiment_url": experiment.experiment_url,
            "firefox_channel": experiment.firefox_channel,
            "firefox_min_version": experiment.firefox_min_version,
            "firefox_max_version": experiment.firefox_max_version,
            "name": experiment.name,
            "objectives": experiment.objectives,
            "population": experiment.population,
            "population_percent": "{0:.4f}".format(
                experiment.population_percent
            ),
            "pref_branch": experiment.pref_branch,
            "pref_key": experiment.pref_key,
            "pref_type": pref_type,
            "addon_experiment_id": experiment.addon_experiment_id,
            "addon_release_url": experiment.addon_release_url,
            "proposed_start_date": JSTimestampField().to_representation(
                experiment.proposed_start_date
            ),
            "proposed_enrollment": experiment.proposed_enrollment,
            "proposed_duration": experiment.proposed_duration,
            "short_description": experiment.short_description,
            "slug": experiment.slug,
            "start_date": JSTimestampField().to_representation(
                experiment.start_date
            ),
            "status": Experiment.STATUS_COMPLETE,
            "type": experiment.type,
            "variants": [
                ExperimentVariantSerializer(variant).data
                for variant in experiment.variants.all()
            ],
            "locales": [],
            "countries": [],
            "changes": [
                ExperimentChangeLogSerializer(change).data
                for change in experiment.changes.all()
            ],
        }

        self.assertEqual(
            set(serializer.data.keys()), set(expected_data.keys())
        )
        self.assertEqual(serializer.data, expected_data)
Exemple #3
0
 def test_serializer_countries(self):
     country = CountryFactory()
     experiment = ExperimentFactory.create(countries=[country])
     serializer = ExperimentSerializer(experiment)
     self.assertEqual(
         serializer.data["countries"],
         [{"code": country.code, "name": country.name}],
     )
Exemple #4
0
 def test_serializer_locales(self):
     locale = LocaleFactory()
     experiment = ExperimentFactory.create(locales=[locale])
     serializer = ExperimentSerializer(experiment)
     self.assertEqual(
         serializer.data["locales"],
         [{"code": locale.code, "name": locale.name}],
     )
Exemple #5
0
    def test_serializer_outputs_expected_schema(self):
        experiment = ExperimentFactory.create_with_status(
            Experiment.STATUS_COMPLETE)
        serialized = ExperimentSerializer(experiment)
        expected_data = {
            "analysis":
            experiment.analysis,
            "analysis_owner":
            experiment.analysis_owner,
            "client_matching":
            experiment.client_matching,
            "end_date":
            JSTimestampField().to_representation(experiment.end_date),
            "experiment_url":
            experiment.experiment_url,
            "firefox_channel":
            experiment.firefox_channel,
            "firefox_version":
            experiment.firefox_version,
            "name":
            experiment.name,
            "objectives":
            experiment.objectives,
            "population":
            experiment.population,
            "population_percent":
            "{0:.4f}".format(experiment.population_percent),
            "pref_branch":
            experiment.pref_branch,
            "pref_key":
            experiment.pref_key,
            "pref_type":
            experiment.pref_type,
            "proposed_start_date":
            JSTimestampField().to_representation(
                experiment.proposed_start_date),
            "proposed_enrollment":
            experiment.proposed_enrollment,
            "proposed_duration":
            experiment.proposed_duration,
            "short_description":
            experiment.short_description,
            "slug":
            experiment.slug,
            "start_date":
            JSTimestampField().to_representation(experiment.start_date),
            "type":
            experiment.type,
            "variants": [
                ExperimentVariantSerializer(variant).data
                for variant in experiment.variants.all()
            ],
        }

        self.assertEqual(set(serialized.data.keys()),
                         set(expected_data.keys()))
        self.assertEqual(serialized.data, expected_data)
Exemple #6
0
    def test_get_experiment_returns_experiment_info(self):
        user_email = "*****@*****.**"
        experiment = ExperimentFactory.create_with_variants()

        response = self.client.get(
            reverse("experiments-api-detail", kwargs={"slug":
                                                      experiment.slug}),
            **{settings.OPENIDC_EMAIL_HEADER: user_email},
        )

        self.assertEqual(response.status_code, 200)
        json_data = json.loads(response.content)
        serialized_experiment = ExperimentSerializer(experiment).data
        self.assertEqual(serialized_experiment, json_data)
    def test_serializer_outputs_expected_schema(self):
        experiment = ExperimentFactory.create_with_status(
            Experiment.STATUS_COMPLETE)
        serialized = ExperimentSerializer(experiment)
        expected_data = {
            'accept_url':
            experiment.accept_url,
            'client_matching':
            experiment.client_matching,
            'control':
            ExperimentVariantSerializer(experiment.control).data,
            'end_date':
            JSTimestampField().to_representation(experiment.end_date),
            'experiment_slug':
            experiment.experiment_slug,
            'experiment_url':
            experiment.experiment_url,
            'firefox_channel':
            experiment.firefox_channel,
            'firefox_version':
            experiment.firefox_version,
            'name':
            experiment.name,
            'objectives':
            experiment.objectives,
            'population_percent':
            '{0:.4f}'.format(experiment.population_percent),
            'pref_branch':
            experiment.pref_branch,
            'pref_key':
            experiment.pref_key,
            'pref_type':
            experiment.pref_type,
            'project_name':
            experiment.project.name,
            'project_slug':
            experiment.project.slug,
            'reject_url':
            experiment.reject_url,
            'slug':
            experiment.slug,
            'start_date':
            JSTimestampField().to_representation(experiment.start_date),
            'variant':
            ExperimentVariantSerializer(experiment.variant).data,
        }

        self.assertEqual(set(serialized.data.keys()),
                         set(expected_data.keys()))
        self.assertEqual(serialized.data, expected_data)
Exemple #8
0
    def test_list_view_serializes_experiments(self):
        experiments = []

        for i in range(3):
            experiment = ExperimentFactory.create_with_variants()
            experiments.append(experiment)

        response = self.client.get(reverse("experiments-api-list"))
        self.assertEqual(response.status_code, 200)

        json_data = json.loads(response.content)

        serialized_experiments = ExperimentSerializer(Experiment.objects.all(),
                                                      many=True).data

        self.assertEqual(serialized_experiments, json_data)
    def test_list_view_filters_by_project_slug(self):
        project = ProjectFactory.create()
        project_experiments = []

        # another projects experiments should be excluded
        for i in range(2):
            ExperimentFactory.create_with_variants()

        # started project experiments should be included
        for i in range(3):
            experiment = ExperimentFactory.create_with_variants(
                project=project)
            project_experiments.append(experiment)

        response = self.client.get(reverse('experiments-list'),
                                   {'project__slug': project.slug})
        self.assertEqual(response.status_code, 200)

        json_data = json.loads(response.content)

        serialized_experiments = ExperimentSerializer(
            project.experiments.all(), many=True).data

        self.assertEqual(serialized_experiments, json_data)