aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mediagoblin.ini2
-rw-r--r--mediagoblin/config_spec.ini1
-rw-r--r--mediagoblin/init/celery/from_tests.py33
-rw-r--r--mediagoblin/media_types/image/__init__.py23
-rw-r--r--mediagoblin/messages.py14
-rw-r--r--mediagoblin/templates/mediagoblin/user_pages/media.html17
-rw-r--r--mediagoblin/tests/__init__.py4
-rw-r--r--mediagoblin/tests/test_messages.py16
-rw-r--r--mediagoblin/tests/test_mgoblin_app.ini4
-rw-r--r--mediagoblin/tests/test_processing.py4
-rw-r--r--mediagoblin/tests/tools.py28
-rwxr-xr-xruntests.sh4
12 files changed, 69 insertions, 81 deletions
diff --git a/mediagoblin.ini b/mediagoblin.ini
index 43621107..4906546a 100644
--- a/mediagoblin.ini
+++ b/mediagoblin.ini
@@ -11,7 +11,7 @@ email_sender_address = "notice@mediagoblin.example.org"
## Uncomment and change to your DB's appropiate setting.
## Default is a local sqlite db "mediagoblin.db".
-# sql_engine = postgresql:///gmg
+# sql_engine = postgresql:///mediagoblin
# set to false to enable sending notices
email_debug_mode = true
diff --git a/mediagoblin/config_spec.ini b/mediagoblin/config_spec.ini
index 6c00aa58..2af4adb2 100644
--- a/mediagoblin/config_spec.ini
+++ b/mediagoblin/config_spec.ini
@@ -61,6 +61,7 @@ csrf_cookie_name = string(default='mediagoblin_csrftoken')
push_urls = string_list(default=list())
exif_visible = boolean(default=False)
+original_date_visible = boolean(default=False)
# Theming stuff
theme_install_dir = string(default="%(here)s/user_dev/themes/")
diff --git a/mediagoblin/init/celery/from_tests.py b/mediagoblin/init/celery/from_tests.py
deleted file mode 100644
index 3149e1ba..00000000
--- a/mediagoblin/init/celery/from_tests.py
+++ /dev/null
@@ -1,33 +0,0 @@
-# GNU MediaGoblin -- federated, autonomous media hosting
-# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-import os
-
-from mediagoblin.tests.tools import TEST_APP_CONFIG
-from mediagoblin.init.celery.from_celery import setup_self
-
-
-OUR_MODULENAME = __name__
-CELERY_SETUP = False
-
-
-if os.environ.get('CELERY_CONFIG_MODULE') == OUR_MODULENAME:
- if CELERY_SETUP:
- pass
- else:
- setup_self(check_environ_for_conf=False, module_name=OUR_MODULENAME,
- default_conf_file=TEST_APP_CONFIG)
- CELERY_SETUP = True
diff --git a/mediagoblin/media_types/image/__init__.py b/mediagoblin/media_types/image/__init__.py
index 15cc8dda..5130ef48 100644
--- a/mediagoblin/media_types/image/__init__.py
+++ b/mediagoblin/media_types/image/__init__.py
@@ -14,6 +14,8 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+import datetime
+
from mediagoblin.media_types import MediaManagerBase
from mediagoblin.media_types.image.processing import process_image, \
sniff_handler
@@ -28,5 +30,26 @@ class ImageMediaManager(MediaManagerBase):
accepted_extensions = ["jpg", "jpeg", "png", "gif", "tiff"]
media_fetch_order = [u'medium', u'original', u'thumb']
+ def get_original_date(self):
+ """
+ Get the original date and time from the EXIF information. Returns
+ either a datetime object or None (if anything goes wrong)
+ """
+ if not self.entry.media_data or not self.entry.media_data.exif_all:
+ return None
+
+ try:
+ # Try wrapped around all since exif_all might be none,
+ # EXIF DateTimeOriginal or printable might not exist
+ # or strptime might not be able to parse date correctly
+ exif_date = self.entry.media_data.exif_all[
+ 'EXIF DateTimeOriginal']['printable']
+ original_date = datetime.datetime.strptime(
+ exif_date,
+ '%Y:%m:%d %H:%M:%S')
+ return original_date
+ except (KeyError, ValueError):
+ return None
+
MEDIA_MANAGER = ImageMediaManager
diff --git a/mediagoblin/messages.py b/mediagoblin/messages.py
index 80d8ece7..d58f13d4 100644
--- a/mediagoblin/messages.py
+++ b/mediagoblin/messages.py
@@ -14,16 +14,24 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+from mediagoblin.tools import common
+
DEBUG = 'debug'
INFO = 'info'
SUCCESS = 'success'
WARNING = 'warning'
ERROR = 'error'
+ADD_MESSAGE_TEST = []
+
def add_message(request, level, text):
messages = request.session.setdefault('messages', [])
messages.append({'level': level, 'text': text})
+
+ if common.TESTS_ENABLED:
+ ADD_MESSAGE_TEST.append(messages)
+
request.session.save()
@@ -33,4 +41,10 @@ def fetch_messages(request, clear_from_session=True):
# Save that we removed the messages from the session
request.session['messages'] = []
request.session.save()
+
return messages
+
+
+def clear_add_message():
+ global ADD_MESSAGE_TEST
+ ADD_MESSAGE_TEST = []
diff --git a/mediagoblin/templates/mediagoblin/user_pages/media.html b/mediagoblin/templates/mediagoblin/user_pages/media.html
index 6d32d009..667510d5 100644
--- a/mediagoblin/templates/mediagoblin/user_pages/media.html
+++ b/mediagoblin/templates/mediagoblin/user_pages/media.html
@@ -147,12 +147,27 @@
{% endif %}
</div>
<div class="media_sidebar">
- <h3>Added</h3>
+ <h3>{% trans %}Added{% endtrans %}</h3>
<p><span title="{{ media.created.strftime("%I:%M%p %Y-%m-%d") }}">
{%- trans formatted_time=timesince(media.created) -%}
{{ formatted_time }} ago
{%- endtrans -%}
</span></p>
+
+ {% if app_config['original_date_visible'] %}
+ {% set original_date = media.media_manager.get_original_date() %}
+
+ {% if original_date %}
+ <h3>{% trans %}Created{% endtrans %}</h3>
+
+ <p><span title="{{ original_date.strftime("%I:%M%p %Y-%m-%d") }}">
+ {%- trans formatted_time=timesince(original_date) -%}
+ {{ formatted_time }} ago
+ {%- endtrans -%}
+ </span></p>
+ {%- endif %}
+ {% endif %}
+
{% if media.tags %}
{% include "mediagoblin/utils/tags.html" %}
{% endif %}
diff --git a/mediagoblin/tests/__init__.py b/mediagoblin/tests/__init__.py
index 5a3235c6..7a88281e 100644
--- a/mediagoblin/tests/__init__.py
+++ b/mediagoblin/tests/__init__.py
@@ -18,12 +18,10 @@ import os
import shutil
from mediagoblin import mg_globals
-from mediagoblin.tests.tools import (
- TEST_USER_DEV, suicide_if_bad_celery_environ)
+from mediagoblin.tests.tools import TEST_USER_DEV
def setup_package():
- suicide_if_bad_celery_environ()
import warnings
from sqlalchemy.exc import SAWarning
diff --git a/mediagoblin/tests/test_messages.py b/mediagoblin/tests/test_messages.py
index 3ac917b0..22f9e800 100644
--- a/mediagoblin/tests/test_messages.py
+++ b/mediagoblin/tests/test_messages.py
@@ -14,7 +14,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-from mediagoblin.messages import fetch_messages, add_message
+from mediagoblin import messages
from mediagoblin.tools import template
@@ -32,11 +32,19 @@ def test_messages(test_app):
# The message queue should be empty
assert request.session.get('messages', []) == []
+ # First of all, we should clear the messages queue
+ messages.clear_add_message()
# Adding a message should modify the session accordingly
- add_message(request, 'herp_derp', 'First!')
+ messages.add_message(request, 'herp_derp', 'First!')
test_msg_queue = [{'text': 'First!', 'level': 'herp_derp'}]
- assert request.session['messages'] == test_msg_queue
+
+ # Alternative tests to the following, test divided in two steps:
+ # assert request.session['messages'] == test_msg_queue
+ # 1. Tests if add_message worked
+ assert messages.ADD_MESSAGE_TEST[-1] == test_msg_queue
+ # 2. Tests if add_message updated session information
+ assert messages.ADD_MESSAGE_TEST[-1] == request.session['messages']
# fetch_messages should return and empty the queue
- assert fetch_messages(request) == test_msg_queue
+ assert messages.fetch_messages(request) == test_msg_queue
assert request.session.get('messages') == []
diff --git a/mediagoblin/tests/test_mgoblin_app.ini b/mediagoblin/tests/test_mgoblin_app.ini
index 9f95a398..8c668356 100644
--- a/mediagoblin/tests/test_mgoblin_app.ini
+++ b/mediagoblin/tests/test_mgoblin_app.ini
@@ -12,10 +12,6 @@ tags_max_length = 50
# So we can start to test attachments:
allow_attachments = True
-# Celery shouldn't be set up by the application as it's setup via
-# mediagoblin.init.celery.from_celery
-celery_setup_elsewhere = true
-
media_types = mediagoblin.media_types.image, mediagoblin.media_types.pdf
[storage:publicstore]
diff --git a/mediagoblin/tests/test_processing.py b/mediagoblin/tests/test_processing.py
index fe8489aa..591add96 100644
--- a/mediagoblin/tests/test_processing.py
+++ b/mediagoblin/tests/test_processing.py
@@ -1,7 +1,5 @@
#!/usr/bin/env python
-from nose.tools import assert_equal
-
from mediagoblin import processing
class TestProcessing(object):
@@ -10,7 +8,7 @@ class TestProcessing(object):
result = builder.fill(format)
if output is None:
return result
- assert_equal(output, result)
+ assert output == result
def test_easy_filename_fill(self):
self.run_fill('/home/user/foo.TXT', '{basename}bar{ext}', 'foobar.txt')
diff --git a/mediagoblin/tests/tools.py b/mediagoblin/tests/tools.py
index 52635e18..794ed940 100644
--- a/mediagoblin/tests/tools.py
+++ b/mediagoblin/tests/tools.py
@@ -33,7 +33,6 @@ from mediagoblin.db.base import Session
from mediagoblin.meddleware import BaseMeddleware
from mediagoblin.auth.lib import bcrypt_gen_password_hash
from mediagoblin.gmg_commands.dbupdate import run_dbupdate
-from mediagoblin.init.celery import setup_celery_app
MEDIAGOBLIN_TEST_DB_NAME = u'__mediagoblin_tests__'
@@ -47,16 +46,6 @@ TEST_USER_DEV = pkg_resources.resource_filename(
USER_DEV_DIRECTORIES_TO_SETUP = ['media/public', 'media/queue']
-BAD_CELERY_MESSAGE = """\
-Sorry, you *absolutely* must run tests with the
-mediagoblin.init.celery.from_tests module. Like so:
-
-$ CELERY_CONFIG_MODULE=mediagoblin.init.celery.from_tests {0}
-""".format(sys.argv[0])
-
-
-class BadCeleryEnviron(Exception): pass
-
class TestingMeddleware(BaseMeddleware):
"""
@@ -97,12 +86,6 @@ class TestingMeddleware(BaseMeddleware):
return
-def suicide_if_bad_celery_environ():
- if not os.environ.get('CELERY_CONFIG_MODULE') == \
- 'mediagoblin.init.celery.from_tests':
- raise BadCeleryEnviron(BAD_CELERY_MESSAGE)
-
-
def get_app(request, paste_config=None, mgoblin_config=None):
"""Create a MediaGoblin app for testing.
@@ -127,14 +110,6 @@ def get_app(request, paste_config=None, mgoblin_config=None):
shutil.copyfile(paste_config, new_paste_config)
shutil.copyfile(mgoblin_config, new_mgoblin_config)
- suicide_if_bad_celery_environ()
-
- # Make sure we've turned on testing
- testing._activate_testing()
-
- # Leave this imported as it sets up celery.
- from mediagoblin.init.celery import from_tests
-
Session.rollback()
Session.remove()
@@ -154,9 +129,6 @@ def get_app(request, paste_config=None, mgoblin_config=None):
test_app = loadapp(
'config:' + new_paste_config)
- # Re-setup celery
- setup_celery_app(app_config, global_config)
-
# Insert the TestingMeddleware, which can do some
# sanity checks on every request/response.
# Doing it this way is probably not the cleanest way.
diff --git a/runtests.sh b/runtests.sh
index 382e2fa6..00164a78 100755
--- a/runtests.sh
+++ b/runtests.sh
@@ -39,10 +39,6 @@ else
fi
-CELERY_CONFIG_MODULE=mediagoblin.init.celery.from_tests
-export CELERY_CONFIG_MODULE
-echo "+ CELERY_CONFIG_MODULE=$CELERY_CONFIG_MODULE"
-
# Look to see if the user has specified a specific directory/file to
# run tests out of. If not we'll need to pass along
# mediagoblin/tests/ later very specifically. Otherwise py.test