Code Duplication    Length = 19-20 lines in 6 locations

elodie/tests/filesystem_test.py 6 locations

@@ 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)
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)
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)
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():
@@ 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)
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)
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)
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():