diff --git a/awx/api/serializers.py b/awx/api/serializers.py index 0d5718c423..c20431dcfc 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -771,7 +771,7 @@ class HostSerializer(BaseSerializerWithVariables): if port < 1 or port > 65535: raise ValueError except ValueError: - raise serializers.ValidationError('Invalid port specification: %s' % str(port)) + raise serializers.ValidationError(u'Invalid port specification: %s' % unicode(port)) return name, port def validate_name(self, attrs, source): diff --git a/awx/main/tests/inventory.py b/awx/main/tests/inventory.py index 18bd22dfe9..79f9a2c5c0 100644 --- a/awx/main/tests/inventory.py +++ b/awx/main/tests/inventory.py @@ -281,21 +281,23 @@ class InventoryTest(BaseTest): organization = self.organizations[0] ) invalid = dict(name='asdf0.example.com') - new_host_a = dict(name='asdf0.example.com:1022', inventory=inv.pk) + new_host_a = dict(name=u'asdf\u0162.example.com:1022', inventory=inv.pk) new_host_b = dict(name='asdf1.example.com', inventory=inv.pk) new_host_c = dict(name='127.1.2.3:2022', inventory=inv.pk, variables=json.dumps({'who': 'what?'})) new_host_d = dict(name='asdf3.example.com', inventory=inv.pk) - new_host_e = dict(name='asdf4.example.com', inventory=inv.pk) + new_host_e = dict(name=u'asdf4.example.com:\u0162', inventory=inv.pk) host_data0 = self.post(hosts, data=invalid, expect=400, auth=self.get_super_credentials()) host_data0 = self.post(hosts, data=new_host_a, expect=201, auth=self.get_super_credentials()) # Port should be split out into host variables. host_a = Host.objects.get(pk=host_data0['id']) - self.assertEqual(host_a.name, 'asdf0.example.com') + self.assertEqual(host_a.name, u'asdf\u0162.example.com') self.assertEqual(host_a.variables_dict, {'ansible_ssh_port': 1022}) - # an org admin can add hosts + # an org admin can add hosts (try first with invalid port #). + host_data1 = self.post(hosts, data=new_host_e, expect=400, auth=self.get_normal_credentials()) + new_host_e['name'] = u'asdf4.example.com' host_data1 = self.post(hosts, data=new_host_e, expect=201, auth=self.get_normal_credentials()) # a normal user cannot add hosts