From 395aa3ee59c693e0a28daa272c3488920e79f82e Mon Sep 17 00:00:00 2001 From: Matheus Faria Date: Thu, 12 Nov 2015 15:54:48 -0200 Subject: [PATCH] Fixing broken test from colab.utils --- colab/utils/tests/colab_settings.py | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ colab/utils/tests/plugins.d/gitlab.py | 15 +++++++++++++++ colab/utils/tests/plugins.d/noosfero.py | 15 +++++++++++++++ colab/utils/tests/plugins.d/plugin_test | 0 colab/utils/tests/plugins.d/spb.py | 10 ++++++++++ colab/utils/tests/settings.d/test.py | 2 ++ colab/utils/tests/settings_with_syntax_error.py | 1 + colab/utils/tests/test_conf.py | 32 ++++++++++++++++++++------------ tests/plugins.d/gitlab.py | 17 ----------------- tests/plugins.d/noosfero.py | 17 ----------------- tests/plugins.d/plugin_test | 0 tests/plugins.d/spb.py | 12 ------------ tests/settings.d/test.py | 2 -- 13 files changed, 119 insertions(+), 60 deletions(-) create mode 100644 colab/utils/tests/colab_settings.py create mode 100644 colab/utils/tests/plugins.d/gitlab.py create mode 100644 colab/utils/tests/plugins.d/noosfero.py create mode 100644 colab/utils/tests/plugins.d/plugin_test create mode 100644 colab/utils/tests/plugins.d/spb.py create mode 100644 colab/utils/tests/settings.d/test.py create mode 100644 colab/utils/tests/settings_with_syntax_error.py delete mode 100644 tests/plugins.d/gitlab.py delete mode 100644 tests/plugins.d/noosfero.py delete mode 100644 tests/plugins.d/plugin_test delete mode 100644 tests/plugins.d/spb.py delete mode 100644 tests/settings.d/test.py diff --git a/colab/utils/tests/colab_settings.py b/colab/utils/tests/colab_settings.py new file mode 100644 index 0000000..fd3298b --- /dev/null +++ b/colab/utils/tests/colab_settings.py @@ -0,0 +1,56 @@ + +# Set to false in production +DEBUG = True +TEMPLATE_DEBUG = False + +# System admins +ADMINS = [['John Foo', 'john@example.com'], ['Mary Bar', 'mary@example.com']] + +MANAGERS = ADMINS + +COLAB_FROM_ADDRESS = '"Colab" ' +SERVER_EMAIL = '"Colab" ' + +EMAIL_HOST = 'localhost' +EMAIL_PORT = 25 +EMAIL_SUBJECT_PREFIX = '[colab]' + +SECRET_KEY = 'not-a-secret' + +ALLOWED_HOSTS = [ + 'localhost', +] + +# Uncomment to enable social networks fields profile +SOCIAL_NETWORK_ENABLED = True + +# Disable indexing +ROBOTS_NOINDEX = True + +LOGGING = { + 'version': 1, + + 'handlers': { + 'null': { + 'level': 'DEBUG', + 'class': 'logging.NullHandler', + }, + }, + + 'loggers': { + 'colab.mailman': { + 'handlers': ['null'], + 'propagate': False, + }, + 'haystack': { + 'handlers': ['null'], + 'propagate': False, + }, + }, +} + +STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage' + +from colab.settings import INSTALLED_APPS + +INSTALLED_APPS += ('behave_django', ) diff --git a/colab/utils/tests/plugins.d/gitlab.py b/colab/utils/tests/plugins.d/gitlab.py new file mode 100644 index 0000000..599ff59 --- /dev/null +++ b/colab/utils/tests/plugins.d/gitlab.py @@ -0,0 +1,15 @@ +from colab.plugins.utils.menu import colab_url_factory + +name = "gitlab" +verbose_name = "Gitlab" + +upstream = 'https://localhost/gitlab/' +private_token = 'AVA8vrohDpoSws41zd1w' + +urls = { + "include": "gitlab.urls", + "prefix": 'gitlab/', + "namespace": "gitlab" +} + +url = colab_url_factory('gitlab') diff --git a/colab/utils/tests/plugins.d/noosfero.py b/colab/utils/tests/plugins.d/noosfero.py new file mode 100644 index 0000000..2a8210e --- /dev/null +++ b/colab/utils/tests/plugins.d/noosfero.py @@ -0,0 +1,15 @@ +from colab.plugins.utils.menu import colab_url_factory + +name = "noosfero" +verbose_name = "Noosfero" +private_token = "ef9a334177c620b68e75a89844e8a402" + +upstream = 'http://localhost/social/' + +urls = { + "include": "noosfero.urls", + "prefix": '^social/', + "namespace": "social" +} + +url = colab_url_factory('social') diff --git a/colab/utils/tests/plugins.d/plugin_test b/colab/utils/tests/plugins.d/plugin_test new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/colab/utils/tests/plugins.d/plugin_test diff --git a/colab/utils/tests/plugins.d/spb.py b/colab/utils/tests/plugins.d/spb.py new file mode 100644 index 0000000..897a529 --- /dev/null +++ b/colab/utils/tests/plugins.d/spb.py @@ -0,0 +1,10 @@ +from colab.plugins.utils.menu import colab_url_factory + +verbose_name = "SPB Plugin" +urls = { + "include": "colab_spb.urls", + "prefix": '^spb/', + "namespace": "colab_spb" +} + +url = colab_url_factory('colab_spb') diff --git a/colab/utils/tests/settings.d/test.py b/colab/utils/tests/settings.d/test.py new file mode 100644 index 0000000..f75909b --- /dev/null +++ b/colab/utils/tests/settings.d/test.py @@ -0,0 +1,2 @@ +RIBBON_ENABLED = False +TEST = 'test' diff --git a/colab/utils/tests/settings_with_syntax_error.py b/colab/utils/tests/settings_with_syntax_error.py new file mode 100644 index 0000000..bea8cd1 --- /dev/null +++ b/colab/utils/tests/settings_with_syntax_error.py @@ -0,0 +1 @@ +) diff --git a/colab/utils/tests/test_conf.py b/colab/utils/tests/test_conf.py index 1eded43..d331f22 100644 --- a/colab/utils/tests/test_conf.py +++ b/colab/utils/tests/test_conf.py @@ -1,3 +1,4 @@ +import sys from django.test import TestCase, override_settings from django.conf import settings @@ -9,6 +10,9 @@ from ..conf import (DatabaseUndefined, validate_database, from mock import patch +test_files_dir = "./colab/utils/tests" + + class TestConf(TestCase): @override_settings(DEBUG=False, DATABASES={ @@ -25,13 +29,13 @@ class TestConf(TestCase): self.assertRaises(InaccessibleSettings, _load_py_file, 'settings_test', '/etc/colab/') - @patch('importlib.import_module', side_effect=SyntaxError) - def test_load_py_file_with_syntax_error(self, mock): + def test_load_py_file_with_syntax_error(self): self.assertRaises(InaccessibleSettings, - _load_py_file, 'settings_test', '/etc/colab/') + _load_py_file, 'settings_with_syntax_error', + test_files_dir) def test_load_py_file(self): - py_settings = _load_py_file('colab_settings', './tests/') + py_settings = _load_py_file('colab_settings', test_files_dir) self.assertIn('SOCIAL_NETWORK_ENABLED', py_settings) self.assertTrue(py_settings['SOCIAL_NETWORK_ENABLED']) @@ -43,7 +47,7 @@ class TestConf(TestCase): def test_load_py_settings_with_inaccessible_settings(self, mock): self.assertRaises(InaccessibleSettings, load_py_settings) - @patch('os.getenv', return_value='./tests/colab_settings.py') + @patch('os.getenv', return_value=test_files_dir + '/colab_settings.py') def test_load_py_settings_without_settings_d(self, mock): py_settings = load_py_settings('/path/fake/settings.d/test.py') @@ -53,13 +57,13 @@ class TestConf(TestCase): self.assertIn('EMAIL_PORT', py_settings) self.assertEquals(py_settings['EMAIL_PORT'], 25) - @patch('os.listdir', return_value=['./tests/settings.d/test.py', + @patch('os.listdir', return_value=[test_files_dir + '/settings.d/test.py', 'non_python_file']) @patch('colab.utils.conf._load_py_file', side_effect=[{'SOCIAL_NETWORK_ENABLED': True, 'EMAIL_PORT': 25}, {'TEST': 'test'}]) def test_load_py_settings_with_settings_d(self, mock_py, mock_listdir): - py_settings = load_py_settings('./tests/settings.d/') + py_settings = load_py_settings(test_files_dir + '/settings.d/') self.assertIn('SOCIAL_NETWORK_ENABLED', py_settings) self.assertTrue(py_settings['SOCIAL_NETWORK_ENABLED']) @@ -76,18 +80,22 @@ class TestConf(TestCase): self.assertIn('COLAB_APPS', colab_apps) self.assertEquals(colab_apps['COLAB_APPS'], {}) - @patch('os.getenv', return_value='./tests/plugins.d/') - def test_load_colab_apps_with_plugins_d_directory(self, mock): + @patch('os.getenv', return_value=test_files_dir + '/plugins.d/') + def test_load_colab_apps_with_plugins_d_directory(self, os_getenv): + sys.path.insert(0, os_getenv.return_value) colab_apps = load_colab_apps() - self.assertIn('colab_gitlab', colab_apps['COLAB_APPS']) - self.assertIn('colab_noosfero', colab_apps['COLAB_APPS']) + self.assertIn('gitlab', colab_apps['COLAB_APPS']) + self.assertIn('noosfero', colab_apps['COLAB_APPS']) + sys.path.remove(os_getenv.return_value) + + self.assertNotIn(os_getenv.return_value, sys.path) @patch('os.getenv', return_value='/path/fake/widgets_settings.py') def test_load_widgets_settings_without_settings(self, mock): self.assertIsNone(load_widgets_settings()) - @patch('os.getenv', side_effect=['./tests/colab_settings.py', + @patch('os.getenv', side_effect=[test_files_dir + '/colab_settings.py', '/path/fake/widgets_settings.py']) def test_load_widgets_settings_without_settings_d(self, mock): self.assertIsNone(load_widgets_settings()) diff --git a/tests/plugins.d/gitlab.py b/tests/plugins.d/gitlab.py deleted file mode 100644 index 0bf6ed1..0000000 --- a/tests/plugins.d/gitlab.py +++ /dev/null @@ -1,17 +0,0 @@ -from django.utils.translation import ugettext_lazy as _ -from colab.plugins.utils.menu import colab_url_factory - -name = "colab_gitlab" -verbose_name = "Gitlab" - -upstream = 'https://localhost/gitlab/' -private_token = 'AVA8vrohDpoSws41zd1w' - -urls = { - "include":"colab_gitlab.urls", - "prefix": 'gitlab/', - "namespace":"gitlab" - } - -url = colab_url_factory('gitlab') - diff --git a/tests/plugins.d/noosfero.py b/tests/plugins.d/noosfero.py deleted file mode 100644 index e752cf1..0000000 --- a/tests/plugins.d/noosfero.py +++ /dev/null @@ -1,17 +0,0 @@ -from django.utils.translation import ugettext_lazy as _ -from colab.plugins.utils.menu import colab_url_factory - -name = "colab_noosfero" -verbose_name = "Noosfero" -private_token = "ef9a334177c620b68e75a89844e8a402" - -upstream = 'http://localhost/social/' - -urls = { - "include":"colab_noosfero.urls", - "prefix": '^social/', - "namespace":"social" - } - -url = colab_url_factory('social') - diff --git a/tests/plugins.d/plugin_test b/tests/plugins.d/plugin_test deleted file mode 100644 index e69de29..0000000 --- a/tests/plugins.d/plugin_test +++ /dev/null diff --git a/tests/plugins.d/spb.py b/tests/plugins.d/spb.py deleted file mode 100644 index a49e7bc..0000000 --- a/tests/plugins.d/spb.py +++ /dev/null @@ -1,12 +0,0 @@ -from django.utils.translation import ugettext_lazy -from colab.plugins.utils.menu import colab_url_factory - - -verbose_name = "SPB Plugin" -urls = { - "include":"colab_spb.urls", - "prefix": '^spb/', - "namespace":"colab_spb" - } - -url = colab_url_factory('colab_spb') diff --git a/tests/settings.d/test.py b/tests/settings.d/test.py deleted file mode 100644 index 00ba103..0000000 --- a/tests/settings.d/test.py +++ /dev/null @@ -1,2 +0,0 @@ -RIBBON_ENABLED=False -TEST='test' -- libgit2 0.21.2