19
19
20
20
import unittest
21
21
import os
22
- from ibm_platform_services import GlobalCatalogV1
23
22
from ibm_cloud_sdk_core import *
23
+ from ibm_platform_services .global_catalog_v1 import *
24
+ from ibm_cloud_sdk_core .authenticators import IAMAuthenticator
24
25
import pytest
26
+ from jproperties import Properties
27
+ import time
25
28
26
29
configFile = 'global_catalog.env'
27
30
configLoaded = None
31
+ config = {}
28
32
29
33
if os .path .exists (configFile ):
30
- os .environ ['IBM_CREDENTIALS_FILE' ] = configFile
34
+ with open (configFile , "rb" ) as f :
35
+ p = Properties ()
36
+ p .load (f , "utf-8" )
37
+ config ['GLOBAL_CATALOG_APIKEY' ] = p ['GLOBAL_CATALOG_APIKEY' ].data
38
+ config ['GLOBAL_CATALOG_AUTH_URL' ] = p ['GLOBAL_CATALOG_AUTH_URL' ].data
39
+ config ['GLOBAL_CATALOG_URL' ] = p ['GLOBAL_CATALOG_URL' ].data
40
+
31
41
configLoaded = True
32
42
else :
33
43
print ('External configuration was not found, skipping tests...' )
34
44
35
45
class TestGlobalCatalogV1 (unittest .TestCase ):
36
46
37
47
@classmethod
38
- def setUpClass (cls ):
48
+ def setUpClass (self ):
39
49
if not configLoaded :
40
50
raise unittest .SkipTest ('External configuration not available, skipping...' )
41
51
42
- cls .service = GlobalCatalogV1 .new_instance ()
43
- assert cls .service is not None
44
-
45
- cls .config = read_external_sources (GlobalCatalogV1 .DEFAULT_SERVICE_NAME )
46
- assert cls .config is not None
47
- cls .authType = cls .config .get ('AUTH_TYPE' )
48
- cls .apkKey = cls .config .get ('APIKEY' )
49
- cls .authUrl = cls .config .get ('AUTH_URL' )
50
- cls .url = cls .config .get ('URL' )
51
- assert cls .authType is not None
52
- print (cls .authType )
53
- assert cls .apkKey is not None
54
- assert cls .authUrl is not None
55
- print (cls .authUrl )
56
- assert cls .url is not None
57
- print (cls .url )
58
-
59
- cls .defaultEntry = {
60
- 'name' : 'someName' ,
61
- 'id' : 'someId' ,
52
+ apiKey = config ['GLOBAL_CATALOG_APIKEY' ]
53
+ iamUrl = config ['GLOBAL_CATALOG_AUTH_URL' ]
54
+ assert apiKey is not None
55
+ assert iamUrl is not None
56
+ authenticator = IAMAuthenticator (apiKey , url = iamUrl )
57
+
58
+ self .service = GlobalCatalogV1 (authenticator = authenticator )
59
+ self .service .set_service_url (config ['GLOBAL_CATALOG_URL' ])
60
+
61
+ timestamp = int (time .time ())
62
+
63
+ self .defaultEntry = {
64
+ 'name' : 'someName{}' .format (timestamp ),
65
+ 'id' : 'someId{}' .format (timestamp ),
62
66
'active' : False ,
63
67
'kind' : 'service' ,
64
68
'disabled' : False ,
@@ -92,10 +96,10 @@ def setUpClass(cls):
92
96
}
93
97
}
94
98
95
- cls .defaultChildEntry = {
99
+ self .defaultChildEntry = {
96
100
'name' : 'someChildName' ,
97
101
'id' : 'someChildId' ,
98
- 'parent_id' : cls .defaultEntry ['id' ],
102
+ 'parent_id' : self .defaultEntry ['id' ],
99
103
'active' : False ,
100
104
'kind' : 'service' ,
101
105
'disabled' : False ,
@@ -119,9 +123,9 @@ def setUpClass(cls):
119
123
}
120
124
}
121
125
122
- cls .updatedEntry = {
123
- 'name' : 'someNameUpdated' ,
124
- 'id' : 'someId' ,
126
+ self .updatedEntry = {
127
+ 'name' : 'someNameUpdated{}' . format ( timestamp ) ,
128
+ 'id' : 'someId{}' . format ( timestamp ) ,
125
129
'active' : False ,
126
130
'kind' : 'template' ,
127
131
'disabled' : False ,
@@ -145,12 +149,11 @@ def setUpClass(cls):
145
149
}
146
150
}
147
151
148
- def setup (self ):
152
+ def setUp (self ):
149
153
self .service .delete_catalog_entry (id = self .defaultEntry ['id' ])
150
154
151
- @classmethod
152
- def tearDown (cls ):
153
- cls .service .delete_catalog_entry (id = cls .defaultEntry ['id' ])
155
+ def tearDown (self ):
156
+ self .service .delete_catalog_entry (id = self .defaultEntry ['id' ])
154
157
155
158
def test_create_catalog_entry (self ):
156
159
env = self .service .create_catalog_entry (id = self .defaultEntry ['id' ],
0 commit comments