chore(api-client): restructure modules
This commit is contained in:
parent
71b3f7f065
commit
8369d55eb9
|
@ -1 +0,0 @@
|
|||
__all__ = ["version1"]
|
|
@ -16,7 +16,7 @@ import urllib.parse
|
|||
import requests
|
||||
|
||||
from ._config import Config
|
||||
from .utils import ApiRequest, RequestProvider
|
||||
from ._utils import ApiRequest, RequestProvider
|
||||
|
||||
AIRTIME_API_VERSION = "1.1"
|
||||
|
|
@ -9,7 +9,7 @@
|
|||
import logging
|
||||
|
||||
from ._config import Config
|
||||
from .utils import RequestProvider
|
||||
from ._utils import RequestProvider
|
||||
|
||||
LIBRETIME_API_VERSION = "2.0"
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
from os import chdir
|
||||
from pathlib import Path
|
||||
|
||||
from setuptools import setup
|
||||
from setuptools import find_packages, setup
|
||||
|
||||
# Change directory since setuptools uses relative paths
|
||||
here = Path(__file__).parent.resolve()
|
||||
|
@ -19,7 +19,7 @@ setup(
|
|||
"Source Code": "https://github.com/libretime/libretime",
|
||||
},
|
||||
license="AGPLv3",
|
||||
packages=["libretime_api_client"],
|
||||
packages=find_packages(),
|
||||
python_requires=">=3.6",
|
||||
install_requires=[
|
||||
"python-dateutil>=2.8.1,<2.9",
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
import pytest
|
||||
|
||||
from libretime_api_client.utils import ApcUrl, IncompleteUrl, UrlBadParam
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"url, params, expected",
|
||||
[
|
||||
("one/two/three", {}, "one/two/three"),
|
||||
("/testing/{key}", {"key": "aaa"}, "/testing/aaa"),
|
||||
(
|
||||
"/more/{key_a}/{key_b}/testing",
|
||||
{"key_a": "aaa", "key_b": "bbb"},
|
||||
"/more/aaa/bbb/testing",
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_apc_url(url: str, params: dict, expected: str):
|
||||
found = ApcUrl(url)
|
||||
assert found.base_url == url
|
||||
assert found.params(**params).url() == expected
|
||||
|
||||
|
||||
def test_apc_url_bad_param():
|
||||
url = ApcUrl("/testing/{key}")
|
||||
with pytest.raises(UrlBadParam):
|
||||
url.params(bad_key="testing")
|
||||
|
||||
|
||||
def test_apc_url_incomplete():
|
||||
url = ApcUrl("/{one}/{two}/three").params(two="testing")
|
||||
with pytest.raises(IncompleteUrl):
|
||||
url.url()
|
|
@ -1,34 +0,0 @@
|
|||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from libretime_api_client.utils import ApcUrl, ApiRequest
|
||||
|
||||
|
||||
def test_api_request_init():
|
||||
u = ApiRequest("request_name", ApcUrl("/test/ing"))
|
||||
assert u.name == "request_name"
|
||||
|
||||
|
||||
def test_api_request_call_json():
|
||||
return_value = {"ok": "ok"}
|
||||
|
||||
read = MagicMock()
|
||||
read.headers = {"content-type": "application/json"}
|
||||
read.json = MagicMock(return_value=return_value)
|
||||
|
||||
with patch("requests.get") as mock_method:
|
||||
mock_method.return_value = read
|
||||
request = ApiRequest("mm", ApcUrl("http://localhost/testing"))()
|
||||
assert request == return_value
|
||||
|
||||
|
||||
def test_api_request_call_html():
|
||||
return_value = "<html><head></head><body></body></html>"
|
||||
|
||||
read = MagicMock()
|
||||
read.headers = {"content-type": "application/html"}
|
||||
read.text = MagicMock(return_value=return_value)
|
||||
|
||||
with patch("requests.get") as mock_method:
|
||||
mock_method.return_value = read
|
||||
request = ApiRequest("mm", ApcUrl("http://localhost/testing"))()
|
||||
assert request.text() == return_value
|
|
@ -1,26 +0,0 @@
|
|||
from libretime_api_client.utils import RequestProvider
|
||||
|
||||
|
||||
def test_request_provider_init():
|
||||
request_provider = RequestProvider(
|
||||
base_url="http://localhost/test",
|
||||
api_key="test_key",
|
||||
endpoints={},
|
||||
)
|
||||
assert len(request_provider.available_requests()) == 0
|
||||
|
||||
|
||||
def test_request_provider_contains():
|
||||
endpoints = {
|
||||
"upload_recorded": "/1/",
|
||||
"update_media_url": "/2/",
|
||||
"list_all_db_files": "/3/",
|
||||
}
|
||||
request_provider = RequestProvider(
|
||||
base_url="http://localhost/test",
|
||||
api_key="test_key",
|
||||
endpoints=endpoints,
|
||||
)
|
||||
|
||||
for endpoint in endpoints:
|
||||
assert endpoint in request_provider.requests
|
|
@ -0,0 +1,97 @@
|
|||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from libretime_api_client._utils import (
|
||||
ApcUrl,
|
||||
ApiRequest,
|
||||
IncompleteUrl,
|
||||
RequestProvider,
|
||||
UrlBadParam,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"url, params, expected",
|
||||
[
|
||||
("one/two/three", {}, "one/two/three"),
|
||||
("/testing/{key}", {"key": "aaa"}, "/testing/aaa"),
|
||||
(
|
||||
"/more/{key_a}/{key_b}/testing",
|
||||
{"key_a": "aaa", "key_b": "bbb"},
|
||||
"/more/aaa/bbb/testing",
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_apc_url(url: str, params: dict, expected: str):
|
||||
found = ApcUrl(url)
|
||||
assert found.base_url == url
|
||||
assert found.params(**params).url() == expected
|
||||
|
||||
|
||||
def test_apc_url_bad_param():
|
||||
url = ApcUrl("/testing/{key}")
|
||||
with pytest.raises(UrlBadParam):
|
||||
url.params(bad_key="testing")
|
||||
|
||||
|
||||
def test_apc_url_incomplete():
|
||||
url = ApcUrl("/{one}/{two}/three").params(two="testing")
|
||||
with pytest.raises(IncompleteUrl):
|
||||
url.url()
|
||||
|
||||
|
||||
def test_api_request_init():
|
||||
u = ApiRequest("request_name", ApcUrl("/test/ing"))
|
||||
assert u.name == "request_name"
|
||||
|
||||
|
||||
def test_api_request_call_json():
|
||||
return_value = {"ok": "ok"}
|
||||
|
||||
read = MagicMock()
|
||||
read.headers = {"content-type": "application/json"}
|
||||
read.json = MagicMock(return_value=return_value)
|
||||
|
||||
with patch("requests.get") as mock_method:
|
||||
mock_method.return_value = read
|
||||
request = ApiRequest("mm", ApcUrl("http://localhost/testing"))()
|
||||
assert request == return_value
|
||||
|
||||
|
||||
def test_api_request_call_html():
|
||||
return_value = "<html><head></head><body></body></html>"
|
||||
|
||||
read = MagicMock()
|
||||
read.headers = {"content-type": "application/html"}
|
||||
read.text = MagicMock(return_value=return_value)
|
||||
|
||||
with patch("requests.get") as mock_method:
|
||||
mock_method.return_value = read
|
||||
request = ApiRequest("mm", ApcUrl("http://localhost/testing"))()
|
||||
assert request.text() == return_value
|
||||
|
||||
|
||||
def test_request_provider_init():
|
||||
request_provider = RequestProvider(
|
||||
base_url="http://localhost/test",
|
||||
api_key="test_key",
|
||||
endpoints={},
|
||||
)
|
||||
assert len(request_provider.available_requests()) == 0
|
||||
|
||||
|
||||
def test_request_provider_contains():
|
||||
endpoints = {
|
||||
"upload_recorded": "/1/",
|
||||
"update_media_url": "/2/",
|
||||
"list_all_db_files": "/3/",
|
||||
}
|
||||
request_provider = RequestProvider(
|
||||
base_url="http://localhost/test",
|
||||
api_key="test_key",
|
||||
endpoints=endpoints,
|
||||
)
|
||||
|
||||
for endpoint in endpoints:
|
||||
assert endpoint in request_provider.requests
|
|
@ -2,7 +2,7 @@ from pathlib import Path
|
|||
|
||||
import pytest
|
||||
|
||||
from libretime_api_client.version2 import AirtimeApiClient
|
||||
from libretime_api_client.v2 import AirtimeApiClient
|
||||
|
||||
|
||||
@pytest.fixture()
|
Loading…
Reference in New Issue