Migrate api_clients tests to pytest
This commit is contained in:
parent
e8d5481422
commit
f944eca0a7
4 changed files with 120 additions and 185 deletions
python_apps/api_clients/tests
|
@ -1,33 +1,32 @@
|
|||
import unittest
|
||||
|
||||
import pytest
|
||||
from api_clients.utils import ApcUrl, IncompleteUrl, UrlBadParam
|
||||
|
||||
|
||||
class TestApcUrl(unittest.TestCase):
|
||||
def test_init(self):
|
||||
url = "/testing"
|
||||
u = ApcUrl(url)
|
||||
self.assertEqual(u.base_url, url)
|
||||
@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_params_1(self):
|
||||
u = ApcUrl("/testing/{key}")
|
||||
self.assertEqual(u.params(key="val").url(), "/testing/val")
|
||||
|
||||
def test_params_2(self):
|
||||
u = ApcUrl("/testing/{key}/{api}/more_testing")
|
||||
full_url = u.params(key="AAA", api="BBB").url()
|
||||
self.assertEqual(full_url, "/testing/AAA/BBB/more_testing")
|
||||
def test_apc_url_bad_param():
|
||||
url = ApcUrl("/testing/{key}")
|
||||
with pytest.raises(UrlBadParam):
|
||||
url.params(bad_key="testing")
|
||||
|
||||
def test_params_ex(self):
|
||||
u = ApcUrl("/testing/{key}")
|
||||
with self.assertRaises(UrlBadParam):
|
||||
u.params(bad_key="testing")
|
||||
|
||||
def test_url(self):
|
||||
u = "one/two/three"
|
||||
self.assertEqual(ApcUrl(u).url(), u)
|
||||
|
||||
def test_url_ex(self):
|
||||
u = ApcUrl("/{one}/{two}/three").params(two="testing")
|
||||
with self.assertRaises(IncompleteUrl):
|
||||
u.url()
|
||||
def test_apc_url_incomplete():
|
||||
url = ApcUrl("/{one}/{two}/three").params(two="testing")
|
||||
with pytest.raises(IncompleteUrl):
|
||||
url.url()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue