Adding initial unit tests

This change adds an initial framework to run unit tests with tox.
A first set of unit tests is provided to test the extension part.
Change-Id: Ib914bcf3e06ede5218926dedde2ab83ab70b8485
This commit is contained in:
mathieu-rohon
2015年05月12日 16:46:21 +02:00
parent 14f2bb5b44
commit 289477f9d5

View File

@@ -2,6 +2,6 @@
test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \
OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \
OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-60} \
${PYTHON:-python} -m subunit.run discover -t ./ . $LISTOPT $IDOPTION
${PYTHON:-python} -m subunit.run discover -t ./ ${OS_TEST_PATH:-./networking_bgpvpn/tests/unit} $LISTOPT $IDOPTION
test_id_option=--load-list $IDFILE
test_list_option=--list

View File

@@ -1,23 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright 2010-2011 OpenStack Foundation
# Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
#
# 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.
from oslotest import base
class TestCase(base.BaseTestCase):
"""Test case base class for all unit tests."""

View File

@@ -1,28 +0,0 @@
# -*- coding: utf-8 -*-
# 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.
"""
test_networking_bgpvpn
----------------------------------
Tests for `networking_bgpvpn` module.
"""
from networking_bgpvpn.tests import base
class TestNetworking_bgpvpn(base.TestCase):
def test_something(self):
pass

View File

View File

@@ -0,0 +1,201 @@
# Copyright (c) 2015 Orange.
# All Rights Reserved.
#
# 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.
import copy
import mock
from neutron.openstack.common import uuidutils
from neutron.plugins.common import constants
from neutron.tests.unit.api.v2 import test_base
from neutron.tests.unit.extensions import base as test_extensions_base
from webob import exc
from networking_bgpvpn.neutron.extensions.bgpvpn import bgpvpn
_uuid = uuidutils.generate_uuid
_get_path = test_base._get_path
BGPVPN_URI = 'bgpvpn'
BGPVPN_CONN_URI = BGPVPN_URI + '/' + 'bgpvpn-connections'
BGPVPN_PLUGIN_BASE_NAME = (
bgpvpn.BGPVPNPluginBase.__module__ + '.' +
bgpvpn.BGPVPNPluginBase.__name__)
class BgpvpnExtensionTestCase(test_extensions_base.ExtensionTestCase):
fmt = 'json'
def setUp(self):
super(BgpvpnExtensionTestCase, self).setUp()
plural_mappings = {'bgpvpn_connection': 'bgpvpn_connections'}
self._setUpExtension(
BGPVPN_PLUGIN_BASE_NAME,
constants.BGPVPN,
bgpvpn.RESOURCE_ATTRIBUTE_MAP,
bgpvpn.Bgpvpn,
BGPVPN_URI,
plural_mappings=plural_mappings,
translate_resource_name=True)
self.instance = self.plugin.return_value
def test_bgpvpn_connection_create(self):
bgpvpn_conn_id = _uuid()
network_id = _uuid()
data = {
'bgpvpn_connection': {'name': 'bgpvpn-connection1',
'type': 'l3',
'route_targets': ['1234:56'],
'network_id': network_id,
'auto_aggregate': False,
'tenant_id': _uuid()}
}
expected_ret_val = copy.copy(data['bgpvpn_connection'])
expected_ret_val['import_targets'] = []
expected_ret_val['export_targets'] = []
expected_call_args = copy.copy(expected_ret_val)
expected_ret_val.update({'id': bgpvpn_conn_id})
self.instance.create_bgpvpn_connection.return_value = expected_ret_val
res = self.api.post(_get_path(BGPVPN_CONN_URI, fmt=self.fmt),
self.serialize(data),
content_type='application/%s' % self.fmt)
self.instance.create_bgpvpn_connection.assert_called_with(
mock.ANY,
bgpvpn_connection={'bgpvpn_connection': expected_call_args}
)
self.assertEqual(res.status_int, exc.HTTPCreated.code)
res = self.deserialize(res)
self.assertIn('bgpvpn_connection', res)
self.assertEqual(res['bgpvpn_connection'], expected_ret_val)
def test_bgpvpn_connection_create_with_malformatted_route_target(self):
network_id = _uuid()
data = {
'bgpvpn_connection': {'name': 'bgpvpn-connection1',
'type': 'l3',
'route_targets': ['ASN:NN'],
'network_id': network_id,
'auto_aggregate': False,
'tenant_id': _uuid()}
}
res = self.api.post(_get_path(BGPVPN_CONN_URI, fmt=self.fmt),
self.serialize(data),
content_type='application/%s' % self.fmt,
expect_errors=True)
self.assertEqual(res.status_int, exc.HTTPBadRequest.code)
def test_bgpvpn_connection_create_with_invalid_route_target(self):
network_id = _uuid()
data = {
'bgpvpn_connection': {'name': 'bgpvpn-connection1',
'type': 'l3',
'route_targets': ['65536:0'],
'network_id': network_id,
'auto_aggregate': False,
'tenant_id': _uuid()}
}
res = self.api.post(_get_path(BGPVPN_CONN_URI,
fmt=self.fmt),
self.serialize(data),
content_type='application/%s' % self.fmt,
expect_errors=True)
self.assertEqual(res.status_int, exc.HTTPBadRequest.code)
data['bgpvpn_connection']['route_targets'] = ['0:65536']
res = self.api.post(_get_path(BGPVPN_CONN_URI, fmt=self.fmt),
self.serialize(data),
content_type='application/%s' % self.fmt,
expect_errors=True)
self.assertEqual(res.status_int, exc.HTTPBadRequest.code)
def test_bgpvpn_connection_list(self):
bgpvpn_conn_id = _uuid()
return_value = [{'name': 'bgpvpn-connection1',
'type': 'l3',
'route_targets': ['1234:56'],
'auto_aggregate': False,
'id': bgpvpn_conn_id}]
self.instance.get_bgpvpn_connections.return_value = return_value
res = self.api.get(
_get_path(BGPVPN_CONN_URI, fmt=self.fmt))
self.instance.get_bgpvpn_connections.assert_called_with(
mock.ANY, fields=mock.ANY, filters=mock.ANY
)
self.assertEqual(res.status_int, exc.HTTPOk.code)
def test_bgpvpn_connection_update(self):
bgpvpn_conn_id = _uuid()
network_id = _uuid()
update_data = {'bgpvpn_connection': {'network_id': network_id}}
return_value = {'name': 'bgpvpn-connection1',
'type': 'l3',
'route_targets': ['1234:56'],
'network_id': network_id,
'auto_aggregate': False,
'tenant_id': _uuid(),
'id': bgpvpn_conn_id}
self.instance.update_bgpvpn_connection.return_value = return_value
res = self.api.put(_get_path(BGPVPN_CONN_URI,
id=bgpvpn_conn_id,
fmt=self.fmt),
self.serialize(update_data),
content_type='application/%s' % self.fmt)
self.instance.update_bgpvpn_connection.assert_called_with(
mock.ANY, bgpvpn_conn_id, bgpvpn_connection=update_data
)
self.assertEqual(res.status_int, exc.HTTPOk.code)
res = self.deserialize(res)
self.assertIn('bgpvpn_connection', res)
self.assertEqual(res['bgpvpn_connection'], return_value)
def test_bgpvpn_connection_get(self):
bgpvpn_conn_id = _uuid()
return_value = {'name': 'bgpvpn-connection1',
'type': 'l3',
'route_targets': ['1234:56'],
'network_id': _uuid(),
'auto_aggregate': False,
'tenant_id': _uuid(),
'id': bgpvpn_conn_id}
self.instance.get_bgpvpn_connection.return_value = return_value
res = self.api.get(_get_path(BGPVPN_CONN_URI,
id=bgpvpn_conn_id,
fmt=self.fmt))
self.instance.get_bgpvpn_connection.assert_called_with(
mock.ANY, bgpvpn_conn_id, fields=mock.ANY
)
self.assertEqual(res.status_int, exc.HTTPOk.code)
res = self.deserialize(res)
self.assertIn('bgpvpn_connection', res)
self.assertEqual(res['bgpvpn_connection'], return_value)
def test_bgpvpn_connection_delete(self):
self._test_entity_delete('bgpvpn_connection')

View File

@@ -4,3 +4,9 @@
pbr>=0.6,!=0.7,<1.0
Babel>=1.3
# This project does depend on neutron as a library, but the
# openstack tooling does not play nicely with projects that
# are not publicly available in pypi.
# -e git+https://git.openstack.org/openstack/neutron#egg=neutron

View File

@@ -9,6 +9,8 @@ discover
python-subunit>=0.0.18
sphinx>=1.1.2,!=1.2.0,!=1.3b1,<1.3
oslosphinx>=2.2.0 # Apache-2.0
WebOb>=1.2.3
WebTest>=2.0
oslotest>=1.2.0 # Apache-2.0
testrepository>=0.0.18
testscenarios>=0.4

View File

@@ -8,7 +8,8 @@ usedevelop = True
install_command = pip install -U {opts} {packages}
setenv =
VIRTUAL_ENV={envdir}
deps = -r{toxinidir}/requirements.txt
deps = -egit+https://git.openstack.org/openstack/neutron#egg=neutron
-r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
commands = python setup.py testr --slowest --testr-args='{posargs}'
Reference in New Issue
openstack/networking-bgpvpn
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.

The note is not visible to the blocked user.