Exemplo n.º 1
0
class Test_wsgi(unittest.TestCase):
    """ Test case for wsgi
    """
    def setUp(self):
        controller_data = {'test_param': 'foo'}
        self.wsgi_app = WSGIApplication()
        self.wsgi_app.register(_TestController, controller_data)

    def tearDown(self):
        pass

    def test_wsgi_decorator_ok(self):
        r = self.wsgi_app(
            {
                'REQUEST_METHOD': 'GET',
                'PATH_INFO': '/test/0123456789abcdef'
            }, lambda s, _: eq_(s, '200 OK'))
        eq_(r[0], (b'0123456789abcdef'))

    def test_wsgi_decorator_ng_path(self):
        self.wsgi_app({
            'REQUEST_METHOD': 'GET',
            'PATH_INFO': '/'
        }, lambda s, _: eq_(s, '404 Not Found'))

    def test_wsgi_decorator_ng_method(self):
        # XXX: If response code is "405 Method Not Allowed", it is better.
        self.wsgi_app(
            {
                'REQUEST_METHOD': 'PUT',
                'PATH_INFO': '/test/0123456789abcdef'
            }, lambda s, _: eq_(s, '404 Not Found'))

    def test_wsgi_decorator_ng_requirements(self):
        # XXX: If response code is "400 Bad Request", it is better.
        self.wsgi_app({
            'REQUEST_METHOD': 'GET',
            'PATH_INFO': '/test/hogehoge'
        }, lambda s, _: eq_(s, '404 Not Found'))

    def test_wsgi_decorator_ok_any_method(self):
        self.wsgi_app({
            'REQUEST_METHOD': 'GET',
            'PATH_INFO': '/test'
        }, lambda s, _: eq_(s, '200 OK'))
        self.wsgi_app({
            'REQUEST_METHOD': 'POST',
            'PATH_INFO': '/test'
        }, lambda s, _: eq_(s, '200 OK'))
        self.wsgi_app({
            'REQUEST_METHOD': 'PUT',
            'PATH_INFO': '/test'
        }, lambda s, _: eq_(s, '200 OK'))
        r = self.wsgi_app({
            'REQUEST_METHOD': 'DELETE',
            'PATH_INFO': '/test'
        }, lambda s, _: eq_(s, '200 OK'))
        eq_(r[0], b'root')
Exemplo n.º 2
0
class Test_wsgi(unittest.TestCase):

    """ Test case for wsgi
    """

    def setUp(self):
        controller_data = {
            'test_param': 'foo'
        }
        self.wsgi_app = WSGIApplication()
        self.wsgi_app.register(_TestController, controller_data)

    def tearDown(self):
        pass

    def test_wsgi_decorator_ok(self):
        r = self.wsgi_app({'REQUEST_METHOD': 'GET',
                           'PATH_INFO': '/test/0123456789abcdef'},
                          lambda s, _: eq_(s, '200 OK'))
        eq_(r[0], (b'0123456789abcdef'))

    def test_wsgi_decorator_ng_path(self):
        self.wsgi_app({'REQUEST_METHOD': 'GET',
                       'PATH_INFO': '/'},
                      lambda s, _: eq_(s, '404 Not Found'))

    def test_wsgi_decorator_ng_method(self):
        # XXX: If response code is "405 Method Not Allowed", it is better.
        self.wsgi_app({'REQUEST_METHOD': 'PUT',
                       'PATH_INFO': '/test/0123456789abcdef'},
                      lambda s, _: eq_(s, '404 Not Found'))

    def test_wsgi_decorator_ng_requirements(self):
        # XXX: If response code is "400 Bad Request", it is better.
        self.wsgi_app({'REQUEST_METHOD': 'GET',
                       'PATH_INFO': '/test/hogehoge'},
                      lambda s, _: eq_(s, '404 Not Found'))

    def test_wsgi_decorator_ok_any_method(self):
        self.wsgi_app({'REQUEST_METHOD': 'GET',
                       'PATH_INFO': '/test'},
                      lambda s, _: eq_(s, '200 OK'))
        self.wsgi_app({'REQUEST_METHOD': 'POST',
                       'PATH_INFO': '/test'},
                      lambda s, _: eq_(s, '200 OK'))
        self.wsgi_app({'REQUEST_METHOD': 'PUT',
                       'PATH_INFO': '/test'},
                      lambda s, _: eq_(s, '200 OK'))
        r = self.wsgi_app({'REQUEST_METHOD': 'DELETE',
                           'PATH_INFO': '/test'},
                          lambda s, _: eq_(s, '200 OK'))
        eq_(r[0], b'root')
Exemplo n.º 3
0
    def _test(self, name, dp, method, path, body):
        print('processing %s ...' % name)

        dpset = DPSet()
        dpset._register(dp)
        wsgi = WSGIApplication()
        contexts = {
            'dpset': dpset,
            'wsgi': wsgi,
        }
        ofctl_rest.RestStatsApi(**contexts)

        req = Request.blank(path)
        req.body = json.dumps(body).encode('utf-8')
        req.method = method

        with mock.patch('ryu.lib.ofctl_utils.send_stats_request'),\
                mock.patch('ryu.lib.ofctl_utils.send_msg'):
            res = req.get_response(wsgi)
        eq_(res.status, '200 OK')
Exemplo n.º 4
0
#*** JSON imports:
import json
from json import JSONEncoder

#*** nmeta2 imports:
import nmeta2
import switch_abstraction
import config

#*** Instantiate Config class:
_config = config.Config()

#====================== switch_abstraction.py Unit Tests ======================
#*** Instantiate class:
wsgi_app = WSGIApplication()
nmeta = nmeta2.Nmeta(wsgi=wsgi_app)

switches = switch_abstraction.Switches(nmeta, _config)

sock_mock = mock.Mock()
addr_mock = mock.Mock()

#*** Constant to use for a port not found value:
PORT_NOT_FOUND = 999999999

#*** Test Constants:
MAC123 = '00:00:00:00:01:23'
PORT123 = 123
CONTEXT1 = 1
Exemplo n.º 5
0
def init_rest_api(hyper_ryu_core, host, port):
    wsgi = WSGIApplication()
    webapp = hub.WSGIServer((host, port), wsgi)
    hub.spawn(webapp.serve_forever)
    wsgi.registry['HRRestController'] = {'core_app': hyper_ryu_core}
    init_mapper(wsgi.mapper)
Exemplo n.º 6
0
 def setUp(self):
     controller_data = {
         'test_param': 'foo'
     }
     self.wsgi_app = WSGIApplication()
     self.wsgi_app.register(_TestController, controller_data)
Exemplo n.º 7
0
 def create_wsgi_app(self, host, port):
     wsgi = WSGIApplication()
     webapp = hub.WSGIServer((host, port), wsgi)
     hub.spawn(webapp.serve_forever)
     return wsgi
Exemplo n.º 8
0
 def setUp(self):
     wsgi = WSGIApplication()
     #*** Instantiate API class:
     self.api = api.Api(self, _config, wsgi)
Exemplo n.º 9
0
 def setUp(self):
     controller_data = {
         'test_param': 'foo'
     }
     self.wsgi_app = WSGIApplication()
     self.wsgi_app.register(_TestController, controller_data)
Exemplo n.º 10
0
 def setUp(self):
     self.wsgi_app = WSGIApplication()
     self.wsgi_app.register(_TestController)