Merge branch 'master' into 623_context_hooks
This commit is contained in:
commit
725404236e
@ -11,7 +11,7 @@ email_sender_address = "notice@mediagoblin.example.org"
|
|||||||
|
|
||||||
## Uncomment and change to your DB's appropiate setting.
|
## Uncomment and change to your DB's appropiate setting.
|
||||||
## Default is a local sqlite db "mediagoblin.db".
|
## Default is a local sqlite db "mediagoblin.db".
|
||||||
# sql_engine = postgresql:///gmg
|
# sql_engine = postgresql:///mediagoblin
|
||||||
|
|
||||||
# set to false to enable sending notices
|
# set to false to enable sending notices
|
||||||
email_debug_mode = true
|
email_debug_mode = true
|
||||||
|
@ -61,6 +61,7 @@ csrf_cookie_name = string(default='mediagoblin_csrftoken')
|
|||||||
push_urls = string_list(default=list())
|
push_urls = string_list(default=list())
|
||||||
|
|
||||||
exif_visible = boolean(default=False)
|
exif_visible = boolean(default=False)
|
||||||
|
original_date_visible = boolean(default=False)
|
||||||
|
|
||||||
# Theming stuff
|
# Theming stuff
|
||||||
theme_install_dir = string(default="%(here)s/user_dev/themes/")
|
theme_install_dir = string(default="%(here)s/user_dev/themes/")
|
||||||
|
@ -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
|
|
@ -14,6 +14,8 @@
|
|||||||
# You should have received a copy of the GNU Affero General Public License
|
# 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/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
|
||||||
from mediagoblin.media_types import MediaManagerBase
|
from mediagoblin.media_types import MediaManagerBase
|
||||||
from mediagoblin.media_types.image.processing import process_image, \
|
from mediagoblin.media_types.image.processing import process_image, \
|
||||||
sniff_handler
|
sniff_handler
|
||||||
@ -28,5 +30,26 @@ class ImageMediaManager(MediaManagerBase):
|
|||||||
accepted_extensions = ["jpg", "jpeg", "png", "gif", "tiff"]
|
accepted_extensions = ["jpg", "jpeg", "png", "gif", "tiff"]
|
||||||
media_fetch_order = [u'medium', u'original', u'thumb']
|
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
|
MEDIA_MANAGER = ImageMediaManager
|
||||||
|
@ -14,16 +14,24 @@
|
|||||||
# You should have received a copy of the GNU Affero General Public License
|
# 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/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from mediagoblin.tools import common
|
||||||
|
|
||||||
DEBUG = 'debug'
|
DEBUG = 'debug'
|
||||||
INFO = 'info'
|
INFO = 'info'
|
||||||
SUCCESS = 'success'
|
SUCCESS = 'success'
|
||||||
WARNING = 'warning'
|
WARNING = 'warning'
|
||||||
ERROR = 'error'
|
ERROR = 'error'
|
||||||
|
|
||||||
|
ADD_MESSAGE_TEST = []
|
||||||
|
|
||||||
|
|
||||||
def add_message(request, level, text):
|
def add_message(request, level, text):
|
||||||
messages = request.session.setdefault('messages', [])
|
messages = request.session.setdefault('messages', [])
|
||||||
messages.append({'level': level, 'text': text})
|
messages.append({'level': level, 'text': text})
|
||||||
|
|
||||||
|
if common.TESTS_ENABLED:
|
||||||
|
ADD_MESSAGE_TEST.append(messages)
|
||||||
|
|
||||||
request.session.save()
|
request.session.save()
|
||||||
|
|
||||||
|
|
||||||
@ -33,4 +41,10 @@ def fetch_messages(request, clear_from_session=True):
|
|||||||
# Save that we removed the messages from the session
|
# Save that we removed the messages from the session
|
||||||
request.session['messages'] = []
|
request.session['messages'] = []
|
||||||
request.session.save()
|
request.session.save()
|
||||||
|
|
||||||
return messages
|
return messages
|
||||||
|
|
||||||
|
|
||||||
|
def clear_add_message():
|
||||||
|
global ADD_MESSAGE_TEST
|
||||||
|
ADD_MESSAGE_TEST = []
|
||||||
|
@ -147,12 +147,27 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<div class="media_sidebar">
|
<div class="media_sidebar">
|
||||||
<h3>Added</h3>
|
<h3>{% trans %}Added{% endtrans %}</h3>
|
||||||
<p><span title="{{ media.created.strftime("%I:%M%p %Y-%m-%d") }}">
|
<p><span title="{{ media.created.strftime("%I:%M%p %Y-%m-%d") }}">
|
||||||
{%- trans formatted_time=timesince(media.created) -%}
|
{%- trans formatted_time=timesince(media.created) -%}
|
||||||
{{ formatted_time }} ago
|
{{ formatted_time }} ago
|
||||||
{%- endtrans -%}
|
{%- endtrans -%}
|
||||||
</span></p>
|
</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 %}
|
{% if media.tags %}
|
||||||
{% include "mediagoblin/utils/tags.html" %}
|
{% include "mediagoblin/utils/tags.html" %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -18,12 +18,10 @@ import os
|
|||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
from mediagoblin import mg_globals
|
from mediagoblin import mg_globals
|
||||||
from mediagoblin.tests.tools import (
|
from mediagoblin.tests.tools import TEST_USER_DEV
|
||||||
TEST_USER_DEV, suicide_if_bad_celery_environ)
|
|
||||||
|
|
||||||
|
|
||||||
def setup_package():
|
def setup_package():
|
||||||
suicide_if_bad_celery_environ()
|
|
||||||
|
|
||||||
import warnings
|
import warnings
|
||||||
from sqlalchemy.exc import SAWarning
|
from sqlalchemy.exc import SAWarning
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
# You should have received a copy of the GNU Affero General Public License
|
# 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/>.
|
# 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
|
from mediagoblin.tools import template
|
||||||
|
|
||||||
|
|
||||||
@ -32,11 +32,19 @@ def test_messages(test_app):
|
|||||||
# The message queue should be empty
|
# The message queue should be empty
|
||||||
assert request.session.get('messages', []) == []
|
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
|
# 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'}]
|
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
|
# 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') == []
|
assert request.session.get('messages') == []
|
||||||
|
@ -12,10 +12,6 @@ tags_max_length = 50
|
|||||||
# So we can start to test attachments:
|
# So we can start to test attachments:
|
||||||
allow_attachments = True
|
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
|
media_types = mediagoblin.media_types.image, mediagoblin.media_types.pdf
|
||||||
|
|
||||||
[storage:publicstore]
|
[storage:publicstore]
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
from nose.tools import assert_equal
|
|
||||||
|
|
||||||
from mediagoblin import processing
|
from mediagoblin import processing
|
||||||
|
|
||||||
class TestProcessing(object):
|
class TestProcessing(object):
|
||||||
@ -10,7 +8,7 @@ class TestProcessing(object):
|
|||||||
result = builder.fill(format)
|
result = builder.fill(format)
|
||||||
if output is None:
|
if output is None:
|
||||||
return result
|
return result
|
||||||
assert_equal(output, result)
|
assert output == result
|
||||||
|
|
||||||
def test_easy_filename_fill(self):
|
def test_easy_filename_fill(self):
|
||||||
self.run_fill('/home/user/foo.TXT', '{basename}bar{ext}', 'foobar.txt')
|
self.run_fill('/home/user/foo.TXT', '{basename}bar{ext}', 'foobar.txt')
|
||||||
|
@ -33,7 +33,6 @@ from mediagoblin.db.base import Session
|
|||||||
from mediagoblin.meddleware import BaseMeddleware
|
from mediagoblin.meddleware import BaseMeddleware
|
||||||
from mediagoblin.auth.lib import bcrypt_gen_password_hash
|
from mediagoblin.auth.lib import bcrypt_gen_password_hash
|
||||||
from mediagoblin.gmg_commands.dbupdate import run_dbupdate
|
from mediagoblin.gmg_commands.dbupdate import run_dbupdate
|
||||||
from mediagoblin.init.celery import setup_celery_app
|
|
||||||
|
|
||||||
|
|
||||||
MEDIAGOBLIN_TEST_DB_NAME = u'__mediagoblin_tests__'
|
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']
|
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):
|
class TestingMeddleware(BaseMeddleware):
|
||||||
"""
|
"""
|
||||||
@ -97,12 +86,6 @@ class TestingMeddleware(BaseMeddleware):
|
|||||||
return
|
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):
|
def get_app(request, paste_config=None, mgoblin_config=None):
|
||||||
"""Create a MediaGoblin app for testing.
|
"""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(paste_config, new_paste_config)
|
||||||
shutil.copyfile(mgoblin_config, new_mgoblin_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.rollback()
|
||||||
Session.remove()
|
Session.remove()
|
||||||
|
|
||||||
@ -154,9 +129,6 @@ def get_app(request, paste_config=None, mgoblin_config=None):
|
|||||||
test_app = loadapp(
|
test_app = loadapp(
|
||||||
'config:' + new_paste_config)
|
'config:' + new_paste_config)
|
||||||
|
|
||||||
# Re-setup celery
|
|
||||||
setup_celery_app(app_config, global_config)
|
|
||||||
|
|
||||||
# Insert the TestingMeddleware, which can do some
|
# Insert the TestingMeddleware, which can do some
|
||||||
# sanity checks on every request/response.
|
# sanity checks on every request/response.
|
||||||
# Doing it this way is probably not the cleanest way.
|
# Doing it this way is probably not the cleanest way.
|
||||||
|
@ -39,10 +39,6 @@ else
|
|||||||
fi
|
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
|
# 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
|
# run tests out of. If not we'll need to pass along
|
||||||
# mediagoblin/tests/ later very specifically. Otherwise py.test
|
# mediagoblin/tests/ later very specifically. Otherwise py.test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user