diff --git a/maigret/submit.py b/maigret/submit.py index 440c63cb..73e81bcc 100644 --- a/maigret/submit.py +++ b/maigret/submit.py @@ -660,11 +660,4 @@ class Submitter: final_site = old_site if old_site else stripped_site self.db.update_site(final_site) - # save the db in file - if self.args.db_file != self.settings.sites_db_path: - print( - f"{Fore.GREEN}[+] Maigret DB is saved to {self.args.db}.{Style.RESET_ALL}" - ) - self.db.save_to_file(self.args.db) - return True diff --git a/tests/test_submit.py b/tests/test_submit.py index 7d894d31..54522a8f 100644 --- a/tests/test_submit.py +++ b/tests/test_submit.py @@ -208,6 +208,41 @@ async def test_dialog_selects_status_code_check(settings): assert db.sites[0].check_type == "status_code" +@pytest.mark.asyncio +async def test_dialog_completes_with_parser_built_args(settings, tmp_path): + # The dialog tests above hand Submitter a MagicMock, which answers to any + # attribute name -- a reference to an attribute argparse never builds stays + # invisible there. At runtime Submitter gets the namespace below, where --db + # lands on `db_file`. + from maigret.maigret import setup_arguments_parser + + args = setup_arguments_parser(settings).parse_args( + [ + "--db", + str(tmp_path / "custom_db.json"), + "--submit", + "https://example.com/claimed", + ] + ) + assert args.db_file == str(tmp_path / "custom_db.json") + assert not hasattr(args, "db") + + db = MaigretDatabase() + submitter = Submitter(db, settings, logging.getLogger("test_logger"), args) + submitter.detect_known_engine = AsyncMock(return_value=([], "")) + submitter.extract_username_dialog = MagicMock(return_value="claimed") + submitter.check_features_manually = AsyncMock( + return_value=(None, None, "Found", "unclaimed", 200, 404) + ) + submitter.site_self_check = AsyncMock(return_value={"disabled": False}) + + with patch('builtins.input', side_effect=['y', '', '']): + result = await submitter.dialog("https://example.com/claimed", None) + + assert result is True + assert len(db.sites) == 1 + + @pytest.mark.asyncio async def test_dialog_keeps_message_check_for_redirect(settings): db = MaigretDatabase()