コード例 #1
0
 def test_validate_invalid_ip(self):
     """Test validate with false data"""
     dns = DnsmasqRange("fdlkfdl")
     invalid = copy.deepcopy(DEFAULT_CONFIG)
     invalid["dhcp-range"][0]["start"] = "fdjfdd"
     dns._config = invalid
     with self.assertRaises(socket.error):
         dns.validate()
コード例 #2
0
 def test_validate_invalid_ip(self):
     """Test validate with false data"""
     dns = DnsmasqRange("fdlkfdl")
     invalid = copy.deepcopy(DEFAULT_CONFIG)
     invalid["dhcp-range"][0]["start"] = "fdjfdd"
     dns._config = invalid
     with self.assertRaises(socket.error):
         dns.validate()
コード例 #3
0
 def test_update_range(self):
     dns = DnsmasqRange("fdsfddf")
     dns._config = copy.deepcopy(DEFAULT_CONFIG)
     expected = {"interface": "wlan0", "start": "192.192.192.2", "end": "192.192.192.254", "lease_time": "24h"}
     dns.update_range(interface="wlan0", start="192.192.192.2", end="192.192.192.254", lease_time="24h")
     cur_range = dns.get_itf_range("wlan0")
     self.assertEqual(set(expected.keys()), set(cur_range.keys()))
     for expected_key, expected_value in expected.iteritems():
         self.assertEqual(expected_value, cur_range[expected_key])
コード例 #4
0
 def test_write(self):
     self.maxDiff = None
     with tempfile.NamedTemporaryFile() as source:
         dns = DnsmasqRange(source.name)
         dns._config = copy.deepcopy(DEFAULT_CONFIG)
         dns.write()
         source.flush()
         content = source.read().decode("ascii").replace("\n", "")
         for line in DEFAULT_CONTENT.split("\n"):
             if not line or line == "\n":
                 continue
             if line.startswith("#"):
                 self.assertNotIn(line, content)
             else:
                 self.assertIn(line, content)
コード例 #5
0
 def test_write(self):
     self.maxDiff = None
     with tempfile.NamedTemporaryFile() as source:
         dns = DnsmasqRange(source.name)
         dns._config = copy.deepcopy(DEFAULT_CONFIG)
         dns.write()
         source.flush()
         content = source.read().replace("\n", "")
         for line in DEFAULT_CONTENT.split("\n"):
             if not line or line == "\n":
                 continue
             if line.startswith("#"):
                 self.assertNotIn(line, content)
             else:
                 self.assertIn(line, content)
コード例 #6
0
 def test_update_range(self):
     dns = DnsmasqRange("fdsfddf")
     dns._config = copy.deepcopy(DEFAULT_CONFIG)
     expected = {
         "interface": 'wlan0',
         "start": '192.192.192.2',
         "end": '192.192.192.254',
         "lease_time": '24h'
     }
     dns.update_range(interface='wlan0',
                      start='192.192.192.2',
                      end='192.192.192.254',
                      lease_time='24h')
     cur_range = dns.get_itf_range("wlan0")
     self.assertEqual(set(expected.keys()), set(cur_range.keys()))
     for expected_key, expected_value in expected.iteritems():
         self.assertEqual(expected_value, cur_range[expected_key])
コード例 #7
0
 def test_validate_valid(self):
     """Test validate with valid data"""
     dns = DnsmasqRange("fdlkfdl")
     dns._config = copy.deepcopy(DEFAULT_CONFIG)
     self.assertEqual(dns.validate(), True)
コード例 #8
0
 def test_validate_valid(self):
     """Test validate with valid data"""
     dns = DnsmasqRange("fdlkfdl")
     dns._config = copy.deepcopy(DEFAULT_CONFIG)
     self.assertEqual(dns.validate(), True)