MCPcopy Create free account
hub / github.com/mlco2/codecarbon / test_save_and_load_credentials

Method test_save_and_load_credentials

tests/cli/test_cli_auth.py:77–91  ·  view source on GitHub ↗
(self, mock_open)

Source from the content-addressed store, hash-verified

75
76 @patch("builtins.open")
77 def test_save_and_load_credentials(self, mock_open):
78 # Save
79 mock_file = MagicMock()
80 mock_open.return_value.__enter__.return_value = mock_file
81 tokens = {"access_token": "a", "refresh_token": "r", "id_token": "i"}
82 auth._save_credentials(tokens)
83 mock_file.write.assert_called()
84 # Load
85 mock_file.read.return_value = json.dumps(tokens)
86 mock_open.return_value.__enter__.return_value = mock_file
87 mock_file.__iter__.return_value = iter([json.dumps(tokens)])
88 mock_file.read.return_value = json.dumps(tokens)
89 with patch("json.load", return_value=tokens):
90 loaded = auth._load_credentials()
91 self.assertEqual(loaded, tokens)
92
93 @patch("codecarbon.cli.auth.requests.get")
94 @patch("codecarbon.cli.auth.KeySet.import_key_set")

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected