11import logging
22import string
33from random import choices
4+ import typing
45
56import pytest
67import responses
@@ -48,7 +49,11 @@ def _create_notebook(
4849
4950 # file_bytes = file.read() # Read file as bytes
5051 with open ("tests/integration/notebook/sample_file.ipynb" , "rb" ) as file :
51- notebook_response = client .create_notebook (metadata = metadata , content = file )
52+ try :
53+ notebook_response = client .create_notebook (metadata = metadata , content = file )
54+ except ApiException as e :
55+ logging .warning (f"Error creating notebook: { metadata } " )
56+ raise
5257 if cleanup :
5358 notebook_ids .append (notebook_response .id )
5459
@@ -61,6 +66,26 @@ def _create_notebook(
6166 client .delete_notebook (id = notebook_id )
6267
6368
69+ @pytest .fixture ()
70+ def update_notebook (client : NotebookClient ):
71+ """Fixture to return a factory that updates a notebook."""
72+ def _update_notebook (
73+ id : str ,
74+ metadata : NotebookMetadata = None ,
75+ content : typing .BinaryIO = None ,
76+ ) -> NotebookMetadata :
77+
78+ try :
79+ notebook_response = client .update_notebook (id = id , metadata = metadata , content = content )
80+ except ApiException as e :
81+ logging .warning (f"Error updating notebook { id } : { metadata } " )
82+ raise
83+
84+ return notebook_response
85+
86+ return _update_notebook
87+
88+
6489@pytest .mark .enterprise
6590@pytest .mark .integration
6691class TestNotebookClient :
@@ -120,7 +145,7 @@ def test__get_notebook_with_invalid_id__raises_ApiException_NotFound(self, clien
120145 client .get_notebook (id = "invalid_id" )
121146
122147 def test__update_existing_notebook_metadata__update_notebook_metadata_succeeds (
123- self , client : NotebookClient , create_notebook , random_filename
148+ self , client : NotebookClient , create_notebook , update_notebook , random_filename
124149 ):
125150 metadata = NotebookMetadata (name = random_filename )
126151 notebook = create_notebook (metadata = metadata )
@@ -130,21 +155,21 @@ def test__update_existing_notebook_metadata__update_notebook_metadata_succeeds(
130155 notebook .name = new_name
131156 notebook .properties = {"key" : "value" }
132157
133- response = client . update_notebook (id = notebook .id , metadata = notebook )
158+ response = update_notebook (id = notebook .id , metadata = notebook )
134159
135160 assert response .id == notebook .id
136161 assert response .name != random_filename
137162 assert response .name == new_name
138163 assert response .properties == notebook .properties
139164
140165 def test__update_existing_notebook_content__update_notebook_content_succeeds (
141- self , client : NotebookClient , create_notebook , random_filename
166+ self , client : NotebookClient , create_notebook , update_notebook , random_filename
142167 ):
143168 metadata = NotebookMetadata (name = random_filename )
144169 notebook = create_notebook (metadata = metadata )
145170
146171 with open ("tests/integration/notebook/sample_file.ipynb" , "rb" ) as file :
147- response = client . update_notebook (id = notebook .id , content = file )
172+ response = update_notebook (id = notebook .id , content = file )
148173
149174 assert response .id == notebook .id
150175
@@ -156,17 +181,17 @@ def test__update_notebook_metadata_with_invalid_id__raises_ApiException_NotFound
156181 client .update_notebook (id = "invalid_id" , metadata = metadata )
157182
158183 def test__update_notebook_content_with_invalid_file__raises_ApiException_BadRequest (
159- self , client : NotebookClient , create_notebook , random_filename
184+ self , client : NotebookClient , create_notebook , update_notebook , random_filename
160185 ):
161186 metadata = NotebookMetadata (name = random_filename )
162187 notebook = create_notebook (metadata = metadata )
163188
164189 with open ("tests/integration/notebook/test_notebook_client.py" , "rb" ) as file :
165190 with pytest .raises (ApiException , match = "Bad Request" ):
166- client . update_notebook (id = notebook .id , content = file )
191+ update_notebook (id = notebook .id , content = file )
167192
168193 def test__update_notebook_content_with_duplicate_file_name__raises_ApiException_BadRequest (
169- self , client : NotebookClient , create_notebook , random_filename
194+ self , client : NotebookClient , create_notebook , update_notebook , random_filename
170195 ):
171196 metadata = NotebookMetadata (name = random_filename )
172197 notebook = create_notebook (metadata = metadata )
@@ -175,17 +200,17 @@ def test__update_notebook_content_with_duplicate_file_name__raises_ApiException_
175200 create_notebook (metadata = metadata )
176201
177202 with pytest .raises (ApiException , match = "409 Conflict" ):
178- client . update_notebook (id = notebook .id , metadata = notebook )
203+ update_notebook (id = notebook .id , metadata = notebook )
179204
180205 def test__update_notebook_with_invalid_workspace__raises_ApiException_BadRequest (
181- self , client : NotebookClient , create_notebook , random_filename
206+ self , client : NotebookClient , create_notebook , update_notebook , random_filename
182207 ):
183208 metadata = NotebookMetadata (name = random_filename )
184209 notebook = create_notebook (metadata = metadata )
185210
186211 metadata .workspace = "invalid_workspace"
187212 with pytest .raises (ApiException , match = "Bad Request" ):
188- client . update_notebook (id = notebook .id , metadata = metadata )
213+ update_notebook (id = notebook .id , metadata = metadata )
189214
190215 def test__delete_notebook_with_valid_id__notebook_should_delete_successfully (
191216 self , client : NotebookClient , create_notebook , random_filename
0 commit comments