-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Define client workspace to management caches.
- Check cached time of providers.json when it initializes. Refs: #3
- Loading branch information
Showing
5 changed files
with
120 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# flake8: noqa | ||
import subprocess | ||
from pathlib import Path | ||
|
||
import httpx | ||
import pytest | ||
from platformdirs.api import PlatformDirsABC | ||
from pytest_mock import MockerFixture | ||
|
||
|
||
from oembedpy import application | ||
|
||
|
||
@pytest.fixture | ||
def mocked_workspace(monkeypatch, tmp_path): | ||
def _append_app_name_and_version(*arg, **kwargs): | ||
return tmp_path | ||
|
||
monkeypatch.setattr( | ||
PlatformDirsABC, | ||
"_append_app_name_and_version", | ||
_append_app_name_and_version, | ||
) | ||
ws = application.Workspace() | ||
return ws | ||
|
||
|
||
@pytest.mark.skipif("sys.platform != 'linux'") | ||
def test_workspace(): | ||
ws = application.Workspace() | ||
assert ws.cache_dir == Path.home() / ".local" / "share/oembedpy" | ||
|
||
|
||
@pytest.mark.skipif("sys.platform != 'linux'") | ||
class TestForWorkspace: | ||
def test_properties(self, mocked_workspace: application.Workspace, tmp_path): | ||
assert mocked_workspace.cache_dir == tmp_path | ||
|
||
def test_cache_providers_json( | ||
self, mocked_workspace: application.Workspace, tmp_path | ||
): | ||
mocked_workspace.init() | ||
assert (tmp_path / "providers.json").exists() | ||
assert mocked_workspace._registry is not None | ||
|
||
def test_fetch_using_cached_providers_json( | ||
self, mocked_workspace: application.Workspace, mocker: MockerFixture, tmp_path | ||
): | ||
spy = mocker.spy(httpx, "get") | ||
mocked_workspace.init() | ||
assert spy.call_count == 1 | ||
other_workspace = application.Workspace() | ||
other_workspace.init() | ||
assert spy.call_count == 1 | ||
|
||
def test_purge_cached_providers_json( | ||
self, mocked_workspace: application.Workspace, mocker: MockerFixture, tmp_path | ||
): | ||
spy = mocker.spy(httpx, "get") | ||
mocked_workspace.init() | ||
assert spy.call_count == 1 | ||
subprocess.run( | ||
[ | ||
"touch", | ||
"-t", | ||
"200001010000", | ||
(mocked_workspace.cache_dir / "providers.json"), | ||
] | ||
) | ||
other_workspace = application.Workspace() | ||
other_workspace.init() | ||
assert spy.call_count == 2 |