Restarting the project.
Fixing unit tests. Continuing SyaParser
This commit is contained in:
+20
-20
@@ -1,11 +1,11 @@
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from fastapi import HTTPException
|
||||
from starlette import status
|
||||
|
||||
from client import SheerkaClient, parse_arguments
|
||||
from mockserver import MockServer
|
||||
|
||||
|
||||
# @pytest.mark.skip("too long")
|
||||
class TestSheerkaClient:
|
||||
def test_i_can_start_with_a_default_hostname(self):
|
||||
parsed = parse_arguments([])
|
||||
@@ -41,7 +41,11 @@ class TestSheerkaClient:
|
||||
assert res.message == "Connection refused."
|
||||
|
||||
def test_i_can_manage_when_resource_is_not_found(self):
|
||||
with MockServer([]):
|
||||
mock_response = MagicMock()
|
||||
mock_response.__bool__ = MagicMock(return_value=False)
|
||||
mock_response.text = '{"detail":"Not Found"}'
|
||||
|
||||
with patch("requests.get", return_value=mock_response):
|
||||
client = SheerkaClient("http://localhost", 5000)
|
||||
res = client.check_url()
|
||||
|
||||
@@ -49,29 +53,25 @@ class TestSheerkaClient:
|
||||
assert res.message == '{"detail":"Not Found"}'
|
||||
|
||||
def test_i_can_connect_to_a_server(self):
|
||||
with MockServer([{
|
||||
"path": "/",
|
||||
"response": "Hello world"
|
||||
}]):
|
||||
mock_response = MagicMock()
|
||||
mock_response.__bool__ = MagicMock(return_value=True)
|
||||
mock_response.text = '"Hello world"'
|
||||
|
||||
with patch("requests.get", return_value=mock_response):
|
||||
client = SheerkaClient("http://localhost", 5000)
|
||||
res = client.check_url()
|
||||
|
||||
assert res.status
|
||||
assert res.message == '"Hello world"'
|
||||
|
||||
def test_i_can_manage_when_authentication_fails(self):
|
||||
with MockServer([{
|
||||
"path": "/",
|
||||
"response": "Hello world"
|
||||
}, {
|
||||
"method": "post",
|
||||
"path": "/token",
|
||||
"exception": HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="Incorrect username or password",
|
||||
headers={"WWW-Authenticate": "Bearer"},
|
||||
)
|
||||
}]):
|
||||
mock_response = MagicMock()
|
||||
mock_response.__bool__ = MagicMock(return_value=False)
|
||||
mock_response.json.return_value = {"detail": "Incorrect username or password"}
|
||||
|
||||
with patch("requests.post", return_value=mock_response):
|
||||
client = SheerkaClient("http://localhost", 5000)
|
||||
res = client.connect("username", "wrong_password")
|
||||
|
||||
assert not res.status
|
||||
assert res.message == 'Incorrect username or password'
|
||||
assert res.message == "Incorrect username or password"
|
||||
|
||||
Reference in New Issue
Block a user