Exemple #1
0
 def test_parse_args(self):
     sys.argv = []
     sys.argv.append("")
     sys.argv.append("-n")
     args = qwifi.parse_args()
     self.assertEqual("Namespace(c='qwifi.conf', n=True)", str(args))
     sys.argv.pop()
     sys.argv.append("-c")
     sys.argv.append("test")
     args = qwifi.parse_args()
     self.assertEqual("Namespace(c='test', n=False)", str(args))
     sys.argv.append("-n")
     args = qwifi.parse_args()
     self.assertEqual("Namespace(c='test', n=True)", str(args))
Exemple #2
0
 def test_main(self):
     #setup
     call(["sudo", "service", "hostapd", "start"])
     os.system("mysql -u " + user + " -p" + password + " -h " + server + " " + database + " < " + "test.sql")
     r = open("qwifi.conf", "r")
     lines = r.readlines()
     r.close()
     sys.argv = []
     sys.argv.append("")
     sys.argv.append("-c")
     sys.argv.append("qwifi.conf")
     qwifi.args = qwifi.parse_args()
     qwifi.parse_config_file("qwifi.conf")
     #launch main
     t = threading.Thread(target=qwifi.main)
     t.start()
     self.assertTrue(t.is_alive())
     time.sleep(5)
     #change config file
     w = open("qwifi.conf", "w+")
     w.writelines([item for item in lines[0:-1]])
     w.write("mode = AP")
     w.close()
     #continue test
     self.assertTrue(t.is_alive())
     time.sleep(5)
     self.assertTrue(t.is_alive())
     qwifi.terminate_service()
     time.sleep(5)#this has to be before assertFalse. Otherwise main may be sleeping while assertFalse is called.
     self.assertFalse(t.is_alive())
     #reset config file
     w = open("qwifi.conf", "w+")
     w.writelines(item for item in lines)
     w.close()