Skip to content

Commit 33e6fc7

Browse files
committed
Fix test cases for DREF
1 parent 82ec512 commit 33e6fc7

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

deployments/snapshots/snap_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@
873873
'is_deprecated': False,
874874
'iso': 'HA',
875875
'iso3': 'xcS',
876-
'name': 'country-jYLXlNQGqkURvDMLeoyyigbmHGRAjMglENMcYIGWhfEQiMIaXR',
876+
'name': 'country-AMjYLXlNQGqkURvDMLeoyyigbmHGRAjMglENMcYIGWhfEQiMIa',
877877
'record_type': 4,
878878
'record_type_display': 'Country Office',
879879
'region': 3,

dref/serializers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ class DrefSerializer(
207207
assessment_report_details = DrefFileSerializer(source='assessment_report', read_only=True)
208208
supporting_document_details = DrefFileSerializer(read_only=True, source='supporting_document')
209209
risk_security = RiskSecuritySerializer(many=True, required=False)
210-
modified_at = serializers.DateTimeField(required=True)
210+
modified_at = serializers.DateTimeField(required=False)
211211

212212
class Meta:
213213
model = Dref

dref/test_views.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)