示例#1
0
    def test_multiple_entries(self):
        response = self.client.post(
            "/api/dnsoverride",
            json=[{
                "hostname": "a.com",
                "ip_address": "1.2.3.4"
            }, {
                "hostname": "b.com",
                "ip_address": "2.3.4.5"
            }],
        )
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.json, {"message": "ok"})

        last_call = sorted(self.dns_overrides_apply.call_args[0][0])
        self.assertEqual(
            last_call,
            sorted([
                DnsOverrideDescriptor(hostname="a.com", ip_address="1.2.3.4"),
                DnsOverrideDescriptor(hostname="b.com", ip_address="2.3.4.5"),
            ]),
        )

        response = self.client.get("/api/dnsoverride")
        self.assertEqual(response.status_code, 200)
        self.assertIn({
            "hostname": "a.com",
            "ip_address": "1.2.3.4"
        }, response.json)
        self.assertIn({
            "hostname": "b.com",
            "ip_address": "2.3.4.5"
        }, response.json)
示例#2
0
    def test_multiple_entries(self):
        response = self.client.post('/api/dnsoverride',
                                    json=[{
                                        'hostname': 'a.com',
                                        'ip_address': '1.2.3.4'
                                    }, {
                                        'hostname': 'b.com',
                                        'ip_address': '2.3.4.5'
                                    }])
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.json, {'message': 'ok'})

        last_call = sorted(self.dns_overrides_apply.call_args[0][0])
        self.assertEqual(
            last_call,
            sorted([
                DnsOverrideDescriptor(hostname='a.com', ip_address='1.2.3.4'),
                DnsOverrideDescriptor(hostname='b.com', ip_address='2.3.4.5')
            ]))

        response = self.client.get('/api/dnsoverride')
        self.assertEqual(response.status_code, 200)
        self.assertIn({
            'hostname': 'a.com',
            'ip_address': '1.2.3.4'
        }, response.json)
        self.assertIn({
            'hostname': 'b.com',
            'ip_address': '2.3.4.5'
        }, response.json)
示例#3
0
    def test_can_be_updated(self):
        response = self.client.post("/api/dnsoverride",
                                    json=[{
                                        "hostname": "a.com",
                                        "ip_address": "1.2.3.4"
                                    }])
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.json, {"message": "ok"})

        self.dns_overrides_apply.assert_called_once_with(
            {DnsOverrideDescriptor(hostname="a.com", ip_address="1.2.3.4")})

        response = self.client.get("/api/dnsoverride")
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.json, [{
            "hostname": "a.com",
            "ip_address": "1.2.3.4"
        }])

        response = self.client.post("/api/dnsoverride",
                                    json=[{
                                        "hostname": "a.com",
                                        "ip_address": "2.3.4.5"
                                    }])
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.json, {"message": "ok"})

        self.dns_overrides_apply.assert_called_with(
            {DnsOverrideDescriptor(hostname="a.com", ip_address="2.3.4.5")})

        response = self.client.get("/api/dnsoverride")
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.json, [{
            "hostname": "a.com",
            "ip_address": "2.3.4.5"
        }])
示例#4
0
    def test_can_be_updated(self):
        response = self.client.post('/api/dnsoverride',
                                    json=[{
                                        'hostname': 'a.com',
                                        'ip_address': '1.2.3.4'
                                    }])
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.json, {'message': 'ok'})

        self.dns_overrides_apply.assert_called_once_with(
            {DnsOverrideDescriptor(hostname='a.com', ip_address='1.2.3.4')})

        response = self.client.get('/api/dnsoverride')
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.json, [{
            'hostname': 'a.com',
            'ip_address': '1.2.3.4'
        }])

        response = self.client.post('/api/dnsoverride',
                                    json=[{
                                        'hostname': 'a.com',
                                        'ip_address': '2.3.4.5'
                                    }])
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.json, {'message': 'ok'})

        self.dns_overrides_apply.assert_called_with(
            {DnsOverrideDescriptor(hostname='a.com', ip_address='2.3.4.5')})

        response = self.client.get('/api/dnsoverride')
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.json, [{
            'hostname': 'a.com',
            'ip_address': '2.3.4.5'
        }])
示例#5
0
 def prepare_descriptor(self, item):
     return DnsOverrideDescriptor(item["hostname"], item["ip_address"])
示例#6
0
 def prepare_descriptor(self, item):
     return DnsOverrideDescriptor(item['hostname'], item['ip_address'])