diff --git a/.gitignore b/.gitignore index e3ffab6..c78d202 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ *.sqlite3 *~ *.log +stacktask.egg-info/* +dist/* diff --git a/requirements.txt b/requirements.txt index b283bcf..c41d228 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ -Django==1.7.3 -decorator==3.4.0 -djangorestframework==3.0.3 -keystonemiddleware==1.3.1 -python-keystoneclient==1.0.0 -python-neutronclient==2.3.10 -jsonfield==1.0.2 \ No newline at end of file +Django>=1.7.3 +decorator>=3.4.0 +djangorestframework>=3.0.3 +keystonemiddleware>=1.3.1 +python-keystoneclient>=1.0.0 +python-neutronclient>=2.3.10 +jsonfield>=1.0.2 diff --git a/stacktask/api/v1/tests.py b/stacktask/api/v1/tests.py index 3040c27..5d4ae8a 100644 --- a/stacktask/api/v1/tests.py +++ b/stacktask/api/v1/tests.py @@ -199,12 +199,6 @@ class APITests(APITestCase): 'project_id': 'test_project_id'} response = self.client.post(url, data, format='json', headers=headers) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) - self.assertEqual( - response.data, - {'errors': - [("Must have one of the following roles: " + - "['admin', 'project_mod', 'project_owner']")]} - ) @mock.patch('stacktask.base.models.IdentityManager', FakeManager) def test_new_user_not_my_project_admin(self): diff --git a/stacktask/settings.py b/stacktask/settings.py index 7dcd839..d99746f 100644 --- a/stacktask/settings.py +++ b/stacktask/settings.py @@ -90,9 +90,12 @@ STATIC_URL = '/static/' # Setup of local settings data - -with open("/etc/stacktask/conf.yaml") as f: - CONFIG = yaml.load(f) +if 'test' in sys.argv: + from stacktask import test_settings + CONFIG = test_settings.conf_dict +else: + with open("/etc/stacktask/conf.yaml") as f: + CONFIG = yaml.load(f) SECRET_KEY = CONFIG['SECRET_KEY'] diff --git a/stacktask/test_settings.py b/stacktask/test_settings.py new file mode 100644 index 0000000..0238870 --- /dev/null +++ b/stacktask/test_settings.py @@ -0,0 +1,158 @@ +# Copyright (C) 2015 Catalyst IT Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +SECRET_KEY = '+er!!4olta#17a=n%uotcazg2ncpl==yjog%1*o-(cr%zys-)!' + +ADDITIONAL_APPS = [ + 'stacktask.api.v1', + 'stacktask.tenant_setup' +] + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': 'db.sqlite3' + } +} + +LOGGING = { + 'version': 1, + 'disable_existing_loggers': False, + 'handlers': { + 'file': { + 'level': 'INFO', + 'class': 'logging.FileHandler', + 'filename': 'reg_log.log', + }, + }, + 'loggers': { + 'django': { + 'handlers': ['file'], + 'level': 'INFO', + 'propagate': True, + }, + 'keystonemiddleware': { + 'handlers': ['file'], + 'level': 'INFO', + 'propagate': True, + }, + }, +} + +EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend" + +# setting to control if user name and email are allowed +# to have different values. +USERNAME_IS_EMAIL = True + +# Keystone admin credentials: +KEYSTONE = { + 'username': 'admin', + 'password': 'openstack', + 'project_name': 'admin', + 'auth_url': "http://localhost:5000/v2.0" +} + +DEFAULT_REGION = 'RegionOne' + +# Additonal actions for views: +# - The order of the actions matters. These will run after the default action, +# in the given order. +ACTIONVIEW_SETTINGS = { + 'AttachUser': { + 'emails': { + 'token': { + 'reply': 'no-reply@example.com', + 'html_template': 'token.txt', + 'template': 'token.txt', + 'subject': 'Your Token' + }, + 'initial': None, + 'completed': { + 'reply': 'no-reply@example.com', + 'html_template': 'completed.txt', + 'template': 'completed.txt', + 'subject': 'Registration completed' + } + } + }, + 'CreateProject': { + 'emails': { + 'token': { + 'reply': 'no-reply@example.com', + 'html_template': 'token.txt', + 'template': 'token.txt', + 'subject': 'Your Token' + }, + 'initial': { + 'reply': 'no-reply@example.com', + 'html_template': 'initial.txt', + 'template': 'initial.txt', + 'subject': 'Initial Confirmation' + }, + 'completed': { + 'reply': 'no-reply@example.com', + 'html_template': 'completed.txt', + 'template': 'completed.txt', + 'subject': 'Registration completed' + } + }, + 'actions': [ + 'AddAdminToProject', + 'DefaultProjectResources' + ] + }, + 'ResetPassword': { + 'emails': { + 'token': { + 'reply': 'no-reply@example.com', + 'html_template': 'token.txt', + 'template': 'token.txt', + 'subject': 'Your Token' + }, + 'completed': { + 'reply': 'no-reply@example.com', + 'html_template': 'completed.txt', + 'template': 'completed.txt', + 'subject': 'Registration completed' + } + } + } +} + +ACTION_SETTINGS = { + 'DefaultProjectResources': { + 'RegionOne': { + 'DNS_NAMESERVERS': ['193.168.1.2', '193.168.1.3'], + 'SUBNET_CIDR': '192.168.1.0/24', + 'network_name': 'somenetwork', + 'public_network': '3cb50f61-5bce-4c03-96e6-8e262e12bb35', + 'router_name': 'somerouter', + 'subnet_name': 'somesubnet' + } + } +} + +conf_dict = { + "SECRET_KEY": SECRET_KEY, + "ADDITIONAL_APPS": ADDITIONAL_APPS, + "DATABASES": DATABASES, + "LOGGING": LOGGING, + "EMAIL_BACKEND": EMAIL_BACKEND, + "USERNAME_IS_EMAIL": USERNAME_IS_EMAIL, + "KEYSTONE": KEYSTONE, + "DEFAULT_REGION": DEFAULT_REGION, + "ACTIONVIEW_SETTINGS": ACTIONVIEW_SETTINGS, + "ACTION_SETTINGS": ACTION_SETTINGS +} diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000..feb26b9 --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1 @@ +mock==1.2.0 diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..7d6f2ea --- /dev/null +++ b/tox.ini @@ -0,0 +1,10 @@ +[tox] +envlist = py27 +skipsdist = True + +[testenv] +usedevelop = True +deps = -r{toxinidir}/requirements.txt + -r{toxinidir}/test-requirements.txt +commands = stacktask test stacktask +setenv = VIRTUAL_ENV={envdir}