@@ -252,9 +252,9 @@ def setUp(self):
252252 self .client .login (username = 'admin' , password = 'password' )
253253 )
254254 self .experiment = Experiment .objects .get (slug = 'homepage-text' )
255- self .homepage = Page .objects .get (url_path = '/home/' )
256- self .homepage_alternative_1 = Page .objects .get (url_path = '/home/home-alternative-1/' )
257- self .homepage_alternative_2 = Page .objects .get (url_path = '/home/home-alternative-2/' )
255+ self .homepage = Page .objects .get (url_path = '/home/' ). specific
256+ self .homepage_alternative_1 = Page .objects .get (url_path = '/home/home-alternative-1/' ). specific
257+ self .homepage_alternative_2 = Page .objects .get (url_path = '/home/home-alternative-2/' ). specific
258258
259259 def get_edit_postdata (self , ** kwargs ):
260260 alternatives = self .experiment .alternatives .all ()
@@ -328,6 +328,65 @@ def test_experiment_edit(self):
328328 experiment = Experiment .objects .get (pk = self .experiment .pk )
329329 self .assertEqual (experiment .name , "Homepage text updated" )
330330
331+ def test_draft_page_content_is_activated_when_experiment_goes_live (self ):
332+ # make a draft edit to homepage_alternative_1
333+ self .homepage_alternative_1 .body = 'updated'
334+ self .homepage_alternative_1 .save_revision ()
335+
336+ # live database entry should not have been updated yet
337+ homepage_alternative_1 = Page .objects .get (pk = self .homepage_alternative_1 .pk ).specific
338+ self .assertEqual (homepage_alternative_1 .body , "Welcome to our site! It's lovely to meet you." )
339+
340+ # submit an edit to the experiment, but preserve its live status
341+ self .client .post (
342+ '/admin/experiments/experiment/edit/%d/' % self .experiment .pk ,
343+ self .get_edit_postdata ()
344+ )
345+ # editing an already-live experiment should not update the page content
346+ homepage_alternative_1 = Page .objects .get (pk = self .homepage_alternative_1 .pk ).specific
347+ self .assertEqual (homepage_alternative_1 .body , "Welcome to our site! It's lovely to meet you." )
348+
349+ # make the experiment draft
350+ self .client .post (
351+ '/admin/experiments/experiment/edit/%d/' % self .experiment .pk ,
352+ self .get_edit_postdata (status = 'draft' )
353+ )
354+ # page content should still be unchanged
355+ homepage_alternative_1 = Page .objects .get (pk = self .homepage_alternative_1 .pk ).specific
356+ self .assertEqual (homepage_alternative_1 .body , "Welcome to our site! It's lovely to meet you." )
357+
358+ # set the experiment from draft to live
359+ self .client .post (
360+ '/admin/experiments/experiment/edit/%d/' % self .experiment .pk ,
361+ self .get_edit_postdata (status = 'live' )
362+ )
363+ # page content should be updated to follow the draft revision now
364+ homepage_alternative_1 = Page .objects .get (pk = self .homepage_alternative_1 .pk ).specific
365+ self .assertEqual (homepage_alternative_1 .body , 'updated' )
366+
367+ def test_draft_page_content_is_not_activated_on_published_pages (self ):
368+ # publish homepage_alternative_1
369+ self .homepage_alternative_1 .save_revision ().publish ()
370+
371+ # make a draft edit to homepage_alternative_1
372+ self .homepage_alternative_1 .body = 'updated'
373+ self .homepage_alternative_1 .save_revision ()
374+
375+ # make the experiment draft
376+ self .client .post (
377+ '/admin/experiments/experiment/edit/%d/' % self .experiment .pk ,
378+ self .get_edit_postdata (status = 'draft' )
379+ )
380+ # set the experiment from draft to live
381+ self .client .post (
382+ '/admin/experiments/experiment/edit/%d/' % self .experiment .pk ,
383+ self .get_edit_postdata (status = 'live' )
384+ )
385+
386+ # page content should still be unchanged
387+ homepage_alternative_1 = Page .objects .get (pk = self .homepage_alternative_1 .pk ).specific
388+ self .assertEqual (homepage_alternative_1 .body , "Welcome to our site! It's lovely to meet you." )
389+
331390 def test_experiment_delete (self ):
332391 response = self .client .get ('/admin/experiments/experiment/delete/%d/' % self .experiment .pk )
333392 self .assertEqual (response .status_code , 200 )
@@ -353,7 +412,7 @@ def test_select_winner(self):
353412 )
354413 experiment = Experiment .objects .get (pk = self .experiment .pk )
355414 self .assertEqual (experiment .status , 'completed' )
356- self .assertEqual (experiment .winning_variation , self .homepage_alternative_1 )
415+ self .assertEqual (experiment .winning_variation . pk , self .homepage_alternative_1 . pk )
357416
358417 def test_preview (self ):
359418 response = self .client .get (
0 commit comments