def setUp(self): self.work_dir = mkdtemp() self.warned_hosts_filename = ospj(self.work_dir, ALLOWED_WARNED_HOSTS) self.prefs = Prefs() self.prefs._Prefs__data['WORK_DIR'] = self.work_dir self.prefs._Prefs__data['ALLOWED_HOSTS_HOSTNAME_LOOKUP'] = 'false' self.allowed_hosts = AllowedHosts(self.prefs)
def setUp(self): data_dir = ospj(dirname(abspath(__file__)), 'data') # Initialize minimal preferences dict: just enough # for the AllowedHosts constructor prefs = { 'WORK_DIR': data_dir, 'ALLOWED_HOSTS_HOSTNAME_LOOKUP': 'false', } self.allowed_hosts = AllowedHosts(prefs)
class AllowedHostsWarnedHostsTest(unittest.TestCase): """ Not a subclass of AllowedHostsBase since testing the warned hosts functionality is kind of distinct from tracking a set of allowed hosts """ def setUp(self): self.work_dir = mkdtemp() self.warned_hosts_filename = ospj(self.work_dir, ALLOWED_WARNED_HOSTS) self.prefs = Prefs() self.prefs._Prefs__data['WORK_DIR'] = self.work_dir self.prefs._Prefs__data['ALLOWED_HOSTS_HOSTNAME_LOOKUP'] = 'false' self.allowed_hosts = AllowedHosts(self.prefs) def test_no_new_warned_host(self): self.assertFalse(self.allowed_hosts.get_new_warned_hosts()) def test_no_warned_host(self): self.allowed_hosts.load_warned_hosts() self.assertFalse(self.allowed_hosts.get_new_warned_hosts()) def test_load_warned_hosts(self): hosts = ['host1', 'host2'] with open(self.warned_hosts_filename, 'w') as f: for host in hosts: print(host, file=f) self.allowed_hosts.load_warned_hosts() self.assertEqual(set(hosts), set(self.allowed_hosts.warned_hosts)) def test_save_warned_hosts(self): hosts = ['host1', 'host2'] test_string = ''.join(host + '\n' for host in hosts) for host in hosts: self.allowed_hosts.add_warned_host(host) self.allowed_hosts.save_warned_hosts() with open(self.warned_hosts_filename) as f: self.assertEqual(test_string, f.read())
def setUp(self): data_dir = ospj(dirname(abspath(__file__)), 'data') self.prefs = Prefs() self.prefs._Prefs__data['WORK_DIR'] = data_dir self.prefs._Prefs__data['ALLOWED_HOSTS_HOSTNAME_LOOKUP'] = 'false' self.allowed_hosts = AllowedHosts(self.prefs)