File tree Expand file tree Collapse file tree 5 files changed +46
-12
lines changed
Expand file tree Collapse file tree 5 files changed +46
-12
lines changed Original file line number Diff line number Diff line change 1515 KeyValueIntHWM ,
1616)
1717from horizon .client .auth import LoginPassword
18- from horizon .commons .schemas .v1 import NamespaceCreateRequestV1
1918from packaging .version import Version
2019
2120from horizon_hwm_store import HorizonHWMStore
@@ -149,6 +148,11 @@ def file_with_mtime(mtime: datetime) -> Path:
149148
150149
151150@pytest .fixture (params = HWMS_WITH_VALUE )
151+ def hwm_new_values (request ):
152+ return request .param
153+
154+
155+ @pytest .fixture (params = [HWMS_WITH_VALUE [0 ]])
152156def hwm_new_value (request ):
153157 return request .param
154158
@@ -164,16 +168,10 @@ def hwm_store():
164168
165169@pytest .fixture (scope = "module" )
166170def ensure_namespace ():
167- from requests .exceptions import HTTPError
168171
169172 store = HorizonHWMStore (
170173 api_url = HORIZON_URL ,
171174 auth = LoginPassword (login = HORIZON_USER , password = HORIZON_PASSWORD ),
172175 namespace = HORIZON_NAMESPACE ,
173176 )
174-
175- try :
176- store .client .create_namespace (NamespaceCreateRequestV1 (name = HORIZON_NAMESPACE )) # noqa: WPS437
177- except HTTPError :
178- # exception: 409 Client Error: Conflict for url: http://horizon/v1/namespaces/ - namespace already exists
179- pass
177+ store .create_namespace (HORIZON_NAMESPACE )
Original file line number Diff line number Diff line change 1+ Add ``create_namespace `` method
Original file line number Diff line number Diff line change @@ -6,4 +6,4 @@ Horizon HWM Store
66.. currentmodule :: horizon_hwm_store.horizon_hwm_store
77
88.. autoclass :: HorizonHWMStore
9- :members: get_hwm, set_hwm
9+ :members: get_hwm, set_hwm, create_namespace
Original file line number Diff line number Diff line change 1212 HWMCreateRequestV1 ,
1313 HWMPaginateQueryV1 ,
1414 HWMUpdateRequestV1 ,
15+ NamespaceCreateRequestV1 ,
1516 NamespacePaginateQueryV1 ,
1617)
1718
@@ -33,7 +34,7 @@ class HorizonHWMStore(BaseHWMStore):
3334
3435 .. warning::
3536
36- It is required to create namespace in Horizon BEFORE using this class .
37+ It is required to create a namespace BEFORE working with HWMs .
3738
3839 Parameters
3940 ----------
@@ -213,6 +214,24 @@ def check(self) -> HorizonHWMStore:
213214 self ._get_namespace_id ()
214215 return self
215216
217+ def create_namespace (self , name : str ) -> None :
218+ """
219+ Create a namespace.
220+
221+ Parameters
222+ ----------
223+ name : str
224+ The name of the namespace to create.
225+
226+ Examples
227+ --------
228+ .. code:: python
229+
230+ hwm_store.create_namespace(namespace_unique_name)
231+ """
232+ if not self .client .paginate_namespaces (query = NamespacePaginateQueryV1 (name = name )).items :
233+ self .client .create_namespace (NamespaceCreateRequestV1 (name = name ))
234+
216235 # LoginPassword, RetryConfig and TimeoutConfig can be inherited from Pydantic v2 BaseModel
217236 # which is detected by Pydantic v1 as arbitrary type. So we need to parse them manually.
218237 @validator ("auth" , pre = True )
Original file line number Diff line number Diff line change 1414HORIZON_NAMESPACE = os .environ .get ("HORIZON_NAMESPACE" )
1515
1616
17- def test_hwm_store_integration (hwm_store , hwm_new_value , ensure_namespace ):
18- hwm , new_value = hwm_new_value
17+ def test_hwm_store_integration (hwm_store , hwm_new_values , ensure_namespace ):
18+ hwm , new_value = hwm_new_values
1919 assert hwm_store .get_hwm (hwm .name ) is None
2020
2121 hwm_store .set_hwm (hwm )
@@ -65,3 +65,19 @@ def test_hwm_store_unexisting_namespace(hwm_new_value):
6565
6666 with pytest .raises (RuntimeError , match = error_msg ):
6767 store .set_hwm (hwm )
68+
69+
70+ def test_hwm_store_creates_namespace ():
71+ namespace_name = "new_namespace"
72+ store = HorizonHWMStore (
73+ api_url = HORIZON_URL ,
74+ auth = LoginPassword (login = HORIZON_USER , password = HORIZON_PASSWORD ),
75+ namespace = namespace_name ,
76+ )
77+ error_msg = "Namespace 'new_namespace' not found. Please create it before using."
78+
79+ with pytest .raises (RuntimeError , match = error_msg ):
80+ store .get_hwm ("some_hwm_name" )
81+
82+ store .create_namespace (namespace_name )
83+ assert store .get_hwm ("some_hwm_name" ) is None
You can’t perform that action at this time.
0 commit comments