forked from scaleway/scaleway-sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_profile_file.py
77 lines (66 loc) · 2.58 KB
/
test_profile_file.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import logging
import os
import sys
import tempfile
import unittest
import uuid
from unittest import mock
import utils
from scaleway_core.profile import Profile
logger = logging.getLogger()
logger.level = logging.DEBUG
stream_handler = logging.StreamHandler(sys.stdout)
logger.addHandler(stream_handler)
class TestProfileFile(unittest.TestCase):
def setUp(self) -> None:
self.profile_config = Profile(
access_key=utils.random_access_key(),
secret_key=str(uuid.uuid4()),
default_organization_id=str(uuid.uuid4()),
default_project_id=str(uuid.uuid4()),
default_region="fr-par",
default_zone="fr-par-1",
api_url="https://example.com",
)
self.demo_profile_config = Profile(**self.profile_config.__dict__)
self.demo_profile_config.access_key = utils.random_access_key()
self.demo_profile_config.secret_key = str(uuid.uuid4())
config = f"\
access_key: {self.profile_config.access_key}\n\
secret_key: {self.profile_config.secret_key}\n\
default_organization_id: {self.profile_config.default_organization_id}\n\
default_project_id: {self.profile_config.default_project_id}\n\
default_region: {self.profile_config.default_region}\n\
default_zone: {self.profile_config.default_zone}\n\
api_url: {self.profile_config.api_url}\n\
\n\
profiles:\n\
demo:\n\
access_key: {self.demo_profile_config.access_key}\n\
secret_key: {self.demo_profile_config.secret_key}\n\
".strip()
fp = tempfile.NamedTemporaryFile(
delete=False,
prefix="scaleway-sdk-python-profile-",
suffix=".yaml",
)
self.profile_file_name = fp.name
fp.write(config.encode())
fp.close()
def tearDown(self) -> None:
os.unlink(self.profile_file_name)
def test_load_profile_from_config_file(self) -> None:
profile = Profile.from_config_file(self.profile_file_name)
self.assertEqual(profile, self.profile_config)
def test_load_profile_from_config_file_with_profile(self) -> None:
profile = Profile.from_config_file(self.profile_file_name, "demo")
self.assertEqual(profile, self.demo_profile_config)
def test_load_profile_from_config_file_and_env(self) -> None:
with mock.patch.dict(
os.environ,
{
"SCW_SECRET_KEY": "11111111-1111-1111-1111-111111111111",
},
):
profile = Profile.from_config_file_and_env(filepath=self.profile_file_name)
self.assertEqual(profile.secret_key, "11111111-1111-1111-1111-111111111111")