@@ -364,6 +364,34 @@ def test_draft_page_content_is_activated_when_experiment_goes_live(self):
364364 homepage_alternative_1 = Page .objects .get (pk = self .homepage_alternative_1 .pk ).specific
365365 self .assertEqual (homepage_alternative_1 .body , 'updated' )
366366
367+ def test_draft_page_content_is_activated_when_creating_experiment_as_live (self ):
368+ # make a draft edit to homepage_alternative_1
369+ self .homepage_alternative_1 .body = 'updated'
370+ self .homepage_alternative_1 .save_revision ()
371+
372+ # create a new experiment with an immediate live status
373+ response = self .client .post ('/admin/experiments/experiment/create/' , {
374+ 'name' : "Another experiment" ,
375+ 'slug' : 'another-experiment' ,
376+ 'control_page' : self .homepage .pk ,
377+ 'alternatives-TOTAL_FORMS' : 1 ,
378+ 'alternatives-INITIAL_FORMS' : 0 ,
379+ 'alternatives-MIN_NUM_FORMS' : 0 ,
380+ 'alternatives-MAX_NUM_FORMS' : 1000 ,
381+ 'alternatives-0-page' : self .homepage_alternative_1 .pk ,
382+ 'alternatives-0-id' : '' ,
383+ 'alternatives-0-ORDER' : '1' ,
384+ 'alternatives-0-DELETE' : '' ,
385+ 'goal' : '' ,
386+ 'status' : 'live' ,
387+ })
388+
389+ self .assertRedirects (response , '/admin/experiments/experiment/' )
390+
391+ # page content should be updated to follow the draft revision now
392+ homepage_alternative_1 = Page .objects .get (pk = self .homepage_alternative_1 .pk ).specific
393+ self .assertEqual (homepage_alternative_1 .body , 'updated' )
394+
367395 def test_draft_page_content_is_not_activated_on_published_pages (self ):
368396 # publish homepage_alternative_1
369397 self .homepage_alternative_1 .save_revision ().publish ()
@@ -387,6 +415,37 @@ def test_draft_page_content_is_not_activated_on_published_pages(self):
387415 homepage_alternative_1 = Page .objects .get (pk = self .homepage_alternative_1 .pk ).specific
388416 self .assertEqual (homepage_alternative_1 .body , "Welcome to our site! It's lovely to meet you." )
389417
418+ def test_draft_page_content_is_not_activated_on_published_pages_when_creating_experiment_as_live (self ):
419+ # publish homepage_alternative_1
420+ self .homepage_alternative_1 .save_revision ().publish ()
421+
422+ # make a draft edit to homepage_alternative_1
423+ self .homepage_alternative_1 .body = 'updated'
424+ self .homepage_alternative_1 .save_revision ()
425+
426+ # create a new experiment with an immediate live status
427+ response = self .client .post ('/admin/experiments/experiment/create/' , {
428+ 'name' : "Another experiment" ,
429+ 'slug' : 'another-experiment' ,
430+ 'control_page' : self .homepage .pk ,
431+ 'alternatives-TOTAL_FORMS' : 1 ,
432+ 'alternatives-INITIAL_FORMS' : 0 ,
433+ 'alternatives-MIN_NUM_FORMS' : 0 ,
434+ 'alternatives-MAX_NUM_FORMS' : 1000 ,
435+ 'alternatives-0-page' : self .homepage_alternative_1 .pk ,
436+ 'alternatives-0-id' : '' ,
437+ 'alternatives-0-ORDER' : '1' ,
438+ 'alternatives-0-DELETE' : '' ,
439+ 'goal' : '' ,
440+ 'status' : 'live' ,
441+ })
442+
443+ self .assertRedirects (response , '/admin/experiments/experiment/' )
444+
445+ # page content should still be unchanged
446+ homepage_alternative_1 = Page .objects .get (pk = self .homepage_alternative_1 .pk ).specific
447+ self .assertEqual (homepage_alternative_1 .body , "Welcome to our site! It's lovely to meet you." )
448+
390449 def test_experiment_delete (self ):
391450 response = self .client .get ('/admin/experiments/experiment/delete/%d/' % self .experiment .pk )
392451 self .assertEqual (response .status_code , 200 )
0 commit comments