@@ -1157,121 +1157,169 @@ def expected_request_json(token) -> str:
1157
1157
)
1158
1158
1159
1159
1160
- def test_check_entity_restrictions_no_unmet_restriction (syn : Synapse ) -> None :
1161
- with patch ("warnings.warn" ) as mocked_warn :
1162
- bundle = {
1163
- "entity" : {
1164
- "id" : "syn123" ,
1165
- "name" : "anonymous" ,
1166
- "concreteType" : "org.sagebionetworks.repo.model.FileEntity" ,
1167
- "parentId" : "syn12345" ,
1168
- },
1169
- "restrictionInformation" : {"hasUnmetAccessRequirement" : False },
1170
- }
1171
- entity = "syn123"
1172
- syn ._check_entity_restrictions (bundle , entity , True )
1173
- mocked_warn .assert_not_called ()
1174
-
1160
+ class TestCheckEntityRestrictions :
1161
+ @pytest .fixture (autouse = True , scope = "function" )
1162
+ def init_syn (self , syn : Synapse ) -> None :
1163
+ self .syn = syn
1164
+ self .syn .credentials = SynapseAuthTokenCredentials (token = "abc" , username = "def" )
1175
1165
1176
- def test_check_entity_restrictions_unmet_restriction_entity_file_with_download_file_is_true (
1177
- syn : Synapse ,
1178
- ) -> None :
1179
- with patch ("warnings.warn" ) as mocked_warn :
1180
- bundle = {
1181
- "entity" : {
1182
- "id" : "syn123" ,
1183
- "name" : "anonymous" ,
1184
- "concreteType" : "org.sagebionetworks.repo.model.FileEntity" ,
1185
- "parentId" : "syn12345" ,
1186
- },
1187
- "entityType" : "file" ,
1188
- "restrictionInformation" : {"hasUnmetAccessRequirement" : True },
1189
- }
1190
- entity = "syn123"
1191
- pytest .raises (
1192
- SynapseUnmetAccessRestrictions ,
1193
- syn ._check_entity_restrictions ,
1194
- bundle ,
1195
- entity ,
1196
- True ,
1197
- )
1198
- mocked_warn .assert_not_called ()
1166
+ def test_check_entity_restrictions_no_unmet_restriction (self ) -> None :
1167
+ with patch ("logging.Logger.warning" ) as mocked_warn :
1168
+ bundle = {
1169
+ "entity" : {
1170
+ "id" : "syn123" ,
1171
+ "name" : "anonymous" ,
1172
+ "concreteType" : "org.sagebionetworks.repo.model.FileEntity" ,
1173
+ "parentId" : "syn12345" ,
1174
+ },
1175
+ "restrictionInformation" : {"hasUnmetAccessRequirement" : False },
1176
+ }
1177
+ entity = "syn123"
1178
+ self .syn ._check_entity_restrictions (bundle , entity , True )
1179
+ mocked_warn .assert_not_called ()
1199
1180
1181
+ def test_check_entity_restrictions_unmet_restriction_entity_file_with_download_file_is_true (
1182
+ self ,
1183
+ ) -> None :
1184
+ with patch ("logging.Logger.warning" ) as mocked_warn :
1185
+ bundle = {
1186
+ "entity" : {
1187
+ "id" : "syn123" ,
1188
+ "name" : "anonymous" ,
1189
+ "concreteType" : "org.sagebionetworks.repo.model.FileEntity" ,
1190
+ "parentId" : "syn12345" ,
1191
+ },
1192
+ "entityType" : "file" ,
1193
+ "restrictionInformation" : {"hasUnmetAccessRequirement" : True },
1194
+ }
1195
+ entity = "syn123"
1196
+ pytest .raises (
1197
+ SynapseUnmetAccessRestrictions ,
1198
+ self .syn ._check_entity_restrictions ,
1199
+ bundle ,
1200
+ entity ,
1201
+ True ,
1202
+ )
1203
+ mocked_warn .assert_not_called ()
1200
1204
1201
- def test_check_entity_restrictions_unmet_restriction_entity_project_with_download_file_is_true (
1202
- syn : Synapse ,
1203
- ) -> None :
1204
- with patch ("warnings.warn " ) as mocked_warn :
1205
- bundle = {
1206
- "entity" : {
1207
- "id" : "syn123" ,
1208
- "name" : "anonymous" ,
1209
- "concreteType" : "org.sagebionetworks.repo.model.FileEntity" ,
1210
- "parentId" : "syn12345" ,
1211
- },
1212
- "entityType" : "project" ,
1213
- "restrictionInformation" : {"hasUnmetAccessRequirement" : True },
1214
- }
1215
- entity = "syn123"
1216
- syn ._check_entity_restrictions (bundle , entity , True )
1217
- mocked_warn .assert_called_with (
1218
- "\n This entity has access restrictions. Please visit the web page for this entity "
1219
- '(syn.onweb("syn123")). Look for the "Access" label and the lock icon underneath '
1220
- 'the file name. Click "Request Access", and then review and fulfill the file '
1221
- "download requirement(s).\n "
1222
- )
1205
+ def test_check_entity_restrictions_unmet_restriction_entity_project_with_download_file_is_true (
1206
+ self ,
1207
+ ) -> None :
1208
+ with patch ("logging.Logger.warning " ) as mocked_warn :
1209
+ bundle = {
1210
+ "entity" : {
1211
+ "id" : "syn123" ,
1212
+ "name" : "anonymous" ,
1213
+ "concreteType" : "org.sagebionetworks.repo.model.FileEntity" ,
1214
+ "parentId" : "syn12345" ,
1215
+ },
1216
+ "entityType" : "project" ,
1217
+ "restrictionInformation" : {"hasUnmetAccessRequirement" : True },
1218
+ }
1219
+ entity = "syn123"
1220
+ self . syn ._check_entity_restrictions (bundle , entity , True )
1221
+ mocked_warn .assert_called_with (
1222
+ "\n This entity has access restrictions. Please visit the web page for this entity "
1223
+ '(syn.onweb("syn123")). Look for the "Access" label and the lock icon underneath '
1224
+ 'the file name. Click "Request Access", and then review and fulfill the file '
1225
+ "download requirement(s).\n "
1226
+ )
1223
1227
1228
+ def test_check_entity_restrictions_unmet_restriction_entity_folder_with_download_file_is_true_and_no_token (
1229
+ self ,
1230
+ ) -> None :
1231
+ with patch ("logging.Logger.warning" ) as mocked_warn :
1232
+ bundle = {
1233
+ "entity" : {
1234
+ "id" : "syn123" ,
1235
+ "name" : "anonymous" ,
1236
+ "concreteType" : "org.sagebionetworks.repo.model.FileEntity" ,
1237
+ "parentId" : "syn12345" ,
1238
+ },
1239
+ "entityType" : "folder" ,
1240
+ "restrictionInformation" : {"hasUnmetAccessRequirement" : True },
1241
+ }
1242
+ entity = "syn123"
1243
+ self .syn .credentials = SynapseAuthTokenCredentials (token = "" )
1244
+ self .syn ._check_entity_restrictions (bundle , entity , True )
1245
+ mocked_warn .assert_called_with (
1246
+ "You have not provided valid credentials for authentication with Synapse."
1247
+ " Please provide an authentication token and use `synapseclient.login()` before your next attempt."
1248
+ " See https://python-docs.synapse.org/tutorials/authentication/ for more information."
1249
+ )
1224
1250
1225
- def test_check_entity_restrictions_unmet_restriction_entity_folder_with_download_file_is_true (
1226
- syn : Synapse ,
1227
- ) -> None :
1228
- with patch ("warnings.warn " ) as mocked_warn :
1229
- bundle = {
1230
- "entity" : {
1231
- "id" : "syn123" ,
1232
- "name" : "anonymous" ,
1233
- "concreteType" : "org.sagebionetworks.repo.model.FileEntity" ,
1234
- "parentId" : "syn12345" ,
1235
- },
1236
- "entityType" : "folder" ,
1237
- "restrictionInformation" : {"hasUnmetAccessRequirement" : True },
1238
- }
1239
- entity = "syn123"
1240
- syn ._check_entity_restrictions ( bundle , entity , True )
1241
- mocked_warn . assert_called_with (
1242
- " \n This entity has access restrictions. Please visit the web page for this entity "
1243
- '(syn.onweb("syn123")). Look for the "Access" label and the lock icon underneath '
1244
- 'the file name. Click "Request Access", and then review and fulfill the file '
1245
- "download requirement(s). \n "
1246
- )
1251
+ def test_check_entity_restrictions_unmet_restriction_entity_folder_with_download_file_is_true_and_no_credentials (
1252
+ self ,
1253
+ ) -> None :
1254
+ with patch ("logging.Logger.warning " ) as mocked_warn :
1255
+ bundle = {
1256
+ "entity" : {
1257
+ "id" : "syn123" ,
1258
+ "name" : "anonymous" ,
1259
+ "concreteType" : "org.sagebionetworks.repo.model.FileEntity" ,
1260
+ "parentId" : "syn12345" ,
1261
+ },
1262
+ "entityType" : "folder" ,
1263
+ "restrictionInformation" : {"hasUnmetAccessRequirement" : True },
1264
+ }
1265
+ entity = "syn123"
1266
+ self . syn .credentials = None
1267
+ self . syn . _check_entity_restrictions ( bundle , entity , True )
1268
+ mocked_warn . assert_called_with (
1269
+ "You have not provided valid credentials for authentication with Synapse."
1270
+ " Please provide an authentication token and use `synapseclient.login()` before your next attempt."
1271
+ " See https://python-docs.synapse.org/tutorials/authentication/ for more information. "
1272
+ )
1247
1273
1274
+ def test_check_entity_restrictions_unmet_restriction_entity_folder_with_download_file_is_true (
1275
+ self ,
1276
+ ) -> None :
1277
+ with patch ("logging.Logger.warning" ) as mocked_warn :
1278
+ bundle = {
1279
+ "entity" : {
1280
+ "id" : "syn123" ,
1281
+ "name" : "anonymous" ,
1282
+ "concreteType" : "org.sagebionetworks.repo.model.FileEntity" ,
1283
+ "parentId" : "syn12345" ,
1284
+ },
1285
+ "entityType" : "folder" ,
1286
+ "restrictionInformation" : {"hasUnmetAccessRequirement" : True },
1287
+ }
1288
+ entity = "syn123"
1289
+ self .syn ._check_entity_restrictions (bundle , entity , True )
1290
+ mocked_warn .assert_called_with (
1291
+ "\n This entity has access restrictions. Please visit the web page for this entity "
1292
+ '(syn.onweb("syn123")). Look for the "Access" label and the lock icon underneath '
1293
+ 'the file name. Click "Request Access", and then review and fulfill the file '
1294
+ "download requirement(s).\n "
1295
+ )
1248
1296
1249
- def test_check_entity_restrictions__unmet_restriction_downloadFile_is_False (
1250
- syn : Synapse ,
1251
- ) -> None :
1252
- with patch ("warnings.warn " ) as mocked_warn :
1253
- bundle = {
1254
- "entity" : {
1255
- "id" : "syn123" ,
1256
- "name" : "anonymous" ,
1257
- "concreteType" : "org.sagebionetworks.repo.model.FileEntity" ,
1258
- "parentId" : "syn12345" ,
1259
- },
1260
- "entityType" : "file" ,
1261
- "restrictionInformation" : {"hasUnmetAccessRequirement" : True },
1262
- }
1263
- entity = "syn123"
1297
+ def test_check_entity_restrictions__unmet_restriction_downloadFile_is_False (
1298
+ self ,
1299
+ ) -> None :
1300
+ with patch ("logging.Logger.warning " ) as mocked_warn :
1301
+ bundle = {
1302
+ "entity" : {
1303
+ "id" : "syn123" ,
1304
+ "name" : "anonymous" ,
1305
+ "concreteType" : "org.sagebionetworks.repo.model.FileEntity" ,
1306
+ "parentId" : "syn12345" ,
1307
+ },
1308
+ "entityType" : "file" ,
1309
+ "restrictionInformation" : {"hasUnmetAccessRequirement" : True },
1310
+ }
1311
+ entity = "syn123"
1264
1312
1265
- syn ._check_entity_restrictions (bundle , entity , False )
1266
- mocked_warn .assert_called_once ()
1313
+ self . syn ._check_entity_restrictions (bundle , entity , False )
1314
+ mocked_warn .assert_called_once ()
1267
1315
1268
- bundle ["entityType" ] = "project"
1269
- syn ._check_entity_restrictions (bundle , entity , False )
1270
- assert mocked_warn .call_count == 2
1316
+ bundle ["entityType" ] = "project"
1317
+ self . syn ._check_entity_restrictions (bundle , entity , False )
1318
+ assert mocked_warn .call_count == 2
1271
1319
1272
- bundle ["entityType" ] = "folder"
1273
- syn ._check_entity_restrictions (bundle , entity , False )
1274
- assert mocked_warn .call_count == 3
1320
+ bundle ["entityType" ] = "folder"
1321
+ self . syn ._check_entity_restrictions (bundle , entity , False )
1322
+ assert mocked_warn .call_count == 3
1275
1323
1276
1324
1277
1325
class TestGetColumns (object ):
@@ -1299,6 +1347,7 @@ class TestPrivateGetEntityBundle:
1299
1347
@pytest .fixture (autouse = True , scope = "function" )
1300
1348
def init_syn (self , syn : Synapse ) -> None :
1301
1349
self .syn = syn
1350
+ self .syn .credentials = SynapseAuthTokenCredentials (token = "abc" , username = "def" )
1302
1351
1303
1352
@pytest .fixture (scope = "function" , autouse = True )
1304
1353
def setup_method (self ) -> None :
0 commit comments