Skip to content

Commit

Permalink
Fix bug creating remote config with a boolean initial value
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewelwell committed Sep 18, 2019
1 parent d027bdb commit 8e218c1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/features/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ class Meta:
fields = "__all__"
read_only_fields = ('feature_segments',)

def to_internal_value(self, data):
if data.get('initial_value'):
data['initial_value'] = str(data.get('initial_value'))
return super(CreateFeatureSerializer, self).to_internal_value(data)

def create(self, validated_data):
if Feature.objects.filter(project=validated_data['project'], name__iexact=validated_data['name']).exists():
raise serializers.ValidationError("Feature with that name already exists for this "
Expand Down
12 changes: 9 additions & 3 deletions src/features/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,23 @@ def test_should_create_feature_states_with_integer_value_when_feature_created(se
def test_should_create_feature_states_with_boolean_value_when_feature_created(self):
# Given - set up data
default_value = True
feature_name = 'Test feature'
data = {
'name': 'Test feature',
'project': self.project.id,
'initial_value': default_value
}

# When
response = self.client.post(self.project_features_url % self.project.id,
data=self.post_template % ("test feature", self.project.id,
default_value),
data=json.dumps(data),
content_type='application/json')

# Then
assert response.status_code == status.HTTP_201_CREATED

# check feature was created successfully
assert Feature.objects.filter(name="test feature", project=self.project.id).count() == 1
assert Feature.objects.filter(name=feature_name, project=self.project.id).count() == 1

# check feature was added to environment
assert FeatureState.objects.filter(environment=self.environment_1).count() == 1
Expand Down

0 comments on commit 8e218c1

Please sign in to comment.