Simple "staticstuff" plugin for writing unit tests on plugin static asset linking.
authorChristopher Allan Webber <cwebber@dustycloud.org>
Wed, 22 May 2013 19:20:44 +0000 (14:20 -0500)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Thu, 23 May 2013 18:33:07 +0000 (13:33 -0500)
It doesn't do much... it just has a static directory with a "bunnify"
CSS file and has a unit test that returns a json encoded set of a
staticdirect with both this plugin enabled and also
with (theoretically) a file distributed with MediaGoblin (it isn't
really, but in our case that doesn't matter.)

Also set up the static_setup hook / PluginStatic object for this
plugin; testing that with `./bin/gmg theme assetlink` seemed to work.
(And argh, need to update that command name, I know.)

This commit sponsored by Bradley Kuhn.  Thanks bkuhn!

mediagoblin/tests/appconfig_static_plugin.ini [new file with mode: 0644]
mediagoblin/tests/testplugins/staticstuff/__init__.py [new file with mode: 0644]
mediagoblin/tests/testplugins/staticstuff/static/css/bunnify.css [new file with mode: 0644]
mediagoblin/tests/testplugins/staticstuff/views.py [new file with mode: 0644]

diff --git a/mediagoblin/tests/appconfig_static_plugin.ini b/mediagoblin/tests/appconfig_static_plugin.ini
new file mode 100644 (file)
index 0000000..dc25117
--- /dev/null
@@ -0,0 +1,26 @@
+[mediagoblin]
+direct_remote_path = /test_static/
+email_sender_address = "notice@mediagoblin.example.org"
+email_debug_mode = true
+
+# TODO: Switch to using an in-memory database
+sql_engine = "sqlite:///%(here)s/user_dev/mediagoblin.db"
+
+# Celery shouldn't be set up by the application as it's setup via
+# mediagoblin.init.celery.from_celery
+celery_setup_elsewhere = true
+
+[storage:publicstore]
+base_dir = %(here)s/user_dev/media/public
+base_url = /mgoblin_media/
+
+[storage:queuestore]
+base_dir = %(here)s/user_dev/media/queue
+
+[celery]
+CELERY_ALWAYS_EAGER = true
+CELERY_RESULT_DBURI = "sqlite:///%(here)s/user_dev/celery.db"
+BROKER_HOST = "sqlite:///%(here)s/user_dev/kombu.db"
+
+[plugins]
+[[mediagoblin.tests.testplugins.staticstuff]]
diff --git a/mediagoblin/tests/testplugins/staticstuff/__init__.py b/mediagoblin/tests/testplugins/staticstuff/__init__.py
new file mode 100644 (file)
index 0000000..a259164
--- /dev/null
@@ -0,0 +1,36 @@
+# 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/>.
+
+from mediagoblin.tools.staticdirect import PluginStatic
+from mediagoblin.tools import pluginapi
+from pkg_resources import resource_filename
+
+def setup_plugin():
+    routes = [
+        ('staticstuff.static_demo',
+         '/staticstuff/',
+         'mediagoblin.tests.testplugins.staticstuff.views:static_demo')]
+
+    pluginapi.register_routes(routes)
+
+
+hooks = {
+    'setup': setup_plugin,
+    'static_setup': lambda: PluginStatic(
+        'staticstuff',
+        resource_filename(
+            'mediagoblin.tests.testplugins.staticstuff',
+            'static'))}
diff --git a/mediagoblin/tests/testplugins/staticstuff/static/css/bunnify.css b/mediagoblin/tests/testplugins/staticstuff/static/css/bunnify.css
new file mode 100644 (file)
index 0000000..1294ab8
--- /dev/null
@@ -0,0 +1,4 @@
+body {
+    background-color: #5edcf1;
+    color: #eb8add;
+}
\ No newline at end of file
diff --git a/mediagoblin/tests/testplugins/staticstuff/views.py b/mediagoblin/tests/testplugins/staticstuff/views.py
new file mode 100644 (file)
index 0000000..ff0dd8e
--- /dev/null
@@ -0,0 +1,28 @@
+# 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 json
+
+from werkzeug import Response
+
+
+def static_demo(request):
+    return Response(json.dumps({
+        # this does not exist, but we'll pretend it does ;)
+        'mgoblin_bunny_pic': request.staticdirect(
+            'images/bunny_pic.png'),
+        'plugin_bunny_css': request.staticdirect(
+            'css/bunnyify.css', 'staticstuff')}))