diff --git a/maigret/sites.py b/maigret/sites.py index 62786997..0d8f0a1c 100644 --- a/maigret/sites.py +++ b/maigret/sites.py @@ -357,10 +357,10 @@ class MaigretSite: if not self.engine_obj: return self - self.request_future = None - self.url_regexp = None - - self_copy = copy.deepcopy(self) + self_copy = copy.copy(self) + self_copy.request_future = None + self_copy.url_regexp = None + self_copy = copy.deepcopy(self_copy) engine_data = self_copy.engine_obj and self_copy.engine_obj.site or {} site_data_keys = list(self_copy.__dict__.keys()) diff --git a/tests/test_sites.py b/tests/test_sites.py index be1a09c2..b4b96f54 100644 --- a/tests/test_sites.py +++ b/tests/test_sites.py @@ -119,6 +119,19 @@ def test_site_strip_engine_data(): assert amperka_stripped.json == EXAMPLE_DB['sites']['Amperka'] +def test_saving_database_preserves_site_url_detector(tmp_path): + db = MaigretDatabase() + db.load_from_json(EXAMPLE_DB) + amperka = db.sites[0] + + db.save_to_file(str(tmp_path / 'data.json')) + + assert ( + amperka.detect_username('http://forum.amperka.ru/members/?username=test') + == 'test' + ) + + def test_site_strip_engine_data_with_site_prior_updates(): db = MaigretDatabase() UPDATED_EXAMPLE_DB = dict(EXAMPLE_DB)