Commit 395aa3ee59c693e0a28daa272c3488920e79f82e

Authored by Matheus de Sousa Faria
1 parent 9b3cca5b

Fixing broken test from colab.utils

- Moved necessary files from tests to colab/utils/tests

Signed-off-by: Lucas Kanashiro <kanashiro.duarte@gmail.com>
Signed-off-by: Matheus Faria <matheus.sousa.faria@gmail.com>
colab/utils/tests/colab_settings.py 0 → 100644
@@ -0,0 +1,56 @@ @@ -0,0 +1,56 @@
  1 +
  2 +# Set to false in production
  3 +DEBUG = True
  4 +TEMPLATE_DEBUG = False
  5 +
  6 +# System admins
  7 +ADMINS = [['John Foo', 'john@example.com'], ['Mary Bar', 'mary@example.com']]
  8 +
  9 +MANAGERS = ADMINS
  10 +
  11 +COLAB_FROM_ADDRESS = '"Colab" <noreply@example.com>'
  12 +SERVER_EMAIL = '"Colab" <noreply@example.com>'
  13 +
  14 +EMAIL_HOST = 'localhost'
  15 +EMAIL_PORT = 25
  16 +EMAIL_SUBJECT_PREFIX = '[colab]'
  17 +
  18 +SECRET_KEY = 'not-a-secret'
  19 +
  20 +ALLOWED_HOSTS = [
  21 + 'localhost',
  22 +]
  23 +
  24 +# Uncomment to enable social networks fields profile
  25 +SOCIAL_NETWORK_ENABLED = True
  26 +
  27 +# Disable indexing
  28 +ROBOTS_NOINDEX = True
  29 +
  30 +LOGGING = {
  31 + 'version': 1,
  32 +
  33 + 'handlers': {
  34 + 'null': {
  35 + 'level': 'DEBUG',
  36 + 'class': 'logging.NullHandler',
  37 + },
  38 + },
  39 +
  40 + 'loggers': {
  41 + 'colab.mailman': {
  42 + 'handlers': ['null'],
  43 + 'propagate': False,
  44 + },
  45 + 'haystack': {
  46 + 'handlers': ['null'],
  47 + 'propagate': False,
  48 + },
  49 + },
  50 +}
  51 +
  52 +STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage'
  53 +
  54 +from colab.settings import INSTALLED_APPS
  55 +
  56 +INSTALLED_APPS += ('behave_django', )
colab/utils/tests/plugins.d/gitlab.py 0 → 100644
@@ -0,0 +1,15 @@ @@ -0,0 +1,15 @@
  1 +from colab.plugins.utils.menu import colab_url_factory
  2 +
  3 +name = "gitlab"
  4 +verbose_name = "Gitlab"
  5 +
  6 +upstream = 'https://localhost/gitlab/'
  7 +private_token = 'AVA8vrohDpoSws41zd1w'
  8 +
  9 +urls = {
  10 + "include": "gitlab.urls",
  11 + "prefix": 'gitlab/',
  12 + "namespace": "gitlab"
  13 +}
  14 +
  15 +url = colab_url_factory('gitlab')
colab/utils/tests/plugins.d/noosfero.py 0 → 100644
@@ -0,0 +1,15 @@ @@ -0,0 +1,15 @@
  1 +from colab.plugins.utils.menu import colab_url_factory
  2 +
  3 +name = "noosfero"
  4 +verbose_name = "Noosfero"
  5 +private_token = "ef9a334177c620b68e75a89844e8a402"
  6 +
  7 +upstream = 'http://localhost/social/'
  8 +
  9 +urls = {
  10 + "include": "noosfero.urls",
  11 + "prefix": '^social/',
  12 + "namespace": "social"
  13 +}
  14 +
  15 +url = colab_url_factory('social')
colab/utils/tests/plugins.d/plugin_test 0 → 100644
colab/utils/tests/plugins.d/spb.py 0 → 100644
@@ -0,0 +1,10 @@ @@ -0,0 +1,10 @@
  1 +from colab.plugins.utils.menu import colab_url_factory
  2 +
  3 +verbose_name = "SPB Plugin"
  4 +urls = {
  5 + "include": "colab_spb.urls",
  6 + "prefix": '^spb/',
  7 + "namespace": "colab_spb"
  8 +}
  9 +
  10 +url = colab_url_factory('colab_spb')
colab/utils/tests/settings.d/test.py 0 → 100644
@@ -0,0 +1,2 @@ @@ -0,0 +1,2 @@
  1 +RIBBON_ENABLED = False
  2 +TEST = 'test'
colab/utils/tests/settings_with_syntax_error.py 0 → 100644
@@ -0,0 +1 @@ @@ -0,0 +1 @@
  1 +)
colab/utils/tests/test_conf.py
  1 +import sys
1 2
2 from django.test import TestCase, override_settings 3 from django.test import TestCase, override_settings
3 from django.conf import settings 4 from django.conf import settings
@@ -9,6 +10,9 @@ from ..conf import (DatabaseUndefined, validate_database, @@ -9,6 +10,9 @@ from ..conf import (DatabaseUndefined, validate_database,
9 from mock import patch 10 from mock import patch
10 11
11 12
  13 +test_files_dir = "./colab/utils/tests"
  14 +
  15 +
12 class TestConf(TestCase): 16 class TestConf(TestCase):
13 17
14 @override_settings(DEBUG=False, DATABASES={ 18 @override_settings(DEBUG=False, DATABASES={
@@ -25,13 +29,13 @@ class TestConf(TestCase): @@ -25,13 +29,13 @@ class TestConf(TestCase):
25 self.assertRaises(InaccessibleSettings, 29 self.assertRaises(InaccessibleSettings,
26 _load_py_file, 'settings_test', '/etc/colab/') 30 _load_py_file, 'settings_test', '/etc/colab/')
27 31
28 - @patch('importlib.import_module', side_effect=SyntaxError)  
29 - def test_load_py_file_with_syntax_error(self, mock): 32 + def test_load_py_file_with_syntax_error(self):
30 self.assertRaises(InaccessibleSettings, 33 self.assertRaises(InaccessibleSettings,
31 - _load_py_file, 'settings_test', '/etc/colab/') 34 + _load_py_file, 'settings_with_syntax_error',
  35 + test_files_dir)
32 36
33 def test_load_py_file(self): 37 def test_load_py_file(self):
34 - py_settings = _load_py_file('colab_settings', './tests/') 38 + py_settings = _load_py_file('colab_settings', test_files_dir)
35 39
36 self.assertIn('SOCIAL_NETWORK_ENABLED', py_settings) 40 self.assertIn('SOCIAL_NETWORK_ENABLED', py_settings)
37 self.assertTrue(py_settings['SOCIAL_NETWORK_ENABLED']) 41 self.assertTrue(py_settings['SOCIAL_NETWORK_ENABLED'])
@@ -43,7 +47,7 @@ class TestConf(TestCase): @@ -43,7 +47,7 @@ class TestConf(TestCase):
43 def test_load_py_settings_with_inaccessible_settings(self, mock): 47 def test_load_py_settings_with_inaccessible_settings(self, mock):
44 self.assertRaises(InaccessibleSettings, load_py_settings) 48 self.assertRaises(InaccessibleSettings, load_py_settings)
45 49
46 - @patch('os.getenv', return_value='./tests/colab_settings.py') 50 + @patch('os.getenv', return_value=test_files_dir + '/colab_settings.py')
47 def test_load_py_settings_without_settings_d(self, mock): 51 def test_load_py_settings_without_settings_d(self, mock):
48 py_settings = load_py_settings('/path/fake/settings.d/test.py') 52 py_settings = load_py_settings('/path/fake/settings.d/test.py')
49 53
@@ -53,13 +57,13 @@ class TestConf(TestCase): @@ -53,13 +57,13 @@ class TestConf(TestCase):
53 self.assertIn('EMAIL_PORT', py_settings) 57 self.assertIn('EMAIL_PORT', py_settings)
54 self.assertEquals(py_settings['EMAIL_PORT'], 25) 58 self.assertEquals(py_settings['EMAIL_PORT'], 25)
55 59
56 - @patch('os.listdir', return_value=['./tests/settings.d/test.py', 60 + @patch('os.listdir', return_value=[test_files_dir + '/settings.d/test.py',
57 'non_python_file']) 61 'non_python_file'])
58 @patch('colab.utils.conf._load_py_file', 62 @patch('colab.utils.conf._load_py_file',
59 side_effect=[{'SOCIAL_NETWORK_ENABLED': True, 'EMAIL_PORT': 25}, 63 side_effect=[{'SOCIAL_NETWORK_ENABLED': True, 'EMAIL_PORT': 25},
60 {'TEST': 'test'}]) 64 {'TEST': 'test'}])
61 def test_load_py_settings_with_settings_d(self, mock_py, mock_listdir): 65 def test_load_py_settings_with_settings_d(self, mock_py, mock_listdir):
62 - py_settings = load_py_settings('./tests/settings.d/') 66 + py_settings = load_py_settings(test_files_dir + '/settings.d/')
63 67
64 self.assertIn('SOCIAL_NETWORK_ENABLED', py_settings) 68 self.assertIn('SOCIAL_NETWORK_ENABLED', py_settings)
65 self.assertTrue(py_settings['SOCIAL_NETWORK_ENABLED']) 69 self.assertTrue(py_settings['SOCIAL_NETWORK_ENABLED'])
@@ -76,18 +80,22 @@ class TestConf(TestCase): @@ -76,18 +80,22 @@ class TestConf(TestCase):
76 self.assertIn('COLAB_APPS', colab_apps) 80 self.assertIn('COLAB_APPS', colab_apps)
77 self.assertEquals(colab_apps['COLAB_APPS'], {}) 81 self.assertEquals(colab_apps['COLAB_APPS'], {})
78 82
79 - @patch('os.getenv', return_value='./tests/plugins.d/')  
80 - def test_load_colab_apps_with_plugins_d_directory(self, mock): 83 + @patch('os.getenv', return_value=test_files_dir + '/plugins.d/')
  84 + def test_load_colab_apps_with_plugins_d_directory(self, os_getenv):
  85 + sys.path.insert(0, os_getenv.return_value)
81 colab_apps = load_colab_apps() 86 colab_apps = load_colab_apps()
82 87
83 - self.assertIn('colab_gitlab', colab_apps['COLAB_APPS'])  
84 - self.assertIn('colab_noosfero', colab_apps['COLAB_APPS']) 88 + self.assertIn('gitlab', colab_apps['COLAB_APPS'])
  89 + self.assertIn('noosfero', colab_apps['COLAB_APPS'])
  90 + sys.path.remove(os_getenv.return_value)
  91 +
  92 + self.assertNotIn(os_getenv.return_value, sys.path)
85 93
86 @patch('os.getenv', return_value='/path/fake/widgets_settings.py') 94 @patch('os.getenv', return_value='/path/fake/widgets_settings.py')
87 def test_load_widgets_settings_without_settings(self, mock): 95 def test_load_widgets_settings_without_settings(self, mock):
88 self.assertIsNone(load_widgets_settings()) 96 self.assertIsNone(load_widgets_settings())
89 97
90 - @patch('os.getenv', side_effect=['./tests/colab_settings.py', 98 + @patch('os.getenv', side_effect=[test_files_dir + '/colab_settings.py',
91 '/path/fake/widgets_settings.py']) 99 '/path/fake/widgets_settings.py'])
92 def test_load_widgets_settings_without_settings_d(self, mock): 100 def test_load_widgets_settings_without_settings_d(self, mock):
93 self.assertIsNone(load_widgets_settings()) 101 self.assertIsNone(load_widgets_settings())
tests/plugins.d/gitlab.py
@@ -1,17 +0,0 @@ @@ -1,17 +0,0 @@
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 -  
tests/plugins.d/noosfero.py
@@ -1,17 +0,0 @@ @@ -1,17 +0,0 @@
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 -  
tests/plugins.d/plugin_test
tests/plugins.d/spb.py
@@ -1,12 +0,0 @@ @@ -1,12 +0,0 @@
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')  
tests/settings.d/test.py
@@ -1,2 +0,0 @@ @@ -1,2 +0,0 @@
1 -RIBBON_ENABLED=False  
2 -TEST='test'