summaryrefslogtreecommitdiffstats
path: root/multivimbroker
diff options
context:
space:
mode:
authorHong Hui Xiao <honghui_xiao@yeah.net>2017-08-28 16:54:57 +0800
committerHong Hui Xiao <honghui_xiao@yeah.net>2017-09-01 20:30:57 +0800
commit7bd792729198f1a04eac6d2042c7a03a632814a0 (patch)
tree1ba4c7b9352f21092c6d7f097c148fe531696bc2 /multivimbroker
parent67430600410e312c2db5a6a7709da8e45a5245fa (diff)
Add code coverage for multicloud framework
Since multicloud projects are Django projects essentially, use the mechanism from Django to check code coverage. Change-Id: I850e64e601f9cf4d26222a2a2295ec005dfea474 Issue-Id: MULTICLOUD-71 Signed-off-by: Hong Hui Xiao <honghui_xiao@yeah.net>
Diffstat (limited to 'multivimbroker')
-rw-r--r--multivimbroker/multivimbroker/settings-cover.py20
-rw-r--r--multivimbroker/multivimbroker/tests/__init__.py10
-rw-r--r--multivimbroker/multivimbroker/tests/test_urls.py26
-rw-r--r--multivimbroker/multivimbroker/urls.py22
-rw-r--r--multivimbroker/requirements.txt1
-rw-r--r--multivimbroker/tox.ini15
6 files changed, 85 insertions, 9 deletions
diff --git a/multivimbroker/multivimbroker/settings-cover.py b/multivimbroker/multivimbroker/settings-cover.py
new file mode 100644
index 0000000..51b73e8
--- /dev/null
+++ b/multivimbroker/multivimbroker/settings-cover.py
@@ -0,0 +1,20 @@
+# 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.
+
+from multivimbroker.settings import * # noqa
+from multivimbroker.settings import INSTALLED_APPS
+
+INSTALLED_APPS.append('django_nose')
+
+TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
+
+NOSE_ARGS = [
+ '--with-coverage',
+ '--cover-package=multivimbroker',
+]
diff --git a/multivimbroker/multivimbroker/tests/__init__.py b/multivimbroker/multivimbroker/tests/__init__.py
new file mode 100644
index 0000000..802f3fb
--- /dev/null
+++ b/multivimbroker/multivimbroker/tests/__init__.py
@@ -0,0 +1,10 @@
+# Copyright (c) 2017 Wind River Systems, Inc.
+#
+# 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.
diff --git a/multivimbroker/multivimbroker/tests/test_urls.py b/multivimbroker/multivimbroker/tests/test_urls.py
new file mode 100644
index 0000000..71241f8
--- /dev/null
+++ b/multivimbroker/multivimbroker/tests/test_urls.py
@@ -0,0 +1,26 @@
+# 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.
+
+import json
+import mock
+import unittest
+
+from multivimbroker.pub.config import config
+from multivimbroker import urls
+
+
+class TestUrls(unittest.TestCase):
+
+ def test_request_msb(self):
+ with mock.patch("multivimbroker.pub.utils.restcall."
+ "req_by_msb") as req_by_msb:
+ urls.req_msb(True)
+ req_by_msb.assert_called_once_with(
+ config.REG_TO_MSB_REG_URL, "POST",
+ json.JSONEncoder().encode(config.REG_TO_MSB_REG_PARAM))
diff --git a/multivimbroker/multivimbroker/urls.py b/multivimbroker/multivimbroker/urls.py
index c8e0f42..7619e5a 100644
--- a/multivimbroker/multivimbroker/urls.py
+++ b/multivimbroker/multivimbroker/urls.py
@@ -10,8 +10,10 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
from django.conf.urls import include, url
-from multivimbroker.pub.config.config \
- import REG_TO_MSB_WHEN_START, REG_TO_MSB_REG_URL, REG_TO_MSB_REG_PARAM
+import json
+
+from multivimbroker.pub.config import config
+
urlpatterns = [
url(r'^', include('multivimbroker.swagger.urls')),
@@ -19,9 +21,13 @@ urlpatterns = [
url(r'^', include('multivimbroker.forwarder.urls')),
]
-# regist to MSB when startup
-if REG_TO_MSB_WHEN_START:
- import json
- from multivimbroker.pub.utils.restcall import req_by_msb
- req_by_msb(REG_TO_MSB_REG_URL, "POST",
- json.JSONEncoder().encode(REG_TO_MSB_REG_PARAM))
+
+def req_msb(request_when_start):
+ # regist to MSB when startup
+ if request_when_start:
+ from multivimbroker.pub.utils.restcall import req_by_msb
+ req_by_msb(config.REG_TO_MSB_REG_URL, "POST",
+ json.JSONEncoder().encode(config.REG_TO_MSB_REG_PARAM))
+
+
+req_msb(config.REG_TO_MSB_WHEN_START)
diff --git a/multivimbroker/requirements.txt b/multivimbroker/requirements.txt
index 6d58957..caf8687 100644
--- a/multivimbroker/requirements.txt
+++ b/multivimbroker/requirements.txt
@@ -18,6 +18,7 @@ python-glanceclient==2.5.0
python-neutronclient==6.0.0
# for unit test
+django-nose>=1.4.0
coverage==4.2
mock==2.0.0
unittest_xml_reporting==1.12.0
diff --git a/multivimbroker/tox.ini b/multivimbroker/tox.ini
index 88d43d9..4db044a 100644
--- a/multivimbroker/tox.ini
+++ b/multivimbroker/tox.ini
@@ -7,8 +7,21 @@ downloadcache = ~/cache/pip
[testenv]
deps = -r{toxinidir}/requirements.txt
-commands = coverage run --branch manage.py test multivimbroker
+commands =
+ /usr/bin/find . -type f -name "*.py[c|o]" -delete
+ python manage.py test multivimbroker
[testenv:pep8]
deps=flake8
commands=flake8
+
+[testenv:py27]
+commands =
+ {[testenv]commands}
+
+[testenv:cover]
+setenv=
+ DJANGO_SETTINGS_MODULE = multivimbroker.settings-cover
+commands =
+ coverage erase
+ {[testenv]commands}