Commits

Anonymous committed c2bd4a9

started writing tests

Comments (0)

Files changed (11)

 :license:   MIT/X11, see LICENSE for details
 """
 from __future__ import with_statement
+import itertools
 import os
+import os.path
 import re
 from flask import (Module, send_from_directory, render_template, json,
                    _request_ctx_stack, abort)
         used to display the full license text if necessary. (It is `None` if
         there was not a license.txt.)
         """
-        lt_path = os.path.join(path, 'license.txt')
+        lt_path = os.path.join(self.path, 'license.txt')
         if os.path.exists(lt_path):
             with open(lt_path) as fd:
                 return fd.read()
     theme_paths = app.config.get('THEME_PATHS', ())
     if isinstance(theme_paths, basestring):
         theme_paths = [p.strip() for p in theme_paths.split(';')]
-    return itertools.chain(
+    return itertools.chain(*(
         load_themes_from(path) for path in theme_paths
-    )
+    ))
 
 
 class ThemeManager(object):

tests/morethemes/cool/info.json

+{
+    "identifier": "cool",
+    "name": "Cool Blue v2",
+    "application": "testing",
+    "author": "LeafStorm"
+}

tests/templates/hello.html

+Hello from the application
+"""
+test-themes.py
+==============
+This tests the Flask-Themes extension.
+"""
+import os.path
+from flask import Flask
+from flaskext.themes import (setup_themes, Theme, load_themes_from,
+    packaged_themes_loader, theme_paths_loader)
+from jinja2 import FileSystemLoader
+from operator import attrgetter
+
+TESTS = os.path.dirname(__file__)
+join = os.path.join
+
+
+class TestThemeObject(object):
+    def test_theme(self):
+        path = join(TESTS, 'themes', 'cool')
+        cool = Theme(path)
+        assert cool.name == 'Cool Blue v1'
+        assert cool.identifier == 'cool'
+        assert cool.path == os.path.abspath(path)
+        assert cool.static_path == join(cool.path, 'static')
+        assert cool.templates_path == join(cool.path, 'templates')
+        assert cool.license_text is None
+        assert isinstance(cool.jinja_loader, FileSystemLoader)
+    
+    def test_license_text(self):
+        path = join(TESTS, 'themes', 'plain')
+        plain = Theme(path)
+        assert plain.license_text.strip() == 'The license.'
+
+
+class TestLoaders(object):
+    def test_load_themes_from(self):
+        path = join(TESTS, 'themes')
+        themes_iter = load_themes_from(path)
+        themes = list(sorted(themes_iter, key=attrgetter('identifier')))
+        assert themes[0].identifier == 'cool'
+        assert themes[1].identifier == 'notthis'
+        assert themes[2].identifier == 'plain'
+    
+    def test_packaged_themes_loader(self):
+        app = Flask(__name__)
+        themes_iter = packaged_themes_loader(app)
+        themes = list(sorted(themes_iter, key=attrgetter('identifier')))
+        assert themes[0].identifier == 'cool'
+        assert themes[1].identifier == 'notthis'
+        assert themes[2].identifier == 'plain'
+    
+    def test_theme_paths_loader(self):
+        app = Flask(__name__)
+        app.config['THEME_PATHS'] = [join(TESTS, 'morethemes')]
+        themes = list(theme_paths_loader(app))
+        assert themes[0].identifier == 'cool'

tests/test-themes.pyc

Binary file added.

tests/themes/cool/info.json

+{
+    "identifier": "cool",
+    "name": "Cool Blue v1",
+    "application": "testing",
+    "author": "LeafStorm"
+}

tests/themes/identifier/info.json

+{
+    "identifier": "mismatch",
+    "name": "Identifier Mismatch",
+    "application": "testing",
+    "author": "LeafStorm"
+}

tests/themes/notthis/info.json

+{
+    "identifier": "notthis",
+    "name": "Not This App",
+    "application": "anotherapp",
+    "author": "LeafStorm"
+}

tests/themes/plain/info.json

+{
+    "identifier": "plain",
+    "name": "Plain",
+    "application": "testing",
+    "author": "LeafStorm"
+}

tests/themes/plain/license.txt

+The license.

tests/themes/warm-theme/info.json

+{
+    "identifier": "warm-theme",
+    "name": "Warm",
+    "application": "testing",
+    "author": "LeafStorm"
+}