Add project information to experiment serializer fixes #205

This commit is contained in:
Jared Kerim 2017-08-25 14:51:27 -04:00 коммит произвёл Jared Kerim
Родитель 5f58643305
Коммит 4e5726e025
3 изменённых файлов: 12 добавлений и 0 удалений

Просмотреть файл

@ -138,6 +138,13 @@ class Experiment(models.Model):
def is_readonly(self):
return self.status != self.STATUS_CREATED
@property
def experiment_slug(self):
return 'pref-flip-{project_slug}-{experiment_slug}'.format(
project_slug=self.project.slug,
experiment_slug=self.slug,
)
class ExperimentVariant(models.Model):
experiment = models.ForeignKey(

Просмотреть файл

@ -34,6 +34,7 @@ class ExperimentVariantSerializer(serializers.ModelSerializer):
class ExperimentSerializer(serializers.ModelSerializer):
project_name = serializers.ReadOnlyField(source='project.name')
start_date = JSTimestampField()
end_date = JSTimestampField()
variant = ExperimentVariantSerializer()
@ -42,8 +43,10 @@ class ExperimentSerializer(serializers.ModelSerializer):
class Meta:
model = Experiment
fields = (
'project_name',
'name',
'slug',
'experiment_slug',
'firefox_version',
'firefox_channel',
'objectives',

Просмотреть файл

@ -45,8 +45,10 @@ class TestExperimentSerializer(TestCase):
experiment = ExperimentFactory.create_with_variants()
serialized = ExperimentSerializer(experiment)
self.assertEqual(serialized.data, {
'project_name': experiment.project.name,
'name': experiment.name,
'slug': experiment.slug,
'experiment_slug': experiment.experiment_slug,
'firefox_version': experiment.firefox_version,
'firefox_channel': experiment.firefox_channel,
'objectives': experiment.objectives,