comparison tests/test_appconfig.py @ 974:72f17534d58e

tests: First pass on making unit tests work again. - Fix all imports - Add more helper functions to work with mock file-systems - Simplify some code by running chef directly on the mock FS - Fix a couple tests
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 17 Oct 2017 01:07:30 -0700
parents fd694f1297c7
children
comparison
equal deleted inserted replaced
973:8419daaa7a0e 974:72f17534d58e
5 5
6 def test_config_default(): 6 def test_config_default():
7 values = {} 7 values = {}
8 config = PieCrustConfiguration(values=values) 8 config = PieCrustConfiguration(values=values)
9 assert config.get('site/root') == '/' 9 assert config.get('site/root') == '/'
10 assert len(config.get('site/sources')) == 3 # pages, posts, theme_pages 10 assert len(config.get('site/sources').keys()) == \
11 len(['theme_assets', 'assets', 'theme_pages', 'pages', 'posts',
12 'tags', 'categories', 'archives'])
11 13
12 14
13 def test_config_site_override_title(): 15 def test_config_site_override_title():
14 values = {'site': {'title': "Whatever"}} 16 values = {'site': {'title': "Whatever"}}
15 config = PieCrustConfiguration(values=values) 17 config = PieCrustConfiguration(values=values)
27 app = fs.getApp() 29 app = fs.getApp()
28 assert app.config.get('site/default_page_layout') == 'foo' 30 assert app.config.get('site/default_page_layout') == 'foo'
29 assert app.config.get('site/default_post_layout') == 'bar' 31 assert app.config.get('site/default_post_layout') == 'bar'
30 assert app.config.get('site/sources/pages/default_layout') == 'foo' 32 assert app.config.get('site/sources/pages/default_layout') == 'foo'
31 assert app.config.get('site/sources/pages/items_per_page') == 5 33 assert app.config.get('site/sources/pages/items_per_page') == 5
34 assert app.config.get('site/sources/posts/default_layout') == 'bar'
35 assert app.config.get('site/sources/posts/items_per_page') == 2
32 assert app.config.get( 36 assert app.config.get(
33 'site/sources/theme_pages/default_layout') == 'default' 37 'site/sources/theme_pages/default_layout') == 'default'
34 assert app.config.get('site/sources/theme_pages/items_per_page') == 5 38 assert app.config.get('site/sources/theme_pages/items_per_page') == 5
35 assert app.config.get('site/sources/posts/default_layout') == 'bar'
36 assert app.config.get('site/sources/posts/items_per_page') == 2
37 39
38 40
39 def test_config_site_add_source(): 41 def test_config_site_add_source():
40 config = {'site': { 42 config = {'site': {
41 'sources': {'notes': {}}, 43 'sources': {'notes': {}},
51 app.config.get('site/routes'))) == 53 app.config.get('site/routes'))) ==
52 [ 54 [
53 'notes', 'posts', 'posts_archives', 'posts_tags', 55 'notes', 'posts', 'posts_archives', 'posts_tags',
54 'posts_categories', 'pages', 'theme_pages']) 56 'posts_categories', 'pages', 'theme_pages'])
55 assert set(app.config.get('site/sources').keys()) == set([ 57 assert set(app.config.get('site/sources').keys()) == set([
56 'theme_pages', 'pages', 'posts', 'notes']) 58 'theme_pages', 'theme_assets', 'pages', 'posts', 'assets',
59 'posts_tags', 'posts_categories', 'posts_archives',
60 'notes'])
57 61
58 62
59 def test_config_site_add_source_in_both_site_and_theme(): 63 def test_config_site_add_source_in_both_site_and_theme():
60 theme_config = {'site': { 64 theme_config = {'site': {
61 'sources': {'theme_notes': {}}, 65 'sources': {'theme_notes': {}},
62 'routes': [{'url': '/theme_notes/%path:slug%', 'source': 'theme_notes'}] 66 'routes': [{'url': '/theme_notes/%path:slug%',
67 'source': 'theme_notes'}]
63 }} 68 }}
64 config = {'site': { 69 config = {'site': {
65 'sources': {'notes': {}}, 70 'sources': {'notes': {}},
66 'routes': [{'url': '/notes/%path:slug%', 'source': 'notes'}] 71 'routes': [{'url': '/notes/%path:slug%', 'source': 'notes'}]
67 }} 72 }}
79 [ 84 [
80 'notes', 'posts', 'posts_archives', 'posts_tags', 85 'notes', 'posts', 'posts_archives', 'posts_tags',
81 'posts_categories', 'pages', 'theme_notes', 86 'posts_categories', 'pages', 'theme_notes',
82 'theme_pages']) 87 'theme_pages'])
83 assert set(app.config.get('site/sources').keys()) == set([ 88 assert set(app.config.get('site/sources').keys()) == set([
84 'theme_pages', 'theme_notes', 'pages', 'posts', 'notes']) 89 'theme_pages', 'theme_assets', 'theme_notes',
90 'pages', 'posts', 'assets', 'posts_tags', 'posts_categories',
91 'posts_archives', 'notes'])
85 92
86 93
87 def test_multiple_blogs(): 94 def test_multiple_blogs():
88 config = {'site': {'blogs': ['aaa', 'bbb']}} 95 config = {'site': {'blogs': ['aaa', 'bbb']}}
89 fs = mock_fs().withConfig(config) 96 fs = mock_fs().withConfig(config)
97 [ 104 [
98 'aaa', 'aaa_archives', 'aaa_tags', 'aaa_categories', 105 'aaa', 'aaa_archives', 'aaa_tags', 'aaa_categories',
99 'bbb', 'bbb_archives', 'bbb_tags', 'bbb_categories', 106 'bbb', 'bbb_archives', 'bbb_tags', 'bbb_categories',
100 'pages', 'theme_pages']) 107 'pages', 'theme_pages'])
101 assert set(app.config.get('site/sources').keys()) == set([ 108 assert set(app.config.get('site/sources').keys()) == set([
102 'aaa', 'bbb', 'pages', 'theme_pages']) 109 'aaa', 'aaa_tags', 'aaa_categories', 'aaa_archives',
110 'bbb', 'bbb_tags', 'bbb_categories', 'bbb_archives',
111 'pages', 'assets',
112 'theme_pages', 'theme_assets'])
103 113
104 114
105 def test_custom_list_setting(): 115 def test_custom_list_setting():
106 config = {'blah': ['foo', 'bar']} 116 config = {'blah': ['foo', 'bar']}
107 fs = mock_fs().withConfig(config) 117 fs = mock_fs().withConfig(config)