From 27c80c81e07dd9c8bdadff13f802ac0bc15773bd Mon Sep 17 00:00:00 2001 From: Chris Church Date: Thu, 29 Aug 2013 16:22:19 -0400 Subject: [PATCH] Fixes AC-376. Set description to empty string when passed as null to the API. --- awx/main/serializers.py | 5 +++++ awx/main/tests/inventory.py | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/awx/main/serializers.py b/awx/main/serializers.py index e267fd5821..82546d81d9 100644 --- a/awx/main/serializers.py +++ b/awx/main/serializers.py @@ -107,6 +107,11 @@ class BaseSerializer(serializers.ModelSerializer): else: return obj.active + def validate_description(self, attrs, source): + # Description should always be empty string, never null. + attrs[source] = attrs.get(source, None) or '' + return attrs + class UserSerializer(BaseSerializer): password = serializers.WritableField(required=False, default='', diff --git a/awx/main/tests/inventory.py b/awx/main/tests/inventory.py index c7285239ab..8487157631 100644 --- a/awx/main/tests/inventory.py +++ b/awx/main/tests/inventory.py @@ -165,6 +165,24 @@ class InventoryTest(BaseTest): data['organization'] = self.organizations[1].pk self.put(url_a, data, expect=403) + # Via AC-376: + # Create an inventory. Leave the description empty. + # Edit the new inventory, change the Name, click Save. + list_url = reverse('main:inventory_list') + new_data = dict(name='inventory-c', description='', + organization=self.organizations[0].pk) + new_id = max(Inventory.objects.values_list('pk', flat=True)) + 1 + with self.current_user(self.super_django_user): + data = self.post(list_url, data=new_data, expect=201) + self.assertEqual(data['id'], new_id) + self.assertEqual(data['description'], '') + url_c = reverse('main:inventory_detail', args=(new_id,)) + data = self.get(url_c, expect=200) + self.assertEqual(data['description'], '') + data['description'] = None + #data['name'] = 'inventory-a-update2' + self.put(url_c, data, expect=200) + def test_delete_inventory_detail(self): url_a = reverse('main:inventory_detail', args=(self.inventory_a.pk,)) url_b = reverse('main:inventory_detail', args=(self.inventory_b.pk,))