Example #1
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)
Example #2
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)
    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)
 def test_field_returns_none_if_no_datetime_passed_in(self):
     field = JSTimestampField()
     self.assertEqual(field.to_representation(None), None)
 def test_field_serializes_to_js_time_format(self):
     field = JSTimestampField()
     example_datetime = datetime.datetime(2000, 1, 1, 1, 1, 1, 1)
     self.assertEqual(field.to_representation(example_datetime),
                      946688461000.0)