Michael Merickel
2018-10-15 3670c2cdb732d378ba6d38e72e7cd875ff726aa9
commit | author | age
d96ff9 1 import unittest
CM 2
99edc5 3 class TestBWCompat(unittest.TestCase):
CM 4     def test_bwcompat_notfound(self):
5         from pyramid.exceptions import NotFound as one
6         from pyramid.httpexceptions import HTTPNotFound as two
7         self.assertTrue(one is two)
8
9     def test_bwcompat_forbidden(self):
10         from pyramid.exceptions import Forbidden as one
11         from pyramid.httpexceptions import HTTPForbidden as two
12         self.assertTrue(one is two)
13
0e2914 14 class TestBadCSRFToken(unittest.TestCase):
MM 15     def test_response_equivalence(self):
16         from pyramid.exceptions import BadCSRFToken
17         from pyramid.httpexceptions import HTTPBadRequest
18         self.assertTrue(isinstance(BadCSRFToken(), HTTPBadRequest))
19
d96ff9 20 class TestNotFound(unittest.TestCase):
CM 21     def _makeOne(self, message):
b60bdb 22         from pyramid.exceptions import NotFound
d96ff9 23         return NotFound(message)
CM 24
25     def test_it(self):
8c2a9e 26         from pyramid.interfaces import IExceptionResponse
d96ff9 27         e = self._makeOne('notfound')
8c2a9e 28         self.assertTrue(IExceptionResponse.providedBy(e))
d96ff9 29         self.assertEqual(e.status, '404 Not Found')
8c2a9e 30         self.assertEqual(e.message, 'notfound')
d96ff9 31
a7e625 32     def test_response_equivalence(self):
CM 33         from pyramid.exceptions import NotFound
99edc5 34         from pyramid.httpexceptions import HTTPNotFound
a7e625 35         self.assertTrue(NotFound is HTTPNotFound)
CM 36
d96ff9 37 class TestForbidden(unittest.TestCase):
CM 38     def _makeOne(self, message):
b60bdb 39         from pyramid.exceptions import Forbidden
d96ff9 40         return Forbidden(message)
CM 41
42     def test_it(self):
8c2a9e 43         from pyramid.interfaces import IExceptionResponse
CM 44         e = self._makeOne('forbidden')
45         self.assertTrue(IExceptionResponse.providedBy(e))
a05353 46         self.assertEqual(e.status, '403 Forbidden')
8c2a9e 47         self.assertEqual(e.message, 'forbidden')
CM 48
a7e625 49     def test_response_equivalence(self):
CM 50         from pyramid.exceptions import Forbidden
99edc5 51         from pyramid.httpexceptions import HTTPForbidden
a7e625 52         self.assertTrue(Forbidden is HTTPForbidden)
4184d9 53
79ef3d 54 class TestConfigurationConflictError(unittest.TestCase):
CM 55     def _makeOne(self, conflicts):
56         from pyramid.exceptions import ConfigurationConflictError
57         return ConfigurationConflictError(conflicts)
58
59     def test_str(self):
60         conflicts = {'a':('1', '2', '3'), 'b':('4', '5', '6')}
61         exc = self._makeOne(conflicts)
62         self.assertEqual(str(exc),
63 """\
64 Conflicting configuration actions
65   For: a
66     1
67     2
68     3
69   For: b
70     4
71     5
72     6""")
73
74 class TestConfigurationExecutionError(unittest.TestCase):
75     def _makeOne(self, etype, evalue, info):
76         from pyramid.exceptions import ConfigurationExecutionError
77         return ConfigurationExecutionError(etype, evalue, info)
78
79     def test_str(self):
80         exc = self._makeOne('etype', 'evalue', 'info')
81         self.assertEqual(str(exc), 'etype: evalue\n  in:\n  info')
82         
66fe1d 83 class TestCyclicDependencyError(unittest.TestCase):
CM 84     def _makeOne(self, cycles):
85         from pyramid.exceptions import CyclicDependencyError
86         return CyclicDependencyError(cycles)
87
88     def test___str__(self):
89         exc = self._makeOne({'a':['c', 'd'], 'c':['a']})
90         result = str(exc)
91         self.assertTrue("'a' sorts before ['c', 'd']" in result)
92         self.assertTrue("'c' sorts before ['a']" in result)