Revision 9cec0c17 snf-cyclades-app/synnefo/api/tests/servers.py

b/snf-cyclades-app/synnefo/api/tests/servers.py
161 161

  
162 162
    def test_server_fqdn(self):
163 163
        vm = mfactory.VirtualMachineFactory()
164
        # test no public ip
164
        # Setting set to None
165 165
        with override_settings(settings,
166
                               CYCLADES_SERVERS_FQDN="vm.example.org"):
166
                               CYCLADES_SERVERS_FQDN=None):
167 167
            response = self.myget("servers/%d" % vm.id, vm.userid)
168 168
            server = json.loads(response.content)['server']
169
            self.assertEqual(server["SNF:fqdn"], "")
170
        mfactory.IPv4AddressFactory(nic__machine=vm, network__public=True)
169
            self.assertEqual(server["SNF:fqdn"], None)
170
        # Unformated setting
171 171
        with override_settings(settings,
172 172
                               CYCLADES_SERVERS_FQDN="vm.example.org"):
173 173
            response = self.myget("servers/%d" % vm.id, vm.userid)
174 174
            server = json.loads(response.content)['server']
175 175
            self.assertEqual(server["SNF:fqdn"], "vm.example.org")
176
        # Formatted settings
176 177
        with override_settings(settings, CYCLADES_SERVERS_FQDN=
177 178
                               "snf-%(id)s.vm.example.org"):
178 179
            response = self.myget("servers/%d" % vm.id, vm.userid)
......
187 188
            self.assertEqual(server["SNF:fqdn"], "snf-%d.vm-%d.example.org" %
188 189
                             (vm.id, vm.id))
189 190

  
190
        vm = mfactory.VirtualMachineFactory()
191
        # No setting, no NICs
192
        with override_settings(settings,
193
                               CYCLADES_SERVERS_FQDN=None):
194
            response = self.myget("servers/%d" % vm.id, vm.userid)
195
            server = json.loads(response.content)['server']
196
            self.assertEqual(server["SNF:fqdn"], "")
197

  
198
        # IPv6 NIC
199
        ipv6_address = mfactory.IPv6AddressFactory(nic__machine=vm,
200
                                                   network__public=True)
201
        with override_settings(settings,
202
                               CYCLADES_SERVERS_FQDN=None):
203
            response = self.myget("servers/%d" % vm.id, vm.userid)
204
            server = json.loads(response.content)['server']
205
            self.assertEqual(server["SNF:fqdn"], ipv6_address.address)
206

  
207
        # IPv4 NIC
208
        ipv4_address = mfactory.IPv4AddressFactory(nic__machine=vm,
209
                                                   network__public=True)
210
        with override_settings(settings,
211
                               CYCLADES_SERVERS_FQDN=None):
212
            response = self.myget("servers/%d" % vm.id, vm.userid)
213
            server = json.loads(response.content)['server']
214
            self.assertEqual(server["SNF:fqdn"], ipv4_address.address)
215

  
216 191
    def test_server_port_forwarding(self):
217 192
        vm = mfactory.VirtualMachineFactory()
218 193
        # test None if the server has no public IP

Also available in: Unified diff