@@ -441,34 +441,42 @@ def test_dref_options(self):
441441 self .assertIn ('needs_identified' , response .data )
442442 self .assertIn ('national_society_actions' , response .data )
443443
444- def test_dref_is_published (self ):
444+ @mock .patch ('django.utils.timezone.now' )
445+ def test_dref_is_published (self , mock_now ):
445446 """
446447 Test for dref if is_published = True
447448 """
449+ initial_now = datetime (2011 , 11 , 11 )
450+ mock_now .return_value = initial_now
451+
448452 dref = DrefFactory .create (
449- title = 'test' , created_by = self .user ,
453+ title = 'test' ,
454+ created_by = self .user ,
450455 is_published = True ,
451- modified_at = datetime .now () + timedelta (days = - 1 )
452456 )
453457 url = f'/api/v2/dref/{ dref .id } /'
454458 data = {
455459 "title" : "New Update Title" ,
456- "modified_at" : datetime . now () ,
460+ "modified_at" : initial_now ,
457461 }
458462 self .client .force_authenticate (self .user )
459463 response = self .client .patch (url , data )
460464 self .assert_400 (response )
461465
462466 # create new dref with is_published = False
463467 not_published_dref = DrefFactory .create (
464- title = 'test' , created_by = self . user ,
465- modified_at = datetime . now () + timedelta ( days = - 1 )
468+ title = 'test' ,
469+ created_by = self . user ,
466470 )
467471 url = f'/api/v2/dref/{ not_published_dref .id } /'
468472 self .client .force_authenticate (self .user )
469473 response = self .client .patch (url , data )
470474 self .assert_200 (response )
471475
476+ data ['modified_at' ] = initial_now - timedelta (seconds = 10 )
477+ response = self .client .patch (url , data )
478+ self .assert_400 (response )
479+
472480 # test dref published endpoint
473481 url = f'/api/v2/dref/{ not_published_dref .id } /publish/'
474482 data = {}
0 commit comments