Skip to content

Commit 7ab2307

Browse files
committed
Add test that tests the credentials file
1 parent 83e3e44 commit 7ab2307

5 files changed

+52
-1
lines changed

mars-cli/mars_lib/authentication.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ def load_credentials(
5050
if not all(
5151
repo in AuthProvider.available_providers() for repo in credentials.keys()
5252
):
53-
raise ValueError("Credentials dictionary must have keys .")
53+
raise ValueError(
54+
f"Credentials dictionary must have valid keys. Valid keys are:\n{AuthProvider.available_providers()}")
5455

5556
if not all(
5657
key in ["username", "password"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"webin": {
3+
"username": "put-your-username-here",
4+
"password": "put-your-password-here"
5+
},
6+
"metabolights_metadata": {
7+
"username": "put-your-username-here",
8+
"password": "put-your-password-here"
9+
},
10+
"metabolights_data": {
11+
"username": "put-your-username-here",
12+
"password": "put-your-password-here"
13+
},
14+
"blahblahblah_repo": {
15+
"username": "put-your-username",
16+
"password": "put-your-password"
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"webin": {
3+
"username": "put-your-username-here",
4+
"password": "put-your-password-here"
5+
},
6+
"metabolights_metadata": {
7+
"username": "put-your-username-here",
8+
"password": "put-your-password-here"
9+
},
10+
"metabolights_data": {
11+
"username": "put-your-username-here",
12+
"password": "put-your-password-here"
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"webin": {
3+
"username": "put-your-username-here",
4+
"password": "put-your-password-here"
5+
}
6+
}

mars-cli/tests/test_authentication.py

+12
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,15 @@ def test_get_metabolights_auth_token():
5151
# This should be updated to return a more informative error message.
5252
with pytest.raises(HTTPError):
5353
get_metabolights_auth_token(fake_credentials_dict["metabolights_metadata"])
54+
55+
56+
def test_valid_credentials_file():
57+
# Test with a full valid credentials file (all providers)
58+
_max_credentials = load_credentials("tests/fixtures/max_credentials_file.json")
59+
60+
# Test with a partial valid credentials file
61+
_min_credentials = load_credentials("tests/fixtures/min_credentials_file.json")
62+
63+
# Test with a credentials file that has an invalid provider
64+
with pytest.raises(ValueError, match="Credentials dictionary must have valid keys."):
65+
load_credentials("tests/fixtures/bad_credentials_file.json")

0 commit comments

Comments
 (0)