Use factory instance in tests
MODIFY
tests/conftest.py
tests/conftest.py
from trakt.tv import TVShow
-from plex_trakt_sync.decorators import memoize
+from plex_trakt_sync.factory import Factory
MOCK_DATA_DIR = join_path(dirname(__file__), "mock_data")
+factory = Factory()
def load_mock(name: str):
@@ -19,37 +20,3 @@ def make(cls=None, **kwargs) -> Union[TVShow]:
cls = cls if cls is not None else "object"
# https://stackoverflow.com/a/2827726/2314626
return type(cls, (object,), kwargs)
-
-
-@memoize
-def get_trakt_api():
- from plex_trakt_sync.trakt_api import TraktApi
-
- trakt = TraktApi()
-
- return trakt
-
-
-@memoize
-def get_plex_api():
- from plex_trakt_sync.config import CONFIG
- from plex_trakt_sync.plex_api import PlexApi
- from plexapi.server import PlexServer
-
- url = CONFIG["PLEX_BASEURL"]
- token = CONFIG["PLEX_TOKEN"]
- server = PlexServer(url, token)
- plex = PlexApi(server)
-
- return plex
-
-
-@memoize
-def get_media_factory():
- from plex_trakt_sync.media import MediaFactory
-
- trakt = get_trakt_api()
- plex = get_plex_api()
- mf = MediaFactory(plex, trakt)
-
- return mf

MODIFY
tests/test_batch.py
tests/test_batch.py
#!/usr/bin/env python3 -m pytest
from plex_trakt_sync.trakt_api import TraktBatch
-from tests.conftest import load_mock, get_trakt_api
+from tests.conftest import load_mock, factory
from unittest.mock import Mock
-trakt = get_trakt_api()
+trakt = factory.trakt_api()
def test_batch_size_none():

MODIFY
tests/test_new_agent.py
tests/test_new_agent.py
#!/usr/bin/env python3 -m pytest
from plex_trakt_sync.plex_api import PlexLibraryItem
-from tests.conftest import get_trakt_api, make
+from tests.conftest import make, factory
-trakt = get_trakt_api()
+trakt = factory.trakt_api()
def test_tv_lookup():

MODIFY
tests/test_plex_search.py
tests/test_plex_search.py
#!/usr/bin/env python3 -m pytest
-from tests.conftest import get_plex_api
+from tests.conftest import factory
-plex = get_plex_api()
+plex = factory.plex_api()
def test_plex_search():

MODIFY
tests/test_tv_lookup.py
tests/test_tv_lookup.py
#!/usr/bin/env python3 -m pytest
from plex_trakt_sync.plex_api import PlexLibraryItem
-from tests.conftest import get_trakt_api, make
+from tests.conftest import make, factory
-trakt = get_trakt_api()
+trakt = factory.trakt_api()
def test_tv_lookup():

MODIFY
tests/test_walker.py
tests/test_walker.py
#!/usr/bin/env python3 -m pytest
from plex_trakt_sync.walker import Walker
-from tests.conftest import get_plex_api, get_media_factory
+from tests.conftest import factory
-plex = get_plex_api()
-mf = get_media_factory()
+plex = factory.plex_api()
+mf = factory.media_factory()
def test_walker():

Use factory instance in tests