diff --git a/kuryr/tests/base.py b/kuryr/tests/base.py index 1c30cdb5..1612098a 100644 --- a/kuryr/tests/base.py +++ b/kuryr/tests/base.py @@ -1,8 +1,3 @@ -# -*- 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 @@ -17,7 +12,13 @@ from oslotest import base +from kuryr import app + class TestCase(base.BaseTestCase): - """Test case base class for all unit tests.""" + + def setUp(self): + super(TestCase, self).setUp() + app.config['TESTING'] = True + self.app = app.test_client() diff --git a/kuryr/tests/test_kuryr.py b/kuryr/tests/test_kuryr.py index 8c94c475..75dda9eb 100644 --- a/kuryr/tests/test_kuryr.py +++ b/kuryr/tests/test_kuryr.py @@ -1,5 +1,3 @@ -# -*- 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 @@ -12,17 +10,42 @@ # License for the specific language governing permissions and limitations # under the License. -""" -test_kuryr ----------------------------------- - -Tests for `kuryr` module. -""" +from ddt import ddt, data, unpack +from oslo_serialization import jsonutils +from kuryr.constants import SCHEMA from kuryr.tests import base +@ddt class TestKuryr(base.TestCase): + """Basic unitests for libnetwork remote driver URI endpoints. - def test_something(self): - pass + This test class covers the following HTTP methods and URIs as described in + the remote driver specification as below: + + https://github.com/docker/libnetwork/blob/3c8e06bc0580a2a1b2440fe0792fbfcd43a9feca/docs/remote.md # noqa + + - POST /Plugin.Activate + - POST /NetworkDriver.CreateNetwork + - POST /NetworkDriver.DeleteNetwork + - POST /NetworkDriver.CreateEndpoint + - POST /NetworkDriver.EndpointOperInfo + - POST /NetworkDriver.DeleteEndpoint + - POST /NetworkDriver.Join + - POST /NetworkDriver.Leave + """ + + @data(('/Plugin.Activate', SCHEMA['PLUGIN_ACTIVATE']), + ('/NetworkDriver.CreateNetwork', SCHEMA['SUCCESS']), + ('/NetworkDriver.DeleteNetwork', SCHEMA['SUCCESS']), + ('/NetworkDriver.CreateEndpoint', SCHEMA['CREATE_ENDPOINT']), + ('/NetworkDriver.EndpointOperInfo', SCHEMA['ENDPOINT_OPER_INFO']), + ('/NetworkDriver.DeleteEndpoint', SCHEMA['SUCCESS']), + ('/NetworkDriver.Join', SCHEMA['JOIN']), + ('/NetworkDriver.Leave', SCHEMA['SUCCESS'])) + @unpack + def test_remote_driver_endpoint(self, endpoint, expected): + response = self.app.post(endpoint) + decoded_json = jsonutils.loads(response.data) + self.assertEqual(expected, decoded_json) diff --git a/requirements.txt b/requirements.txt index fa3748aa..7dac0c3b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,3 +5,5 @@ pbr<2.0,>=1.3 Babel>=1.3 Flask>=0.10,<1.0 +oslo.serialization>=1.4.0 # Apache-2.0 + diff --git a/test-requirements.txt b/test-requirements.txt index 60ff718f..838bced1 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -7,6 +7,7 @@ hacking<0.11,>=0.10.0 coverage>=3.6 discover +ddt>=0.7.0 python-subunit>=0.0.18 sphinx!=1.2.0,!=1.3b1,<1.3,>=1.1.2 oslosphinx>=2.5.0 # Apache-2.0