Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding tests to utils.py #45

Merged
merged 4 commits into from
Apr 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from unittest import TestCase, mock
from unittest import mock
from unittest.mock import patch

import pytest
import requests
from giza.schemas.endpoints import Endpoint, EndpointsList
from giza.schemas.workspaces import Workspace

from giza_actions.utils import get_endpoint_uri, get_workspace_uri
from giza_actions.utils import get_endpoint_uri, get_workspace_uri, read_json


@patch("giza.client.EndpointsClient.list")
Expand Down Expand Up @@ -59,6 +60,25 @@ def test_get_workspace_uri_request_exception(mock_get):
"""
mock_get.side_effect = requests.exceptions.RequestException

TestCase.assertRaises(
TestCase, requests.exceptions.RequestException, get_workspace_uri
)
with pytest.raises(requests.exceptions.RequestException):
get_workspace_uri()


@mock.patch("builtins.open")
@mock.patch("json.load", side_effect=[{"test": "test"}])
def test_read_json_successful(*args):
"""
Tests when file is found
"""
response = read_json("path/to/open")
assert response == {"test": "test"}
assert response is not None


@mock.patch("builtins.open", side_effect=FileNotFoundError)
def test_read_json_file_not_found(mock_open):
"""
Tests when the JSON file is not found.
"""
with pytest.raises(FileNotFoundError):
read_json("/notFound/")
Loading