@@ 556-579 (lines=24) @@ | ||
553 | ||
554 | assert path == os.path.join('2015','12','No Album Fool','12'), path |
|
555 | ||
556 | @mock.patch('elodie.config.config_file', '%s/config.ini-location-date' % gettempdir()) |
|
557 | def test_get_folder_path_with_with_more_than_two_levels(): |
|
558 | with open('%s/config.ini-location-date' % gettempdir(), 'w') as f: |
|
559 | f.write(""" |
|
560 | [MapQuest] |
|
561 | key=czjNKTtFjLydLteUBwdgKAIC8OAbGLUx |
|
562 | ||
563 | [Directory] |
|
564 | year=%Y |
|
565 | month=%m |
|
566 | location=%city, %state |
|
567 | full_path=%year/%month/%location |
|
568 | """) |
|
569 | ||
570 | if hasattr(load_config, 'config'): |
|
571 | del load_config.config |
|
572 | ||
573 | filesystem = FileSystem() |
|
574 | media = Photo(helper.get_file('with-location.jpg')) |
|
575 | path = filesystem.get_folder_path(media.get_metadata()) |
|
576 | if hasattr(load_config, 'config'): |
|
577 | del load_config.config |
|
578 | ||
579 | assert path == os.path.join('2015','12','Sunnyvale, California'), path |
|
580 | ||
581 | @mock.patch('elodie.config.config_file', '%s/config.ini-location-date' % gettempdir()) |
|
582 | def test_get_folder_path_with_with_only_one_level(): |
|
@@ 514-534 (lines=21) @@ | ||
511 | ||
512 | assert path == os.path.join('2015-12-Dec','Unknown Location'), path |
|
513 | ||
514 | @mock.patch('elodie.config.config_file', '%s/config.ini-custom-path' % gettempdir()) |
|
515 | def test_get_folder_path_with_custom_path(): |
|
516 | with open('%s/config.ini-custom-path' % gettempdir(), 'w') as f: |
|
517 | f.write(""" |
|
518 | [MapQuest] |
|
519 | key=czjNKTtFjLydLteUBwdgKAIC8OAbGLUx |
|
520 | ||
521 | [Directory] |
|
522 | date=%Y-%m-%d |
|
523 | location=%country-%state-%city |
|
524 | full_path=%date/%location |
|
525 | """) |
|
526 | if hasattr(load_config, 'config'): |
|
527 | del load_config.config |
|
528 | filesystem = FileSystem() |
|
529 | media = Photo(helper.get_file('with-location.jpg')) |
|
530 | path = filesystem.get_folder_path(media.get_metadata()) |
|
531 | if hasattr(load_config, 'config'): |
|
532 | del load_config.config |
|
533 | ||
534 | assert path == os.path.join('2015-12-05','United States of America-California-Sunnyvale'), path |
|
535 | ||
536 | @mock.patch('elodie.config.config_file', '%s/config.ini-fallback' % gettempdir()) |
|
537 | def test_get_folder_path_with_fallback_folder(): |
|
@@ 344-363 (lines=20) @@ | ||
341 | ||
342 | assert file_name == helper.path_tz_fix('2015-12-05-plain.jpg'), file_name |
|
343 | ||
344 | @mock.patch('elodie.config.config_file', '%s/config.ini-filename-custom-with-uppercase' % gettempdir()) |
|
345 | def test_get_file_name_custom_with_upper_capitalization(): |
|
346 | with open('%s/config.ini-filename-custom-with-uppercase' % gettempdir(), 'w') as f: |
|
347 | f.write(""" |
|
348 | [File] |
|
349 | date=%Y-%m-%d |
|
350 | name=%date-%original_name-%title.%extension |
|
351 | capitalization=upper |
|
352 | """) |
|
353 | if hasattr(load_config, 'config'): |
|
354 | del load_config.config |
|
355 | ||
356 | filesystem = FileSystem() |
|
357 | media = Photo(helper.get_file('plain.jpg')) |
|
358 | file_name = filesystem.get_file_name(media.get_metadata()) |
|
359 | ||
360 | if hasattr(load_config, 'config'): |
|
361 | del load_config.config |
|
362 | ||
363 | assert file_name == helper.path_tz_fix('2015-12-05-PLAIN.JPG'), file_name |
|
364 | ||
365 | def test_get_folder_path_plain(): |
|
366 | filesystem = FileSystem() |
|
@@ 323-342 (lines=20) @@ | ||
320 | ||
321 | assert file_name == helper.path_tz_fix('2015-12-05-plain.jpg'), file_name |
|
322 | ||
323 | @mock.patch('elodie.config.config_file', '%s/config.ini-filename-custom-with-invalidcase' % gettempdir()) |
|
324 | def test_get_file_name_custom_with_invalid_capitalization(): |
|
325 | with open('%s/config.ini-filename-custom-with-invalidcase' % gettempdir(), 'w') as f: |
|
326 | f.write(""" |
|
327 | [File] |
|
328 | date=%Y-%m-%d |
|
329 | name=%date-%original_name-%title.%extension |
|
330 | capitalization=garabage |
|
331 | """) |
|
332 | if hasattr(load_config, 'config'): |
|
333 | del load_config.config |
|
334 | ||
335 | filesystem = FileSystem() |
|
336 | media = Photo(helper.get_file('plain.jpg')) |
|
337 | file_name = filesystem.get_file_name(media.get_metadata()) |
|
338 | ||
339 | if hasattr(load_config, 'config'): |
|
340 | del load_config.config |
|
341 | ||
342 | assert file_name == helper.path_tz_fix('2015-12-05-plain.jpg'), file_name |
|
343 | ||
344 | @mock.patch('elodie.config.config_file', '%s/config.ini-filename-custom-with-uppercase' % gettempdir()) |
|
345 | def test_get_file_name_custom_with_upper_capitalization(): |
|
@@ 302-321 (lines=20) @@ | ||
299 | ||
300 | assert file_name == helper.path_tz_fix('2015-12-05-plain.jpg'), file_name |
|
301 | ||
302 | @mock.patch('elodie.config.config_file', '%s/config.ini-filename-custom-with-lowercase' % gettempdir()) |
|
303 | def test_get_file_name_custom_with_lower_capitalization(): |
|
304 | with open('%s/config.ini-filename-custom-with-lowercase' % gettempdir(), 'w') as f: |
|
305 | f.write(""" |
|
306 | [File] |
|
307 | date=%Y-%m-%d |
|
308 | name=%date-%original_name-%title.%extension |
|
309 | capitalization=lower |
|
310 | """) |
|
311 | if hasattr(load_config, 'config'): |
|
312 | del load_config.config |
|
313 | ||
314 | filesystem = FileSystem() |
|
315 | media = Photo(helper.get_file('plain.jpg')) |
|
316 | file_name = filesystem.get_file_name(media.get_metadata()) |
|
317 | ||
318 | if hasattr(load_config, 'config'): |
|
319 | del load_config.config |
|
320 | ||
321 | assert file_name == helper.path_tz_fix('2015-12-05-plain.jpg'), file_name |
|
322 | ||
323 | @mock.patch('elodie.config.config_file', '%s/config.ini-filename-custom-with-invalidcase' % gettempdir()) |
|
324 | def test_get_file_name_custom_with_invalid_capitalization(): |
|
@@ 581-599 (lines=19) @@ | ||
578 | ||
579 | assert path == os.path.join('2015','12','Sunnyvale, California'), path |
|
580 | ||
581 | @mock.patch('elodie.config.config_file', '%s/config.ini-location-date' % gettempdir()) |
|
582 | def test_get_folder_path_with_with_only_one_level(): |
|
583 | with open('%s/config.ini-location-date' % gettempdir(), 'w') as f: |
|
584 | f.write(""" |
|
585 | [Directory] |
|
586 | year=%Y |
|
587 | full_path=%year |
|
588 | """) |
|
589 | ||
590 | if hasattr(load_config, 'config'): |
|
591 | del load_config.config |
|
592 | ||
593 | filesystem = FileSystem() |
|
594 | media = Photo(helper.get_file('plain.jpg')) |
|
595 | path = filesystem.get_folder_path(media.get_metadata()) |
|
596 | if hasattr(load_config, 'config'): |
|
597 | del load_config.config |
|
598 | ||
599 | assert path == os.path.join('2015'), path |
|
600 | ||
601 | def test_get_folder_path_with_location_and_title(): |
|
602 | filesystem = FileSystem() |
|
@@ 439-457 (lines=19) @@ | ||
436 | ||
437 | assert path == os.path.join('2015'), path |
|
438 | ||
439 | @mock.patch('elodie.config.config_file', '%s/config.ini-combined-date-and-album' % gettempdir()) |
|
440 | def test_get_folder_path_with_combined_date_and_album(): |
|
441 | # gh-239 |
|
442 | with open('%s/config.ini-combined-date-and-album' % gettempdir(), 'w') as f: |
|
443 | f.write(""" |
|
444 | [Directory] |
|
445 | date=%Y-%m-%b |
|
446 | custom=%date %album |
|
447 | full_path=%custom |
|
448 | """) |
|
449 | if hasattr(load_config, 'config'): |
|
450 | del load_config.config |
|
451 | filesystem = FileSystem() |
|
452 | media = Photo(helper.get_file('with-album.jpg')) |
|
453 | path = filesystem.get_folder_path(media.get_metadata()) |
|
454 | if hasattr(load_config, 'config'): |
|
455 | del load_config.config |
|
456 | ||
457 | assert path == '2015-12-Dec Test Album', path |
|
458 | ||
459 | @mock.patch('elodie.config.config_file', '%s/config.ini-combined-date-album-location-fallback' % gettempdir()) |
|
460 | def test_get_folder_path_with_album_and_location_fallback(): |
|
@@ 282-300 (lines=19) @@ | ||
279 | ||
280 | assert file_name == helper.path_tz_fix('2015-12-05-with-title-some-title.jpg'), file_name |
|
281 | ||
282 | @mock.patch('elodie.config.config_file', '%s/config.ini-filename-custom-with-empty-value' % gettempdir()) |
|
283 | def test_get_file_name_custom_with_empty_value(): |
|
284 | with open('%s/config.ini-filename-custom-with-empty-value' % gettempdir(), 'w') as f: |
|
285 | f.write(""" |
|
286 | [File] |
|
287 | date=%Y-%m-%d |
|
288 | name=%date-%original_name-%title.%extension |
|
289 | """) |
|
290 | if hasattr(load_config, 'config'): |
|
291 | del load_config.config |
|
292 | ||
293 | filesystem = FileSystem() |
|
294 | media = Photo(helper.get_file('plain.jpg')) |
|
295 | file_name = filesystem.get_file_name(media.get_metadata()) |
|
296 | ||
297 | if hasattr(load_config, 'config'): |
|
298 | del load_config.config |
|
299 | ||
300 | assert file_name == helper.path_tz_fix('2015-12-05-plain.jpg'), file_name |
|
301 | ||
302 | @mock.patch('elodie.config.config_file', '%s/config.ini-filename-custom-with-lowercase' % gettempdir()) |
|
303 | def test_get_file_name_custom_with_lower_capitalization(): |
|
@@ 262-280 (lines=19) @@ | ||
259 | ||
260 | assert file_name == helper.path_tz_fix('2015-12-dec-plain.jpg'), file_name |
|
261 | ||
262 | @mock.patch('elodie.config.config_file', '%s/config.ini-filename-custom-with-title' % gettempdir()) |
|
263 | def test_get_file_name_custom_with_title(): |
|
264 | with open('%s/config.ini-filename-custom-with-title' % gettempdir(), 'w') as f: |
|
265 | f.write(""" |
|
266 | [File] |
|
267 | date=%Y-%m-%d |
|
268 | name=%date-%original_name-%title.%extension |
|
269 | """) |
|
270 | if hasattr(load_config, 'config'): |
|
271 | del load_config.config |
|
272 | ||
273 | filesystem = FileSystem() |
|
274 | media = Photo(helper.get_file('with-title.jpg')) |
|
275 | file_name = filesystem.get_file_name(media.get_metadata()) |
|
276 | ||
277 | if hasattr(load_config, 'config'): |
|
278 | del load_config.config |
|
279 | ||
280 | assert file_name == helper.path_tz_fix('2015-12-05-with-title-some-title.jpg'), file_name |
|
281 | ||
282 | @mock.patch('elodie.config.config_file', '%s/config.ini-filename-custom-with-empty-value' % gettempdir()) |
|
283 | def test_get_file_name_custom_with_empty_value(): |
|
@@ 242-260 (lines=19) @@ | ||
239 | ||
240 | assert file_name == helper.path_tz_fix('2015-12-05_00-59-26-plain-with-spaces-and-uppercase-123.jpg'), file_name |
|
241 | ||
242 | @mock.patch('elodie.config.config_file', '%s/config.ini-filename-custom' % gettempdir()) |
|
243 | def test_get_file_name_custom(): |
|
244 | with open('%s/config.ini-filename-custom' % gettempdir(), 'w') as f: |
|
245 | f.write(""" |
|
246 | [File] |
|
247 | date=%Y-%m-%b |
|
248 | name=%date-%original_name.%extension |
|
249 | """) |
|
250 | if hasattr(load_config, 'config'): |
|
251 | del load_config.config |
|
252 | ||
253 | filesystem = FileSystem() |
|
254 | media = Photo(helper.get_file('plain.jpg')) |
|
255 | file_name = filesystem.get_file_name(media.get_metadata()) |
|
256 | ||
257 | if hasattr(load_config, 'config'): |
|
258 | del load_config.config |
|
259 | ||
260 | assert file_name == helper.path_tz_fix('2015-12-dec-plain.jpg'), file_name |
|
261 | ||
262 | @mock.patch('elodie.config.config_file', '%s/config.ini-filename-custom-with-title' % gettempdir()) |
|
263 | def test_get_file_name_custom_with_title(): |
|
@@ 420-437 (lines=18) @@ | ||
417 | ||
418 | assert path == os.path.join('nomake', 'nomodel'), path |
|
419 | ||
420 | @mock.patch('elodie.config.config_file', '%s/config.ini-int-in-component-path' % gettempdir()) |
|
421 | def test_get_folder_path_with_int_in_config_component(): |
|
422 | # gh-239 |
|
423 | with open('%s/config.ini-int-in-component-path' % gettempdir(), 'w') as f: |
|
424 | f.write(""" |
|
425 | [Directory] |
|
426 | date=%Y |
|
427 | full_path=%date |
|
428 | """) |
|
429 | if hasattr(load_config, 'config'): |
|
430 | del load_config.config |
|
431 | filesystem = FileSystem() |
|
432 | media = Photo(helper.get_file('plain.jpg')) |
|
433 | path = filesystem.get_folder_path(media.get_metadata()) |
|
434 | if hasattr(load_config, 'config'): |
|
435 | del load_config.config |
|
436 | ||
437 | assert path == os.path.join('2015'), path |
|
438 | ||
439 | @mock.patch('elodie.config.config_file', '%s/config.ini-combined-date-and-album' % gettempdir()) |
|
440 | def test_get_folder_path_with_combined_date_and_album(): |
|
@@ 403-418 (lines=16) @@ | ||
400 | ||
401 | assert path == os.path.join('Canon', 'Canon EOS REBEL T2i'), path |
|
402 | ||
403 | @mock.patch('elodie.config.config_file', '%s/config.ini-original-with-camera-make-and-model-fallback' % gettempdir()) |
|
404 | def test_get_folder_path_with_camera_make_and_model_fallback(): |
|
405 | with open('%s/config.ini-original-with-camera-make-and-model-fallback' % gettempdir(), 'w') as f: |
|
406 | f.write(""" |
|
407 | [Directory] |
|
408 | full_path=%camera_make|"nomake"/%camera_model|"nomodel" |
|
409 | """) |
|
410 | if hasattr(load_config, 'config'): |
|
411 | del load_config.config |
|
412 | filesystem = FileSystem() |
|
413 | media = Photo(helper.get_file('no-exif.jpg')) |
|
414 | path = filesystem.get_folder_path(media.get_metadata()) |
|
415 | if hasattr(load_config, 'config'): |
|
416 | del load_config.config |
|
417 | ||
418 | assert path == os.path.join('nomake', 'nomodel'), path |
|
419 | ||
420 | @mock.patch('elodie.config.config_file', '%s/config.ini-int-in-component-path' % gettempdir()) |
|
421 | def test_get_folder_path_with_int_in_config_component(): |
|
@@ 386-401 (lines=16) @@ | ||
383 | ||
384 | assert path == os.path.join('2015-12-Dec','Sunnyvale'), path |
|
385 | ||
386 | @mock.patch('elodie.config.config_file', '%s/config.ini-original-with-camera-make-and-model' % gettempdir()) |
|
387 | def test_get_folder_path_with_camera_make_and_model(): |
|
388 | with open('%s/config.ini-original-with-camera-make-and-model' % gettempdir(), 'w') as f: |
|
389 | f.write(""" |
|
390 | [Directory] |
|
391 | full_path=%camera_make/%camera_model |
|
392 | """) |
|
393 | if hasattr(load_config, 'config'): |
|
394 | del load_config.config |
|
395 | filesystem = FileSystem() |
|
396 | media = Photo(helper.get_file('plain.jpg')) |
|
397 | path = filesystem.get_folder_path(media.get_metadata()) |
|
398 | if hasattr(load_config, 'config'): |
|
399 | del load_config.config |
|
400 | ||
401 | assert path == os.path.join('Canon', 'Canon EOS REBEL T2i'), path |
|
402 | ||
403 | @mock.patch('elodie.config.config_file', '%s/config.ini-original-with-camera-make-and-model-fallback' % gettempdir()) |
|
404 | def test_get_folder_path_with_camera_make_and_model_fallback(): |
|
@@ 500-512 (lines=13) @@ | ||
497 | ||
498 | assert path == os.path.join('2015-12-Dec','Unknown Location'), path |
|
499 | ||
500 | @mock.patch('elodie.config.config_file', '%s/config.ini-original-default-unknown-location' % gettempdir()) |
|
501 | def test_get_folder_path_with_original_default_unknown_location(): |
|
502 | with open('%s/config.ini-original-default-with-unknown-location' % gettempdir(), 'w') as f: |
|
503 | f.write('') |
|
504 | if hasattr(load_config, 'config'): |
|
505 | del load_config.config |
|
506 | filesystem = FileSystem() |
|
507 | media = Photo(helper.get_file('plain.jpg')) |
|
508 | path = filesystem.get_folder_path(media.get_metadata()) |
|
509 | if hasattr(load_config, 'config'): |
|
510 | del load_config.config |
|
511 | ||
512 | assert path == os.path.join('2015-12-Dec','Unknown Location'), path |
|
513 | ||
514 | @mock.patch('elodie.config.config_file', '%s/config.ini-custom-path' % gettempdir()) |
|
515 | def test_get_folder_path_with_custom_path(): |