def test_args_config(self): argv = [] argv.append("-c") argv.append("/path/to/config") argv.append("--html") argv.append("/path/to/html") argv.append("--scanfs") argv.append("/path/to/scanfs") args = Seedsync._parse_args(argv) self.assertIsNotNone(args) self.assertEqual("/path/to/config", args.config_dir) argv = [] argv.append("--config_dir") argv.append("/path/to/config") argv.append("--html") argv.append("/path/to/html") argv.append("--scanfs") argv.append("/path/to/scanfs") args = Seedsync._parse_args(argv) self.assertIsNotNone(args) self.assertEqual("/path/to/config", args.config_dir) argv = [] with self.assertRaises(SystemExit): Seedsync._parse_args(argv)
def test_args_debug(self): argv = [] argv.append("-c") argv.append("/path/to/config") argv.append("--html") argv.append("/path/to/html") argv.append("--scanfs") argv.append("/path/to/scanfs") argv.append("-d") args = Seedsync._parse_args(argv) self.assertIsNotNone(args) self.assertTrue(args.debug) argv = [] argv.append("-c") argv.append("/path/to/config") argv.append("--debug") argv.append("--html") argv.append("/path/to/html") argv.append("--scanfs") argv.append("/path/to/scanfs") args = Seedsync._parse_args(argv) self.assertIsNotNone(args) self.assertTrue(args.debug) argv = [] argv.append("-c") argv.append("/path/to/config") argv.append("--html") argv.append("/path/to/html") argv.append("--scanfs") argv.append("/path/to/scanfs") args = Seedsync._parse_args(argv) self.assertIsNotNone(args) self.assertFalse(args.debug)
def test_detect_incomplete_config(self): # Test a complete config config = Seedsync._create_default_config() incomplete_value = config.lftp.remote_address config.lftp.remote_address = "value" config.lftp.remote_password = "******" config.lftp.remote_username = "******" config.lftp.remote_path = "value" config.lftp.local_path = "value" config.lftp.remote_path_to_scan_script = "value" self.assertFalse(Seedsync._detect_incomplete_config(config)) # Test incomplete configs config.lftp.remote_address = incomplete_value self.assertTrue(Seedsync._detect_incomplete_config(config)) config.lftp.remote_address = "value" config.lftp.remote_username = incomplete_value self.assertTrue(Seedsync._detect_incomplete_config(config)) config.lftp.remote_username = "******" config.lftp.remote_path = incomplete_value self.assertTrue(Seedsync._detect_incomplete_config(config)) config.lftp.remote_path = "value" config.lftp.local_path = incomplete_value self.assertTrue(Seedsync._detect_incomplete_config(config)) config.lftp.local_path = "value" config.lftp.remote_path_to_scan_script = incomplete_value self.assertTrue(Seedsync._detect_incomplete_config(config)) config.lftp.remote_path_to_scan_script = "value"
def test_args_scanfs(self): sys.argv.append("-c") sys.argv.append("/path/to/config") sys.argv.append("--html") sys.argv.append("/path/to/html") sys.argv.append("--scanfs") sys.argv.append("/path/to/scanfs") args = Seedsync._parse_args() self.assertIsNotNone(args) self.assertEqual("/path/to/scanfs", args.scanfs)
def test_args_html(self): argv = [] argv.append("-c") argv.append("/path/to/config") argv.append("--scanfs") argv.append("/path/to/scanfs") argv.append("--html") argv.append("/path/to/html") args = Seedsync._parse_args(argv) self.assertIsNotNone(args) self.assertEqual("/path/to/html", args.html)
def test_args_logdir(self): sys.argv.append("-c") sys.argv.append("/path/to/config") sys.argv.append("--logdir") sys.argv.append("/path/to/logdir") sys.argv.append("--html") sys.argv.append("/path/to/html") sys.argv.append("--scanfs") sys.argv.append("/path/to/scanfs") args = Seedsync._parse_args() self.assertIsNotNone(args) self.assertEqual("/path/to/logdir", args.logdir) sys.argv = sys.argv[:-8] sys.argv.append("-c") sys.argv.append("/path/to/config") sys.argv.append("--html") sys.argv.append("/path/to/html") sys.argv.append("--scanfs") sys.argv.append("/path/to/scanfs") args = Seedsync._parse_args() self.assertIsNotNone(args) self.assertIsNone(args.logdir)
def test_default_config(self): config = Seedsync._create_default_config() # Test that default config doesn't have any uninitialized values config_dict = config.as_dict() for section, inner_config in config_dict.items(): for key in inner_config: self.assertIsNotNone(inner_config[key], msg="{}.{} is uninitialized".format(section, key)) # Test that default config is a valid config config_dict = config.as_dict() config2 = Config.from_dict(config_dict) config2_dict = config2.as_dict() self.assertEqual(config_dict, config2_dict)