Commit c275c19dc38393e8604e9690734d19f79d233a4c
1 parent
8546474a
Exists in
master
and in
4 other branches
Write unit tests for utils/conf
Signed-off-by: Lucas Kanashiro <kanashiro.duarte@gmail.com> Signed-off-by: Lucas Moura <lucas.moura128@gmail.com>
Showing
6 changed files
with
124 additions
and
1 deletions
Show diff stats
colab/utils/tests/test_conf.py
... | ... | @@ -2,7 +2,11 @@ |
2 | 2 | from django.test import TestCase, override_settings |
3 | 3 | from django.conf import settings |
4 | 4 | |
5 | -from ..conf import DatabaseUndefined, validate_database | |
5 | +from ..conf import (DatabaseUndefined, validate_database, | |
6 | + InaccessibleSettings, _load_py_file, load_py_settings, | |
7 | + load_colab_apps, load_widgets_settings) | |
8 | + | |
9 | +from mock import patch | |
6 | 10 | |
7 | 11 | |
8 | 12 | class TestConf(TestCase): |
... | ... | @@ -16,3 +20,74 @@ class TestConf(TestCase): |
16 | 20 | with self.assertRaises(DatabaseUndefined): |
17 | 21 | validate_database(settings.DATABASES, settings.DEFAULT_DATABASE, |
18 | 22 | settings.DEBUG) |
23 | + | |
24 | + def test_load_py_file_with_io_error(self): | |
25 | + self.assertRaises(InaccessibleSettings, | |
26 | + _load_py_file, 'settings_test', '/etc/colab/') | |
27 | + | |
28 | + @patch('importlib.import_module', side_effect=SyntaxError) | |
29 | + def test_load_py_file_with_syntax_error(self, mock): | |
30 | + self.assertRaises(InaccessibleSettings, | |
31 | + _load_py_file, 'settings_test', '/etc/colab/') | |
32 | + | |
33 | + def test_load_py_file(self): | |
34 | + py_settings = _load_py_file('colab_settings', './tests/') | |
35 | + | |
36 | + self.assertIn('SOCIAL_NETWORK_ENABLED', py_settings) | |
37 | + self.assertTrue(py_settings['SOCIAL_NETWORK_ENABLED']) | |
38 | + | |
39 | + self.assertIn('EMAIL_PORT', py_settings) | |
40 | + self.assertEquals(py_settings['EMAIL_PORT'], 25) | |
41 | + | |
42 | + @patch('os.getenv', return_value='/path/fake/settings.py') | |
43 | + def test_load_py_settings_with_inaccessible_settings(self, mock): | |
44 | + self.assertRaises(InaccessibleSettings, load_py_settings) | |
45 | + | |
46 | + @patch('os.path.exists', side_effect=[True, False]) | |
47 | + def test_load_py_settings_without_settings_d(self, mock): | |
48 | + py_settings = load_py_settings() | |
49 | + | |
50 | + self.assertIn('SOCIAL_NETWORK_ENABLED', py_settings) | |
51 | + self.assertTrue(py_settings['SOCIAL_NETWORK_ENABLED']) | |
52 | + | |
53 | + self.assertIn('EMAIL_PORT', py_settings) | |
54 | + self.assertEquals(py_settings['EMAIL_PORT'], 25) | |
55 | + | |
56 | + @patch('os.listdir', return_value=['./tests/settings.d/test.py', | |
57 | + 'non_python_file']) | |
58 | + @patch('colab.utils.conf._load_py_file', | |
59 | + side_effect=[{'SOCIAL_NETWORK_ENABLED': True, 'EMAIL_PORT': 25}, | |
60 | + {'TEST':'test'}]) | |
61 | + def test_load_py_settings_with_settings_d(self, mock_py, mock_listdir): | |
62 | + py_settings = load_py_settings() | |
63 | + | |
64 | + self.assertIn('SOCIAL_NETWORK_ENABLED', py_settings) | |
65 | + self.assertTrue(py_settings['SOCIAL_NETWORK_ENABLED']) | |
66 | + | |
67 | + self.assertIn('EMAIL_PORT', py_settings) | |
68 | + self.assertEquals(py_settings['EMAIL_PORT'], 25) | |
69 | + | |
70 | + self.assertIn('TEST', py_settings) | |
71 | + self.assertEquals(py_settings['TEST'], 'test') | |
72 | + | |
73 | + @patch('os.getenv', return_value='/path/fake/plugins.d/') | |
74 | + def test_load_colab_apps_without_plugins_d_directory(self, mock): | |
75 | + colab_apps = load_colab_apps() | |
76 | + self.assertIn('COLAB_APPS', colab_apps) | |
77 | + self.assertEquals(colab_apps['COLAB_APPS'], {}) | |
78 | + | |
79 | + @patch('os.getenv', return_value='./tests/plugins.d/') | |
80 | + def test_load_colab_apps_with_plugins_d_directory(self, mock): | |
81 | + colab_apps = load_colab_apps() | |
82 | + | |
83 | + self.assertIn('colab_gitlab', colab_apps['COLAB_APPS']) | |
84 | + self.assertIn('colab_noosfero', colab_apps['COLAB_APPS']) | |
85 | + | |
86 | + @patch('os.getenv', return_value='/path/fake/widgets_settings.py') | |
87 | + def test_load_widgets_settings_without_settings(self, mock): | |
88 | + self.assertIsNone(load_widgets_settings()) | |
89 | + | |
90 | + @patch('os.getenv', side_effect=['./tests/colab_settings.py', | |
91 | + '/path/fake/widgets_settings.py']) | |
92 | + def test_load_widgets_settings_without_settings(self, mock): | |
93 | + self.assertIsNone(load_widgets_settings()) | ... | ... |
... | ... | @@ -0,0 +1,17 @@ |
1 | +from django.utils.translation import ugettext_lazy as _ | |
2 | +from colab.plugins.utils.menu import colab_url_factory | |
3 | + | |
4 | +name = "colab_gitlab" | |
5 | +verbose_name = "Gitlab" | |
6 | + | |
7 | +upstream = 'https://localhost/gitlab/' | |
8 | +private_token = 'AVA8vrohDpoSws41zd1w' | |
9 | + | |
10 | +urls = { | |
11 | + "include":"colab_gitlab.urls", | |
12 | + "prefix": 'gitlab/', | |
13 | + "namespace":"gitlab" | |
14 | + } | |
15 | + | |
16 | +url = colab_url_factory('gitlab') | |
17 | + | ... | ... |
... | ... | @@ -0,0 +1,17 @@ |
1 | +from django.utils.translation import ugettext_lazy as _ | |
2 | +from colab.plugins.utils.menu import colab_url_factory | |
3 | + | |
4 | +name = "colab_noosfero" | |
5 | +verbose_name = "Noosfero" | |
6 | +private_token = "ef9a334177c620b68e75a89844e8a402" | |
7 | + | |
8 | +upstream = 'http://localhost/social/' | |
9 | + | |
10 | +urls = { | |
11 | + "include":"colab_noosfero.urls", | |
12 | + "prefix": '^social/', | |
13 | + "namespace":"social" | |
14 | + } | |
15 | + | |
16 | +url = colab_url_factory('social') | |
17 | + | ... | ... |
... | ... | @@ -0,0 +1,12 @@ |
1 | +from django.utils.translation import ugettext_lazy | |
2 | +from colab.plugins.utils.menu import colab_url_factory | |
3 | + | |
4 | + | |
5 | +verbose_name = "SPB Plugin" | |
6 | +urls = { | |
7 | + "include":"colab_spb.urls", | |
8 | + "prefix": '^spb/', | |
9 | + "namespace":"colab_spb" | |
10 | + } | |
11 | + | |
12 | +url = colab_url_factory('colab_spb') | ... | ... |