-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
94 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,36 @@ | ||
import datetime | ||
from urllib import request | ||
|
||
import pytest | ||
|
||
from diracx.core.config import RemoteGitConfigSource | ||
from diracx.core.config import ConfigSource, RemoteGitConfigSource | ||
from diracx.core.config.schema import Config | ||
|
||
DIRACX_URL = "https://github.com/DIRACGrid/diracx-charts/" | ||
# The diracx-chart contains a CS example | ||
TEST_REPO = "git+https://github.com/DIRACGrid/diracx-charts/" | ||
|
||
|
||
@pytest.fixture | ||
def change_default_branch_and_file(monkeypatch): | ||
monkeypatch.setattr("diracx.core.config.DEFAULT_GIT_BRANCH", "master") | ||
def github_is_down(): | ||
try: | ||
|
||
request.urlopen("https://github.com", timeout=1) | ||
return False | ||
except Exception: | ||
return True | ||
|
||
|
||
@pytest.mark.skipif(github_is_down(), reason="Github unavailble") | ||
def test_remote_git_config_source(monkeypatch): | ||
|
||
monkeypatch.setattr( | ||
"diracx.core.config.DEFAULT_CONFIG_FILE", | ||
"k3s/examples/cs.yaml", | ||
) | ||
remote_conf = ConfigSource.create_from_url(backend_url=TEST_REPO) | ||
assert isinstance(remote_conf, RemoteGitConfigSource) | ||
|
||
|
||
def test_remote_git_config_source(change_default_branch_and_file): | ||
RemoteConf = RemoteGitConfigSource(backend_url=DIRACX_URL) | ||
hexsha, modified = RemoteConf.latest_revision() | ||
hexsha, modified = remote_conf.latest_revision() | ||
assert isinstance(hexsha, str) | ||
assert isinstance(modified, datetime.datetime) | ||
result = RemoteConf.read_raw(hexsha, modified) | ||
result = remote_conf.read_raw(hexsha, modified) | ||
assert isinstance(result, Config) | ||
RemoteConf.clear_temp() |