-
Notifications
You must be signed in to change notification settings - Fork 9
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
10 changed files
with
140 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
requests |
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,3 +1,4 @@ | ||
from ._impl import PathAlias, origin_aliases, rhui_aliases | ||
from ._impl import PathAlias, load_data | ||
from ._impl.cdn_data import CdnData | ||
|
||
__all__ = ["PathAlias", "origin_aliases", "rhui_aliases"] | ||
__all__ = ["PathAlias", "load_data", "CdnData"] |
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,26 @@ | ||
from . import load_data, PathAlias | ||
|
||
|
||
class CdnData(object): | ||
def __init__(self, source=None): | ||
self._source = source | ||
self._data = None | ||
|
||
def data(self): | ||
if not self._data: | ||
self._data = load_data(self._source) | ||
return self._data | ||
|
||
def rhui_aliases(self): | ||
"""Returns: | ||
list[:class:`~PathAlias`] | ||
A list of aliases relating to RHUI paths. | ||
""" | ||
return [PathAlias(**elem) for elem in self.data()["rhui_alias"]] | ||
|
||
def origin_aliases(self): | ||
"""Returns: | ||
list[:class:`~PathAlias`] | ||
A list of aliases relating to origin paths. | ||
""" | ||
return [PathAlias(**elem) for elem in self.data()["origin_alias"]] |
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,14 @@ | ||
import os | ||
import json | ||
from .. import load_data | ||
|
||
|
||
def schema(): | ||
with open( | ||
os.path.join(os.path.dirname(os.path.dirname(__file__)), "schema.json") | ||
) as f: | ||
return json.load(f) | ||
|
||
|
||
def data(source=None): | ||
return load_data(source) |
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,3 +1,4 @@ | ||
pytest | ||
jsonschema | ||
PyYAML | ||
mock |
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,25 @@ | ||
import json | ||
import os | ||
|
||
from cdn_definitions import api | ||
|
||
|
||
def test_load_schema_api(): | ||
schema = api.schema() | ||
with open( | ||
os.path.join( | ||
os.path.dirname(os.path.dirname(__file__)), | ||
"src", | ||
"cdn_definitions", | ||
"schema.json", | ||
) | ||
) as f: | ||
local_schema = json.load(f) | ||
assert schema == local_schema | ||
|
||
|
||
def test_load_data_api(tmpdir): | ||
json_file = tmpdir.join("myfile.json") | ||
json_file.write('{"hello": "world"}') | ||
data = api.data(source=str(json_file)) | ||
assert data == {"hello": "world"} |
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