@@ -251,12 +251,48 @@ def test_publish_app_saves_and_prints_last_successful_url(
251251 state = json .load (fin )
252252 self .assertEqual (state .get ("last_published_url" ), first_url )
253253
254+ FakePublishingClient .sites = [FakePublishingClient .created_site ]
255+ FakePublishingClient .created_site = None
256+
254257 second_stdout = io .StringIO ()
255258 with patch ("sys.stdout" , second_stdout ):
256259 second_url = model .publish_app (open_browser = False )
257260
258261 self .assertEqual (second_url , first_url )
262+ self .assertIsNone (FakePublishingClient .created_site )
259263 self .assertIn (f"Last published app URL: { first_url } " , second_stdout .getvalue ())
264+ self .assertIn (f"Checking existing app URL: { first_url } " , second_stdout .getvalue ())
265+ self .assertIn (f"Using app URL: { first_url } " , second_stdout .getvalue ())
266+
267+ @patch ("supervised.apps.publisher.generate_machine_learning_slug" , return_value = "feature-lab" )
268+ @patch ("supervised.apps.publisher.PlatformClient" , FakePublishingClient )
269+ @patch ("supervised.apps.publisher.BrowserTokenSession.authenticate" , return_value = "app.jwt.token" )
270+ def test_publish_app_creates_new_site_when_last_published_url_is_missing (
271+ self , _mock_authenticate , _mock_slug
272+ ):
273+ model = self ._trained_model ()
274+
275+ first_stdout = io .StringIO ()
276+ with patch ("sys.stdout" , first_stdout ):
277+ first_url = model .publish_app (open_browser = False )
278+
279+ self .assertEqual (first_url , "https://feature-lab.ismvp.org" )
280+ FakePublishingClient .created_site = None
281+ FakePublishingClient .sites = []
282+
283+ second_stdout = io .StringIO ()
284+ with patch ("sys.stdout" , second_stdout ):
285+ second_url = model .publish_app (open_browser = False )
286+
287+ self .assertEqual (second_url , first_url )
288+ self .assertIsNotNone (FakePublishingClient .created_site )
289+ output = second_stdout .getvalue ()
290+ self .assertIn (f"Checking existing app URL: { first_url } " , output )
291+ self .assertIn (
292+ f"Last published app URL not found on platform: { first_url } " ,
293+ output ,
294+ )
295+ self .assertIn ("Creating app URL" , output )
260296
261297 @patch ("supervised.apps.publisher.PlatformClient" , FakePublishingClient )
262298 @patch ("supervised.apps.publisher.BrowserTokenSession.authenticate" , return_value = "app.jwt.token" )
0 commit comments