Passed
Push — master ( 9ddb09...7fc5b5 )
by Jaisen
01:14
created

test_set_album_from_folder_invalid_file()   A

Complexity

Conditions 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nop 0
dl 0
loc 13
rs 10
c 0
b 0
f 0
1
# Project imports
2
import os
3
import sys
4
5
import hashlib
6
import random
7
import re
8
import shutil
9
import string
10
import tempfile
11
import time
12
13
sys.path.insert(0, os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))))))
14
sys.path.insert(0, os.path.abspath(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))))
15
16
import helper
17
from elodie.media.base import Base, get_all_subclasses
18
from elodie.media.media import Media
19
from elodie.media.audio import Audio
20
from elodie.media.text import Text
21
from elodie.media.photo import Photo
22
from elodie.media.video import Video
23
24
os.environ['TZ'] = 'GMT'
25
26
27
def test_get_all_subclasses():
28
    subclasses = get_all_subclasses(Base)
29
    expected = {Media, Base, Text, Photo, Video, Audio}
30
    assert subclasses == expected, subclasses
31
32
def test_get_class_by_file_without_extension():
33
    base_file = helper.get_file('withoutextension')
34
35
    cls = Base.get_class_by_file(base_file, [Audio, Text, Photo, Video])
36
    
37
    assert cls is None, cls
38
39 View Code Duplication
def test_get_original_name():
0 ignored issues
show
Duplication introduced by Jaisen Mathai
This code seems to be duplicated in your project.
Loading history...
40
    temporary_folder, folder = helper.create_working_folder()
41
42
    origin = '%s/%s' % (folder, 'with-original-name.jpg')
43
    file = helper.get_file('with-original-name.jpg')
44
    
45
    shutil.copyfile(file, origin)
46
47
    media = Media.get_class_by_file(origin, [Photo])
48
    original_name = media.get_original_name()
49
50
    assert original_name == 'originalfilename.jpg', original_name
51
52 View Code Duplication
def test_get_original_name_invalid_file():
0 ignored issues
show
Duplication introduced by Jaisen Mathai
This code seems to be duplicated in your project.
Loading history...
53
    temporary_folder, folder = helper.create_working_folder()
54
55
    origin = '%s/%s' % (folder, 'invalid.jpg')
56
    file = helper.get_file('invalid.jpg')
57
    
58
    shutil.copyfile(file, origin)
59
60
    media = Media.get_class_by_file(origin, [Photo])
61
    original_name = media.get_original_name()
62
63
    assert original_name is None, original_name
64
65
def test_set_album_from_folder_invalid_file():
66
    temporary_folder, folder = helper.create_working_folder()
67
68
    base_file = helper.get_file('invalid.jpg')
69
    origin = '%s/invalid.jpg' % folder
70
71
    shutil.copyfile(base_file, origin)
72
73
    base = Base(origin)
74
75
    status = base.set_album_from_folder()
76
77
    assert status == False, status
78
79
def test_set_album_from_folder():
80
    temporary_folder, folder = helper.create_working_folder()
81
82
    origin = '%s/photo.jpg' % folder
83
    shutil.copyfile(helper.get_file('plain.jpg'), origin)
84
85
    photo = Photo(origin)
86
    metadata = photo.get_metadata()
87
88
    assert metadata['album'] is None, metadata['album']
89
90
    new_album_name = os.path.split(folder)[1]
91
    status = photo.set_album_from_folder()
92
93
    assert status == True, status
94
95
    photo_new = Photo(origin)
96
    metadata_new = photo_new.get_metadata()
97
98
    shutil.rmtree(folder)
99
100
    assert metadata_new['album'] == new_album_name, metadata_new['album']
101
102
def test_set_metadata():
103
    temporary_folder, folder = helper.create_working_folder()
104
105
    origin = '%s/photo.jpg' % folder
106
    shutil.copyfile(helper.get_file('plain.jpg'), origin)
107
108
    photo = Photo(origin)
109
110
    metadata = photo.get_metadata()
111
112
    assert metadata['title'] == None, metadata['title']
113
114
    new_title = 'Some Title'
115
    photo.set_metadata(title = new_title)
116
117
    new_metadata = photo.get_metadata()
118
119
    assert new_metadata['title'] == new_title, new_metadata['title']
120
121
def test_set_metadata_basename():
122
    temporary_folder, folder = helper.create_working_folder()
123
124
    origin = '%s/photo.jpg' % folder
125
    shutil.copyfile(helper.get_file('plain.jpg'), origin)
126
127
    photo = Photo(origin)
128
129
    metadata = photo.get_metadata()
130
131
    assert metadata['base_name'] == 'photo', metadata['base_name']
132
133
    new_basename = 'Some Base Name'
134
    photo.set_metadata_basename(new_basename)
135
136
    new_metadata = photo.get_metadata()
137
138
    assert new_metadata['base_name'] == new_basename, new_metadata['base_name']
139