mirror of
https://github.com/soxoj/maigret.git
synced 2026-10-16 21:45:11 +02:00
Fix database saves mutating site detectors (#3184)
Co-authored-by: Soxoj <soxoj@protonmail.com>
This commit is contained in:
+4
-4
@@ -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())
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user