Merge pull request #133 from jmathai/geolocation-tests
gh-40 Increase test coverage for media and geolocation modules
This commit is contained in:
commit
fbaef53033
|
@ -17,6 +17,8 @@ import urllib.error
|
||||||
from elodie import constants
|
from elodie import constants
|
||||||
from elodie.localstorage import Db
|
from elodie.localstorage import Db
|
||||||
|
|
||||||
|
__KEY__ = None
|
||||||
|
|
||||||
|
|
||||||
def coordinates_by_name(name):
|
def coordinates_by_name(name):
|
||||||
# Try to get cached location first
|
# Try to get cached location first
|
||||||
|
@ -95,6 +97,10 @@ def dms_string(decimal, type='latitude'):
|
||||||
|
|
||||||
|
|
||||||
def get_key():
|
def get_key():
|
||||||
|
global __KEY__
|
||||||
|
if __KEY__ is not None:
|
||||||
|
return __KEY__
|
||||||
|
|
||||||
config_file = '%s/config.ini' % constants.application_directory
|
config_file = '%s/config.ini' % constants.application_directory
|
||||||
if not path.exists(config_file):
|
if not path.exists(config_file):
|
||||||
return None
|
return None
|
||||||
|
@ -104,7 +110,8 @@ def get_key():
|
||||||
if('MapQuest' not in config.sections()):
|
if('MapQuest' not in config.sections()):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return config.get('MapQuest', 'key')
|
__KEY__ = config.get('MapQuest', 'key')
|
||||||
|
return __KEY__
|
||||||
|
|
||||||
|
|
||||||
def place_name(lat, lon):
|
def place_name(lat, lon):
|
||||||
|
|
|
@ -75,3 +75,13 @@ def test_dms_string_longitude():
|
||||||
|
|
||||||
assert check_value in dms_string, '%s not in %s' % (check_value, dms_string)
|
assert check_value in dms_string, '%s not in %s' % (check_value, dms_string)
|
||||||
assert str(dms[0]) in dms_string, '%s not in %s' % (dms[0], dms_string)
|
assert str(dms[0]) in dms_string, '%s not in %s' % (dms[0], dms_string)
|
||||||
|
|
||||||
|
def test_reverse_lookup_with_invalid_key():
|
||||||
|
geolocation.__KEY__ = 'invalid_key'
|
||||||
|
res = geolocation.reverse_lookup(123.45, 123.45)
|
||||||
|
assert res is None, res
|
||||||
|
|
||||||
|
def test_lookup_with_invalid_key():
|
||||||
|
geolocation.__KEY__ = 'invalid_key'
|
||||||
|
res = geolocation.lookup('foo')
|
||||||
|
assert res is None, res
|
||||||
|
|
|
@ -24,6 +24,14 @@ from elodie.media.video import Video
|
||||||
os.environ['TZ'] = 'GMT'
|
os.environ['TZ'] = 'GMT'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_class_by_file_without_extension():
|
||||||
|
base_file = helper.get_file('withoutextension')
|
||||||
|
|
||||||
|
cls = Base.get_class_by_file(base_file, [Audio, Text, Photo, Video])
|
||||||
|
|
||||||
|
assert cls is None, cls
|
||||||
|
|
||||||
def test_set_album_from_folder_invalid_file():
|
def test_set_album_from_folder_invalid_file():
|
||||||
temporary_folder, folder = helper.create_working_folder()
|
temporary_folder, folder = helper.create_working_folder()
|
||||||
|
|
||||||
|
@ -38,9 +46,63 @@ def test_set_album_from_folder_invalid_file():
|
||||||
|
|
||||||
assert status == False, status
|
assert status == False, status
|
||||||
|
|
||||||
def test_get_class_by_file_without_extension():
|
def test_set_album_from_folder():
|
||||||
base_file = helper.get_file('withoutextension')
|
temporary_folder, folder = helper.create_working_folder()
|
||||||
|
|
||||||
cls = Base.get_class_by_file(base_file, [Audio, Text, Photo, Video])
|
origin = '%s/photo.jpg' % folder
|
||||||
|
shutil.copyfile(helper.get_file('plain.jpg'), origin)
|
||||||
assert cls is None, cls
|
|
||||||
|
photo = Photo(origin)
|
||||||
|
metadata = photo.get_metadata()
|
||||||
|
|
||||||
|
assert metadata['album'] is None, metadata['album']
|
||||||
|
|
||||||
|
new_album_name = os.path.split(folder)[1]
|
||||||
|
status = photo.set_album_from_folder()
|
||||||
|
|
||||||
|
assert status == True, status
|
||||||
|
|
||||||
|
photo_new = Photo(origin)
|
||||||
|
metadata_new = photo_new.get_metadata()
|
||||||
|
|
||||||
|
shutil.rmtree(folder)
|
||||||
|
|
||||||
|
assert metadata_new['album'] == new_album_name, metadata_new['album']
|
||||||
|
|
||||||
|
def test_set_metadata():
|
||||||
|
temporary_folder, folder = helper.create_working_folder()
|
||||||
|
|
||||||
|
origin = '%s/photo.jpg' % folder
|
||||||
|
shutil.copyfile(helper.get_file('plain.jpg'), origin)
|
||||||
|
|
||||||
|
photo = Photo(origin)
|
||||||
|
|
||||||
|
metadata = photo.get_metadata()
|
||||||
|
|
||||||
|
assert metadata['title'] == None, metadata['title']
|
||||||
|
|
||||||
|
new_title = 'Some Title'
|
||||||
|
photo.set_metadata(title = new_title)
|
||||||
|
|
||||||
|
new_metadata = photo.get_metadata()
|
||||||
|
|
||||||
|
assert new_metadata['title'] == new_title, new_metadata['title']
|
||||||
|
|
||||||
|
def test_set_metadata_basename():
|
||||||
|
temporary_folder, folder = helper.create_working_folder()
|
||||||
|
|
||||||
|
origin = '%s/photo.jpg' % folder
|
||||||
|
shutil.copyfile(helper.get_file('plain.jpg'), origin)
|
||||||
|
|
||||||
|
photo = Photo(origin)
|
||||||
|
|
||||||
|
metadata = photo.get_metadata()
|
||||||
|
|
||||||
|
assert metadata['base_name'] == 'photo', metadata['base_name']
|
||||||
|
|
||||||
|
new_basename = 'Some Base Name'
|
||||||
|
photo.set_metadata_basename(new_basename)
|
||||||
|
|
||||||
|
new_metadata = photo.get_metadata()
|
||||||
|
|
||||||
|
assert new_metadata['base_name'] == new_basename, new_metadata['base_name']
|
||||||
|
|
Loading…
Reference in New Issue