@@ -2226,6 +2226,47 @@ def test_upload_non_picture_with_png_extension(
2226
2226
logic .ValidationError , match = "Unsupported upload type" ):
2227
2227
create_with_upload ("hello world" , "file.png" , ** params )
2228
2228
2229
+ @pytest .mark .ckan_config ("ckan.upload.user.mimetypes" , "" )
2230
+ @pytest .mark .ckan_config ("ckan.upload.user.types" , "" )
2231
+ def test_uploads_not_allowed_when_empty_mimetypes_and_types (
2232
+ self , create_with_upload , faker ):
2233
+ params = {
2234
+ "name" : faker .user_name (),
2235
+ "email" : faker .email (),
2236
+ "password" : "12345678" ,
2237
+ "action" : "user_create" ,
2238
+ "upload_field_name" : "image_upload" ,
2239
+ }
2240
+ with pytest .raises (
2241
+ logic .ValidationError , match = "No uploads allowed for object type" ):
2242
+ create_with_upload ("hello world" , "file.png" , ** params )
2243
+
2244
+ @pytest .mark .ckan_config ("ckan.upload.user.mimetypes" , "*" )
2245
+ @pytest .mark .ckan_config ("ckan.upload.user.types" , "image" )
2246
+ def test_upload_all_types_allowed_needs_both_options (self , create_with_upload , faker ):
2247
+ params = {
2248
+ "name" : faker .user_name (),
2249
+ "email" : faker .email (),
2250
+ "password" : "12345678" ,
2251
+ "action" : "user_create" ,
2252
+ "upload_field_name" : "image_upload" ,
2253
+ }
2254
+ with pytest .raises (
2255
+ logic .ValidationError , match = "Unsupported upload type" ):
2256
+ assert create_with_upload (faker .json (), "file.json" , ** params )
2257
+
2258
+ @pytest .mark .ckan_config ("ckan.upload.user.mimetypes" , "*" )
2259
+ @pytest .mark .ckan_config ("ckan.upload.user.types" , "*" )
2260
+ def test_upload_all_types_allowed (self , create_with_upload , faker ):
2261
+ params = {
2262
+ "name" : faker .user_name (),
2263
+ "email" : faker .email (),
2264
+ "password" : "12345678" ,
2265
+ "action" : "user_create" ,
2266
+ "upload_field_name" : "image_upload" ,
2267
+ }
2268
+ assert create_with_upload (faker .json (), "file.json" , ** params )
2269
+
2229
2270
@pytest .mark .ckan_config ("ckan.upload.user.types" , "image" )
2230
2271
def test_upload_picture (self , create_with_upload , faker ):
2231
2272
params = {
@@ -2237,6 +2278,20 @@ def test_upload_picture(self, create_with_upload, faker):
2237
2278
}
2238
2279
assert create_with_upload (faker .image (), "file.png" , ** params )
2239
2280
2281
+ @pytest .mark .ckan_config ("ckan.upload.user.types" , "image" )
2282
+ def test_upload_picture_extension_enforced (self , create_with_upload , faker ):
2283
+ params = {
2284
+ "name" : faker .user_name (),
2285
+ "email" : faker .email (),
2286
+ "password" : "12345678" ,
2287
+ "action" : "user_create" ,
2288
+ "upload_field_name" : "image_upload" ,
2289
+ }
2290
+ user = create_with_upload (faker .image (image_format = "jpeg" ), "file.png" , ** params )
2291
+
2292
+ assert user ["image_url" ].endswith (".jpg" )
2293
+ assert user ["image_display_url" ].endswith (".jpg" )
2294
+
2240
2295
2241
2296
class TestVocabularyCreate (object ):
2242
2297
@pytest .mark .usefixtures ("non_clean_db" )
0 commit comments