File: test_root.py

package info (click to toggle)
python-wsme 0.6-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 956 kB
  • ctags: 1,831
  • sloc: python: 8,452; makefile: 138
file content (41 lines) | stat: -rw-r--r-- 1,247 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# encoding=utf8

import unittest

from wsme import WSRoot
from wsme.root import default_prepare_response_body

from six import b, u


class TestRoot(unittest.TestCase):
    def test_default_transaction(self):
        import transaction
        root = WSRoot(transaction=True)
        assert root._transaction is transaction

        txn = root.begin()
        txn.abort()

    def test_default_prepare_response_body(self):
        default_prepare_response_body(None, [b('a')]) == b('a')
        default_prepare_response_body(None, [b('a'), b('b')]) == b('a\nb')
        default_prepare_response_body(None, [u('a')]) == u('a')
        default_prepare_response_body(None, [u('a'), u('b')]) == u('a\nb')

    def test_protocol_selection_error(self):
        import wsme.protocol

        class P(wsme.protocol.Protocol):
            def accept(self, r):
                raise Exception('test')

        root = WSRoot()
        root.addprotocol(P())

        from webob import Request
        req = Request.blank('/test?check=a&check=b&name=Bob')
        res = root._handle_request(req)
        assert res.status_int == 500
        assert res.content_type == 'text/plain'
        assert res.text == u('Error while selecting protocol: test'), req.text