@@ -863,7 +863,8 @@ def test_get_legacy_edit_link_submission_as_owner(self):
863
863
assert response .status_code == status .HTTP_200_OK
864
864
865
865
expected_response = {
866
- 'url' : f"{ settings .ENKETO_URL } /edit/{ self .submission ['_uuid' ]} "
866
+ 'url' : f"{ settings .ENKETO_URL } /edit/{ self .submission ['_uuid' ]} " ,
867
+ 'version_uid' : self .asset .latest_deployed_version .uid ,
867
868
}
868
869
assert response .data == expected_response
869
870
@@ -886,7 +887,8 @@ def test_get_edit_link_submission_as_owner(self):
886
887
response = self .client .get (self .submission_url , {'format' : 'json' })
887
888
assert response .status_code == status .HTTP_200_OK
888
889
expected_response = {
889
- 'url' : f"{ settings .ENKETO_URL } /edit/{ self .submission ['_uuid' ]} "
890
+ 'url' : f"{ settings .ENKETO_URL } /edit/{ self .submission ['_uuid' ]} " ,
891
+ 'version_uid' : self .asset .latest_deployed_version .uid ,
890
892
}
891
893
self .assertEqual (response .data , expected_response )
892
894
@@ -1002,8 +1004,10 @@ def test_get_edit_link_with_partial_perms_as_anotheruser(self):
1002
1004
1003
1005
response = self .client .get (url , {'format' : 'json' })
1004
1006
self .assertEqual (response .status_code , status .HTTP_200_OK )
1005
- url = f"{ settings .ENKETO_URL } /edit/{ submission ['_uuid' ]} "
1006
- expected_response = {'url' : url }
1007
+ expected_response = {
1008
+ 'url' : f"{ settings .ENKETO_URL } /edit/{ submission ['_uuid' ]} " ,
1009
+ 'version_uid' : self .asset .latest_deployed_version .uid ,
1010
+ }
1007
1011
self .assertEqual (response .data , expected_response )
1008
1012
1009
1013
@responses .activate
@@ -1118,6 +1122,70 @@ def test_get_multiple_edit_links_and_attempt_submit_edits(self):
1118
1122
with pytest .raises (KeyError ) as e :
1119
1123
res = self .client .post (url )
1120
1124
1125
+ @responses .activate
1126
+ def test_get_edit_link_submission_with_latest_asset_deployment (self ):
1127
+ """
1128
+ Check that the submission edit is using the asset version associated
1129
+ with the latest **deployed** version.
1130
+ """
1131
+ original_versions_count = self .asset .asset_versions .count ()
1132
+ original_deployed_versions_count = self .asset .deployed_versions .count ()
1133
+ original_deployed_version_uid = self .asset .latest_deployed_version .uid
1134
+
1135
+ ee_url = (
1136
+ f'{ settings .ENKETO_URL } /{ settings .ENKETO_EDIT_INSTANCE_ENDPOINT } '
1137
+ )
1138
+ # Mock Enketo response
1139
+ responses .add_callback (
1140
+ responses .POST ,
1141
+ ee_url ,
1142
+ callback = enketo_edit_instance_response ,
1143
+ content_type = 'application/json' ,
1144
+ )
1145
+
1146
+ # make a change to the asset content but don't redeploy yet
1147
+ self .asset .content ['survey' ].append (
1148
+ {
1149
+ 'type' : 'note' ,
1150
+ 'name' : 'n' ,
1151
+ 'label' : 'A new note' ,
1152
+ }
1153
+ )
1154
+ self .asset .save ()
1155
+ assert self .asset .asset_versions .count () == original_versions_count + 1
1156
+ assert (
1157
+ self .asset .deployed_versions .count ()
1158
+ == original_deployed_versions_count
1159
+ )
1160
+
1161
+ # ensure that the latest deployed version is used for the edit, even if
1162
+ # there's a new asset version
1163
+ response = self .client .get (self .submission_url , {'format' : 'json' })
1164
+ assert response .status_code == status .HTTP_200_OK
1165
+ expected_response = {
1166
+ 'url' : f"{ settings .ENKETO_URL } /edit/{ self .submission ['_uuid' ]} " ,
1167
+ 'version_uid' : original_deployed_version_uid ,
1168
+ }
1169
+ assert response .data == expected_response
1170
+
1171
+ # redeploy the asset to create a new deployment version
1172
+ self .asset .deploy (active = True )
1173
+ self .asset .save ()
1174
+ assert self .asset .asset_versions .count () == original_versions_count + 2
1175
+ assert (
1176
+ self .asset .deployed_versions .count ()
1177
+ == original_deployed_versions_count + 1
1178
+ )
1179
+
1180
+ # ensure that the newly deployed version is used for editing
1181
+ response = self .client .get (self .submission_url , {'format' : 'json' })
1182
+ assert response .status_code == status .HTTP_200_OK
1183
+ expected_response = {
1184
+ 'url' : f"{ settings .ENKETO_URL } /edit/{ self .submission ['_uuid' ]} " ,
1185
+ 'version_uid' : self .asset .latest_deployed_version .uid ,
1186
+ }
1187
+ assert response .data == expected_response
1188
+
1121
1189
1122
1190
class SubmissionViewApiTests (BaseSubmissionTestCase ):
1123
1191
@@ -1153,7 +1221,8 @@ def test_get_view_link_submission_as_owner(self):
1153
1221
assert response .status_code == status .HTTP_200_OK
1154
1222
1155
1223
expected_response = {
1156
- 'url' : f"{ settings .ENKETO_URL } /view/{ self .submission ['_uuid' ]} "
1224
+ 'url' : f"{ settings .ENKETO_URL } /view/{ self .submission ['_uuid' ]} " ,
1225
+ 'version_uid' : self .asset .latest_deployed_version .uid ,
1157
1226
}
1158
1227
assert response .data == expected_response
1159
1228
@@ -1256,8 +1325,10 @@ def test_get_view_link_with_partial_perms_as_anotheruser(self):
1256
1325
1257
1326
response = self .client .get (url , {'format' : 'json' })
1258
1327
self .assertEqual (response .status_code , status .HTTP_200_OK )
1259
- url = f"{ settings .ENKETO_URL } /view/{ submission ['_uuid' ]} "
1260
- expected_response = {'url' : url }
1328
+ expected_response = {
1329
+ 'url' : f"{ settings .ENKETO_URL } /view/{ submission ['_uuid' ]} " ,
1330
+ 'version_uid' : self .asset .latest_deployed_version .uid ,
1331
+ }
1261
1332
self .assertEqual (response .data , expected_response )
1262
1333
1263
1334
0 commit comments