forked from runpod/runpod-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_auth.py
More file actions
29 lines (23 loc) · 806 Bytes
/
test_auth.py
File metadata and controls
29 lines (23 loc) · 806 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""
Test shared functions related to authentication
"""
import importlib
import unittest
from unittest.mock import mock_open, patch
class TestAPIKey(unittest.TestCase):
"""Test the API key"""
# The mocked TOML file
CREDENTIALS = b"""
[default]
api_key = "RUNPOD_API_KEY"
"""
@patch("builtins.open", new_callable=mock_open, read_data=CREDENTIALS)
@patch("runpod.cli.groups.config.functions.os.path.exists", return_value=True)
def test_use_file_credentials(self, _mock_exists, mock_file):
"""
Test that the API key is read from the credentials file
"""
import runpod # pylint: disable=import-outside-toplevel
importlib.reload(runpod)
self.assertEqual(runpod.api_key, "RUNPOD_API_KEY")
assert mock_file.called