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)
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)
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" }])
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' }])
def prepare_descriptor(self, item): return DnsOverrideDescriptor(item["hostname"], item["ip_address"])
def prepare_descriptor(self, item): return DnsOverrideDescriptor(item['hostname'], item['ip_address'])