def test_reload_config( default_config: config.Config, default_conf_file: str, default_cache_file: str, subscriptions: List[subscription.Subscription], ) -> None: """Test that reloading gets us new settings.""" write_subs_to_file(subs=subscriptions, out_file=default_cache_file, write_type="cache") write_subs_to_file(subs=subscriptions, out_file=default_conf_file, write_type="config") default_config.load_state() assert default_config.subscriptions == subscriptions new_subscriptions = copy.deepcopy(subscriptions) for sub in new_subscriptions: sub.metadata["artist"] = "foo" write_subs_to_file(subs=new_subscriptions, out_file=default_conf_file, write_type="config") default_config.load_state() assert default_config.subscriptions != subscriptions assert default_config.subscriptions == new_subscriptions
def test_load_only_user_settings( default_config: config.Config, default_conf_file: str, subscriptions: List[subscription.Subscription], ) -> None: """Test that settings can be loaded correctly from just the user settings.""" write_subs_to_file(subs=subscriptions, out_file=default_conf_file, write_type="config") default_config.load_state() assert default_config.subscriptions == subscriptions
def test_load_only_cache( default_config: config.Config, default_cache_file: str, subscriptions: List[subscription.Subscription], ) -> None: """Subscriptions list should be empty if there are cached subs but no subs in settings.""" write_subs_to_file(subs=subscriptions, out_file=default_cache_file, write_type="cache") default_config.load_state() assert default_config.subscriptions == []
def test_non_config_subs_ignore( default_config: config.Config, default_conf_file: str, default_cache_file: str, subscriptions: List[subscription.Subscription], ) -> None: """Subscriptions in cache but not config shouldn't be in subscriptions list.""" write_subs_to_file(subs=subscriptions, out_file=default_cache_file, write_type="cache") write_subs_to_file(subs=subscriptions[0:1], out_file=default_conf_file, write_type="config") default_config.load_state() assert default_config.subscriptions == subscriptions[0:1]
def test_subscriptions_matching( default_config: config.Config, default_conf_file: str, default_cache_file: str, subscriptions: List[subscription.Subscription], ) -> None: """Subscriptions in cache should be matched to subscriptions in config by name or url.""" write_subs_to_file(subs=subscriptions, out_file=default_conf_file, write_type="config") test_urls = ["bababba", "aaaaaaa", "ccccccc"] test_names = ["ffffff", "ggggg", "hhhhhh"] test_nums = [23, 555, 66666] # Change names and urls in subscriptions. They should be able to be matched to config # subscriptions. for i, sub in enumerate(subscriptions): sub.feed_state.latest_entry_number = test_nums[i] if i % 2 == 0: sub.original_url = test_urls[i] sub.url = test_urls[i] else: sub.metadata["name"] = test_names[i] subscriptions[i] = sub write_subs_to_file(subs=subscriptions, out_file=default_cache_file, write_type="cache") default_config.load_state() # The url and name the user gave should be prioritized and the cached url/name discarded. for i, sub in enumerate(default_config.subscriptions): if i % 2 == 0: assert sub.original_url != test_urls[i] assert sub.url != test_urls[i] else: assert sub.metadata["name"] != test_names[i] assert sub.feed_state.latest_entry_number == test_nums[i]
def test_save_works( default_config: config.Config, default_cache_file: str, subscriptions: List[subscription.Subscription], ) -> None: """Test that we can save subscriptions correctly.""" default_config.subscriptions = subscriptions default_config.save_cache() with open(default_cache_file, "rb") as stream: contents = stream.read() unpacked_contents = umsgpack.unpackb(contents) subs = [ subscription.Subscription.decode_subscription(sub) for sub in unpacked_contents ] assert default_config.subscriptions == subs
def _choose_sub(conf: config.Config) -> int: sub_names = conf.get_subs() subscription_options = [] pad_num = len(str(len(sub_names))) for i, sub_name in enumerate(sub_names): subscription_options.append({ "selector": str(i + 1).zfill(pad_num), "prompt": sub_name, "return": i }) return prompt.options("Choose a subscription:", subscription_options)
def _handle_command(command: str, conf: config.Config) -> None: try: if command == config.Command.update.name: conf.update() elif command == config.Command.list.name: conf.list() elif command == config.Command.summarize.name: conf.summarize() input("Press enter when done.") elif command == config.Command.details.name: sub_index = _choose_sub(conf) conf.details(sub_index) input("Press enter when done.") elif command == config.Command.summarize_sub.name: sub_index = _choose_sub(conf) conf.summarize_sub(sub_index) input("Press enter when done.") elif command == config.Command.download_queue.name: sub_index = _choose_sub(conf) conf.download_queue(sub_index) # TODO this needs work. elif command == config.Command.enqueue.name: (sub_index, entry_nums) = _sub_list_command_wrapper(conf, command) conf.enqueue(sub_index, entry_nums) elif command == config.Command.mark.name: (sub_index, entry_nums) = _sub_list_command_wrapper(conf, command) conf.mark(sub_index, entry_nums) elif command == config.Command.unmark.name: (sub_index, entry_nums) = _sub_list_command_wrapper(conf, command) conf.unmark(sub_index, entry_nums) elif command == config.Command.reload_config.name: conf.reload_config() else: LOG.error("Unknown command. Allowed commands are:") LOG.error(config.get_command_help()) return except error.PuckError as e: LOG.error("Encountered error running command.") LOG.error(e.desc)
def _sub_list_command_wrapper(conf: config.Config, command: str) -> Tuple[int, List[int]]: sub_index = _choose_sub(conf) conf.details(sub_index) LOG.info(f"COMMAND - {command}") return (sub_index, _choose_entries())