|
21 | 21 | from django.core.files.uploadedfile import SimpleUploadedFile
|
22 | 22 |
|
23 | 23 | from aws.s3.s3fs import S3ListAllBucketsException
|
24 |
| -from filebrowser.api import copy, get_all_filesystems, listdir_paged, mkdir, move, rename, upload_file |
| 24 | +from filebrowser.api import copy, get_all_filesystems, listdir_paged, mkdir, move, rename, touch, upload_file |
25 | 25 | from filebrowser.conf import (
|
26 | 26 | MAX_FILE_SIZE_UPLOAD_LIMIT,
|
27 | 27 | RESTRICT_FILE_EXTENSIONS,
|
@@ -331,6 +331,70 @@ def test_file_upload_failure(self):
|
331 | 331 | reset()
|
332 | 332 |
|
333 | 333 |
|
| 334 | +class TestTouchAPI: |
| 335 | + def test_touch_success(self): |
| 336 | + request = Mock( |
| 337 | + method='POST', |
| 338 | + POST={'path': 's3a://test-bucket/test-user/', 'name': 'test_file.txt'}, |
| 339 | + fs=Mock( |
| 340 | + isfile=Mock(return_value=False), |
| 341 | + join=Mock(return_value='s3a://test-bucket/test-user/test_file.txt'), |
| 342 | + create=Mock(), |
| 343 | + ), |
| 344 | + ) |
| 345 | + response = touch(request) |
| 346 | + |
| 347 | + assert response.status_code == 201 |
| 348 | + request.fs.create.assert_called_once_with('s3a://test-bucket/test-user/test_file.txt') |
| 349 | + |
| 350 | + def test_touch_file_exists(self): |
| 351 | + request = Mock( |
| 352 | + method='POST', |
| 353 | + POST={'path': 's3a://test-bucket/test-user/', 'name': 'test_file.txt'}, |
| 354 | + fs=Mock( |
| 355 | + isfile=Mock(return_value=True), |
| 356 | + join=Mock(return_value='s3a://test-bucket/test-user/test_file.txt'), |
| 357 | + ), |
| 358 | + ) |
| 359 | + response = touch(request) |
| 360 | + |
| 361 | + assert response.status_code == 409 |
| 362 | + assert response.content.decode('utf-8') == 'Error creating test_file.txt file: File already exists.' |
| 363 | + |
| 364 | + def test_touch_invalid_name(self): |
| 365 | + request = Mock( |
| 366 | + method='POST', |
| 367 | + POST={'path': 's3a://test-bucket/test-user/', 'name': 'test/file.txt'}, |
| 368 | + fs=Mock(), |
| 369 | + ) |
| 370 | + response = touch(request) |
| 371 | + |
| 372 | + assert response.status_code == 400 |
| 373 | + assert response.content.decode('utf-8') == 'Slashes are not allowed in filename. Please choose a different name.' |
| 374 | + |
| 375 | + def test_touch_no_path(self): |
| 376 | + request = Mock( |
| 377 | + method='POST', |
| 378 | + POST={'name': 'test_file.txt'}, |
| 379 | + fs=Mock(), |
| 380 | + ) |
| 381 | + response = touch(request) |
| 382 | + |
| 383 | + assert response.status_code == 400 |
| 384 | + assert response.content.decode('utf-8') == 'Missing parameters: path and name are required.' |
| 385 | + |
| 386 | + def test_touch_no_name(self): |
| 387 | + request = Mock( |
| 388 | + method='POST', |
| 389 | + POST={'path': 's3a://test-bucket/test-user/'}, |
| 390 | + fs=Mock(), |
| 391 | + ) |
| 392 | + response = touch(request) |
| 393 | + |
| 394 | + assert response.status_code == 400 |
| 395 | + assert response.content.decode('utf-8') == 'Missing parameters: path and name are required.' |
| 396 | + |
| 397 | + |
334 | 398 | class TestMkdirAPI:
|
335 | 399 | def test_mkdir_success(self):
|
336 | 400 | request = Mock(
|
|
0 commit comments