diff options
author | xinhuili <lxinhui@vmware.com> | 2017-09-13 00:33:33 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2017-09-13 00:33:33 +0000 |
commit | d4123e672586bc38820d6a00d7f0103b4e10b103 (patch) | |
tree | 76ac23441cf31de2124c276516ef026927836125 /multivimbroker | |
parent | 363bd35940c079bf364ca9b5b4c4f3915972df63 (diff) | |
parent | 7bd792729198f1a04eac6d2042c7a03a632814a0 (diff) |
Merge "Add code coverage for multicloud framework"
Diffstat (limited to 'multivimbroker')
-rw-r--r-- | multivimbroker/multivimbroker/settings-cover.py | 20 | ||||
-rw-r--r-- | multivimbroker/multivimbroker/tests/__init__.py | 10 | ||||
-rw-r--r-- | multivimbroker/multivimbroker/tests/test_urls.py | 26 | ||||
-rw-r--r-- | multivimbroker/multivimbroker/urls.py | 22 | ||||
-rw-r--r-- | multivimbroker/requirements.txt | 1 | ||||
-rw-r--r-- | multivimbroker/tox.ini | 15 |
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} |