File size: 859 Bytes
9116984
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
30
31
import os
import unittest
from unittest.mock import patch

from scripts.upload import modelscope_access


class CachedGitOnly:
    @staticmethod
    def get_token():
        return 'cached-git-credential-not-an-api-token'

    @staticmethod
    def get_cookies():
        return None


class UploadAuthTests(unittest.TestCase):
    def test_cached_git_credential_cannot_authorize_api_upload(self):
        with patch.dict(os.environ, {}, clear=True):
            with self.assertRaisesRegex(RuntimeError, 'API'):
                modelscope_access(CachedGitOnly, 'iximbox')

    def test_explicit_sdk_token_is_selected(self):
        with patch.dict(os.environ, {'MODELSCOPE_API_TOKEN': 'test-sdk-token'}, clear=True):
            self.assertEqual(modelscope_access(CachedGitOnly, 'iximbox'), 'test-sdk-token')


if __name__ == '__main__':
    unittest.main()