1616
1717from . import REGION
1818
19- _UNIQUE_SUFFIX = uuid .uuid4 ().hex
20- APP_NAME = f"smithy-python-integ-test-{ _UNIQUE_SUFFIX } "
21- INDEX_NAME = "integ-test-index"
22- RETRIEVER_NAME = "integ-test-retriever"
19+ # Tags applied to all resources so orphaned resources from interrupted
20+ # test runs can be discovered and cleaned up.
21+ _TAGS = [{"key" : "Purpose" , "value" : "IntegTest" }]
2322
2423# Custom waiter configs for Q Business resources.
2524# Q Business does not provide built-in boto3 waiters.
101100_waiter_model = WaiterModel (_WAITER_CONFIG )
102101
103102
104- def _create_qbusiness_app () -> str :
103+ def _create_qbusiness_app (app_name : str , index_name : str , retriever_name : str ) -> str :
105104 """Create a Q Business application with index and retriever.
106105
106+ Args:
107+ app_name: The name of the Q Business application to create.
108+ index_name: The name of the index to create.
109+ retriever_name: The name of the retriever to create.
110+
107111 Returns:
108112 The application ID.
109113 """
110114 qbusiness = boto3 .client ("qbusiness" , region_name = REGION )
111115
112116 # Create application
113- resp = qbusiness .create_application (displayName = APP_NAME , identityType = "ANONYMOUS" )
117+ resp = qbusiness .create_application (
118+ displayName = app_name , identityType = "ANONYMOUS" , tags = _TAGS
119+ )
114120 app_id = resp ["applicationId" ]
115121 create_waiter_with_client ("ApplicationActive" , _waiter_model , qbusiness ).wait (
116122 applicationId = app_id
117123 )
118124
119125 # Create index
120- resp = qbusiness .create_index (applicationId = app_id , displayName = INDEX_NAME )
126+ resp = qbusiness .create_index (
127+ applicationId = app_id , displayName = index_name , tags = _TAGS
128+ )
121129 index_id = resp ["indexId" ]
122130 create_waiter_with_client ("IndexActive" , _waiter_model , qbusiness ).wait (
123131 applicationId = app_id , indexId = index_id
@@ -126,9 +134,10 @@ def _create_qbusiness_app() -> str:
126134 # Create retriever
127135 resp = qbusiness .create_retriever (
128136 applicationId = app_id ,
129- displayName = RETRIEVER_NAME ,
137+ displayName = retriever_name ,
130138 type = "NATIVE_INDEX" ,
131139 configuration = {"nativeIndexConfiguration" : {"indexId" : index_id }},
140+ tags = _TAGS ,
132141 )
133142 retriever_id = resp ["retrieverId" ]
134143 create_waiter_with_client ("RetrieverActive" , _waiter_model , qbusiness ).wait (
@@ -141,6 +150,8 @@ def _create_qbusiness_app() -> str:
141150def _delete_qbusiness_app (app_id : str | None ) -> None :
142151 """Delete a Q Business application.
143152
153+ Deleting the application cascades to its index and retriever.
154+
144155 Args:
145156 app_id: The application ID to delete, or None if creation failed.
146157 """
@@ -153,9 +164,14 @@ def _delete_qbusiness_app(app_id: str | None) -> None:
153164@pytest .fixture (scope = "session" )
154165def qbusiness_app ():
155166 """Create a Q Business application for the test session and delete it after."""
167+ unique_suffix = uuid .uuid4 ().hex [:16 ]
168+ app_name = f"integ-test-qbusiness-app-{ unique_suffix } "
169+ index_name = f"integ-test-qbusiness-index-{ unique_suffix } "
170+ retriever_name = f"integ-test-qbusiness-retriever-{ unique_suffix } "
171+
156172 app_id = None
157173 try :
158- app_id = _create_qbusiness_app ()
174+ app_id = _create_qbusiness_app (app_name , index_name , retriever_name )
159175 yield app_id
160176 finally :
161177 _delete_qbusiness_app (app_id )
0 commit comments