1
0
Fork 0
mirror of https://github.com/morpheus65535/bazarr synced 2024-12-23 00:03:33 +00:00

Fix provider pool updates

This commit is contained in:
Vitiko 2022-10-03 20:44:31 -04:00
parent 0cd89ea0f0
commit 571ffbccf8
2 changed files with 66 additions and 10 deletions

View file

@ -193,11 +193,22 @@ class SZProviderPool(ProviderPool):
# Check if any new provider has been added
updated = providers != self.providers or ban_list != self.ban_list
removed_providers = list(sorted(self.providers - providers))
new_providers = list(sorted(providers - self.providers))
removed_providers = set(sorted(self.providers - providers))
logger.debug("Discarded providers: %s | New providers: %s", self.discarded_providers, providers)
self.discarded_providers.difference_update(providers)
logger.debug("Updated discarded providers: %s", self.discarded_providers)
removed_providers.update(self.discarded_providers)
logger.debug("Removed providers: %s", removed_providers)
self.providers.difference_update(removed_providers)
self.providers.update(list(providers))
# Terminate and delete removed providers from instance
for removed in removed_providers:
logger.debug("Removing provider: %s", removed)
try:
del self[removed]
# If the user has updated the providers but hasn't made any
@ -206,14 +217,6 @@ class SZProviderPool(ProviderPool):
except KeyError:
pass
if updated:
logger.debug("Removed providers: %s", removed_providers)
logger.debug("New providers: %s", new_providers)
self.discarded_providers.difference_update(new_providers)
self.providers.difference_update(removed_providers)
self.providers.update(list(providers))
# self.provider_configs = provider_configs
self.provider_configs.update(provider_configs)

View file

@ -1,5 +1,7 @@
from pathlib import Path
import pytest
from subliminal_patch import core
@ -17,3 +19,54 @@ def test_scan_video_episode(tmpdir):
result = core.scan_video(str(video_path))
assert isinstance(result, core.Episode)
@pytest.fixture
def pool_instance():
yield core.SZProviderPool({"argenteam"}, {})
def test_pool_update_w_nothing(pool_instance):
pool_instance.update({}, {}, [], {})
assert pool_instance.providers == set()
assert pool_instance.discarded_providers == set()
def test_pool_update_w_multiple_providers(pool_instance):
assert pool_instance.providers == {"argenteam"}
pool_instance.update({"argenteam", "subdivx", "subf2m"}, {}, [], {})
assert pool_instance.providers == {"argenteam", "subdivx", "subf2m"}
def test_pool_update_discarded_providers(pool_instance):
assert pool_instance.providers == {"argenteam"}
# Provider was discarded internally
pool_instance.discarded_providers = {"argenteam"}
assert pool_instance.discarded_providers == {"argenteam"}
# Provider is set to be used again
pool_instance.update({"subdivx", "argenteam"}, {}, [], {})
assert pool_instance.providers == {"argenteam", "subdivx"}
# Provider should disappear from discarded providers
assert pool_instance.discarded_providers == set()
def test_pool_update_discarded_providers_2(pool_instance):
assert pool_instance.providers == {"argenteam"}
# Provider was discarded internally
pool_instance.discarded_providers = {"argenteam"}
assert pool_instance.discarded_providers == {"argenteam"}
# Provider is not set to be used again
pool_instance.update({"subdivx"}, {}, [], {})
assert pool_instance.providers == {"subdivx"}
# Provider should not disappear from discarded providers
assert pool_instance.discarded_providers == {"argenteam"}