/usr/lib/python2.7/dist-packages/pyramid/tests/test_config/test_init.py is in python-pyramid 1.4.5+dfsg-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 | import unittest
import warnings
import os
from pyramid.compat import PYPY
from pyramid.compat import im_func
from pyramid.testing import skip_on
from pyramid.tests.test_config import dummy_tween_factory
from pyramid.tests.test_config import dummy_include
from pyramid.tests.test_config import dummy_extend
from pyramid.tests.test_config import dummy_extend2
from pyramid.tests.test_config import IDummy
from pyramid.tests.test_config import DummyContext
from pyramid.exceptions import ConfigurationExecutionError
from pyramid.exceptions import ConfigurationConflictError
class ConfiguratorTests(unittest.TestCase):
def _makeOne(self, *arg, **kw):
from pyramid.config import Configurator
config = Configurator(*arg, **kw)
return config
def _getViewCallable(self, config, ctx_iface=None, request_iface=None,
name='', exception_view=False):
from zope.interface import Interface
from pyramid.interfaces import IRequest
from pyramid.interfaces import IView
from pyramid.interfaces import IViewClassifier
from pyramid.interfaces import IExceptionViewClassifier
if exception_view: # pragma: no cover
classifier = IExceptionViewClassifier
else:
classifier = IViewClassifier
if ctx_iface is None:
ctx_iface = Interface
if request_iface is None:
request_iface = IRequest
return config.registry.adapters.lookup(
(classifier, request_iface, ctx_iface), IView, name=name,
default=None)
def _registerEventListener(self, config, event_iface=None):
if event_iface is None: # pragma: no cover
from zope.interface import Interface
event_iface = Interface
L = []
def subscriber(*event):
L.extend(event)
config.registry.registerHandler(subscriber, (event_iface,))
return L
def _makeRequest(self, config):
request = DummyRequest()
request.registry = config.registry
return request
def test_ctor_no_registry(self):
import sys
from pyramid.interfaces import ISettings
from pyramid.config import Configurator
from pyramid.interfaces import IRendererFactory
config = Configurator()
this_pkg = sys.modules['pyramid.tests.test_config']
self.assertTrue(config.registry.getUtility(ISettings))
self.assertEqual(config.package, this_pkg)
config.commit()
self.assertTrue(config.registry.getUtility(IRendererFactory, 'json'))
self.assertTrue(config.registry.getUtility(IRendererFactory, 'string'))
if not PYPY:
self.assertTrue(config.registry.getUtility(IRendererFactory, '.pt'))
self.assertTrue(config.registry.getUtility(IRendererFactory,'.txt'))
self.assertTrue(config.registry.getUtility(IRendererFactory, '.mak'))
self.assertTrue(config.registry.getUtility(IRendererFactory, '.mako'))
def test_begin(self):
from pyramid.config import Configurator
config = Configurator()
manager = DummyThreadLocalManager()
config.manager = manager
config.begin()
self.assertEqual(manager.pushed,
{'registry':config.registry, 'request':None})
self.assertEqual(manager.popped, False)
def test_begin_with_request(self):
from pyramid.config import Configurator
config = Configurator()
request = object()
manager = DummyThreadLocalManager()
config.manager = manager
config.begin(request=request)
self.assertEqual(manager.pushed,
{'registry':config.registry, 'request':request})
self.assertEqual(manager.popped, False)
def test_end(self):
from pyramid.config import Configurator
config = Configurator()
manager = DummyThreadLocalManager()
config.manager = manager
config.end()
self.assertEqual(manager.pushed, None)
self.assertEqual(manager.popped, True)
def test_ctor_with_package_registry(self):
import sys
from pyramid.config import Configurator
pkg = sys.modules['pyramid']
config = Configurator(package=pkg)
self.assertEqual(config.package, pkg)
def test_ctor_noreg_custom_settings(self):
from pyramid.interfaces import ISettings
settings = {'reload_templates':True,
'mysetting':True}
config = self._makeOne(settings=settings)
settings = config.registry.getUtility(ISettings)
self.assertEqual(settings['reload_templates'], True)
self.assertEqual(settings['debug_authorization'], False)
self.assertEqual(settings['mysetting'], True)
def test_ctor_noreg_debug_logger_None_default(self):
from pyramid.interfaces import IDebugLogger
config = self._makeOne()
logger = config.registry.getUtility(IDebugLogger)
self.assertEqual(logger.name, 'pyramid.tests.test_config')
def test_ctor_noreg_debug_logger_non_None(self):
from pyramid.interfaces import IDebugLogger
logger = object()
config = self._makeOne(debug_logger=logger)
result = config.registry.getUtility(IDebugLogger)
self.assertEqual(logger, result)
def test_ctor_authentication_policy(self):
from pyramid.interfaces import IAuthenticationPolicy
policy = object()
config = self._makeOne(authentication_policy=policy)
config.commit()
result = config.registry.getUtility(IAuthenticationPolicy)
self.assertEqual(policy, result)
def test_ctor_authorization_policy_only(self):
policy = object()
config = self._makeOne(authorization_policy=policy)
self.assertRaises(ConfigurationExecutionError, config.commit)
def test_ctor_no_root_factory(self):
from pyramid.interfaces import IRootFactory
config = self._makeOne()
self.assertEqual(config.registry.queryUtility(IRootFactory), None)
config.commit()
self.assertEqual(config.registry.queryUtility(IRootFactory), None)
def test_ctor_with_root_factory(self):
from pyramid.interfaces import IRootFactory
factory = object()
config = self._makeOne(root_factory=factory)
self.assertEqual(config.registry.queryUtility(IRootFactory), None)
config.commit()
self.assertEqual(config.registry.queryUtility(IRootFactory), factory)
def test_ctor_alternate_renderers(self):
from pyramid.interfaces import IRendererFactory
renderer = object()
config = self._makeOne(renderers=[('yeah', renderer)])
config.commit()
self.assertEqual(config.registry.getUtility(IRendererFactory, 'yeah'),
renderer)
def test_ctor_default_renderers(self):
from pyramid.interfaces import IRendererFactory
from pyramid.renderers import json_renderer_factory
config = self._makeOne()
self.assertEqual(config.registry.getUtility(IRendererFactory, 'json'),
json_renderer_factory)
def test_ctor_default_permission(self):
from pyramid.interfaces import IDefaultPermission
config = self._makeOne(default_permission='view')
config.commit()
self.assertEqual(config.registry.getUtility(IDefaultPermission), 'view')
def test_ctor_session_factory(self):
from pyramid.interfaces import ISessionFactory
factory = object()
config = self._makeOne(session_factory=factory)
self.assertEqual(config.registry.queryUtility(ISessionFactory), None)
config.commit()
self.assertEqual(config.registry.getUtility(ISessionFactory), factory)
def test_ctor_default_view_mapper(self):
from pyramid.interfaces import IViewMapperFactory
mapper = object()
config = self._makeOne(default_view_mapper=mapper)
config.commit()
self.assertEqual(config.registry.getUtility(IViewMapperFactory),
mapper)
def test_ctor_httpexception_view_default(self):
from pyramid.interfaces import IExceptionResponse
from pyramid.httpexceptions import default_exceptionresponse_view
from pyramid.interfaces import IRequest
config = self._makeOne()
view = self._getViewCallable(config,
ctx_iface=IExceptionResponse,
request_iface=IRequest)
self.assertTrue(view.__wraps__ is default_exceptionresponse_view)
def test_ctor_exceptionresponse_view_None(self):
from pyramid.interfaces import IExceptionResponse
from pyramid.interfaces import IRequest
config = self._makeOne(exceptionresponse_view=None)
view = self._getViewCallable(config,
ctx_iface=IExceptionResponse,
request_iface=IRequest)
self.assertTrue(view is None)
def test_ctor_exceptionresponse_view_custom(self):
from pyramid.interfaces import IExceptionResponse
from pyramid.interfaces import IRequest
def exceptionresponse_view(context, request): pass
config = self._makeOne(exceptionresponse_view=exceptionresponse_view)
view = self._getViewCallable(config,
ctx_iface=IExceptionResponse,
request_iface=IRequest)
self.assertTrue(view.__wraps__ is exceptionresponse_view)
def test_ctor_with_introspection(self):
config = self._makeOne(introspection=False)
self.assertEqual(config.introspection, False)
def test_with_package_module(self):
from pyramid.tests.test_config import test_init
import pyramid.tests
config = self._makeOne()
newconfig = config.with_package(test_init)
self.assertEqual(newconfig.package, pyramid.tests.test_config)
def test_with_package_package(self):
import pyramid.tests.test_config
config = self._makeOne()
newconfig = config.with_package(pyramid.tests.test_config)
self.assertEqual(newconfig.package, pyramid.tests.test_config)
def test_with_package(self):
import pyramid.tests
config = self._makeOne()
config.basepath = 'basepath'
config.info = 'info'
config.includepath = ('spec',)
config.autocommit = True
config.route_prefix = 'prefix'
newconfig = config.with_package(pyramid.tests)
self.assertEqual(newconfig.package, pyramid.tests)
self.assertEqual(newconfig.registry, config.registry)
self.assertEqual(newconfig.autocommit, True)
self.assertEqual(newconfig.route_prefix, 'prefix')
self.assertEqual(newconfig.info, 'info')
self.assertEqual(newconfig.basepath, 'basepath')
self.assertEqual(newconfig.includepath, ('spec',))
def test_maybe_dotted_string_success(self):
import pyramid.tests.test_config
config = self._makeOne()
result = config.maybe_dotted('pyramid.tests.test_config')
self.assertEqual(result, pyramid.tests.test_config)
def test_maybe_dotted_string_fail(self):
config = self._makeOne()
self.assertRaises(ImportError, config.maybe_dotted, 'cant.be.found')
def test_maybe_dotted_notstring_success(self):
import pyramid.tests.test_config
config = self._makeOne()
result = config.maybe_dotted(pyramid.tests.test_config)
self.assertEqual(result, pyramid.tests.test_config)
def test_absolute_asset_spec_already_absolute(self):
import pyramid.tests.test_config
config = self._makeOne(package=pyramid.tests.test_config)
result = config.absolute_asset_spec('already:absolute')
self.assertEqual(result, 'already:absolute')
def test_absolute_asset_spec_notastring(self):
import pyramid.tests.test_config
config = self._makeOne(package=pyramid.tests.test_config)
result = config.absolute_asset_spec(None)
self.assertEqual(result, None)
def test_absolute_asset_spec_relative(self):
import pyramid.tests.test_config
config = self._makeOne(package=pyramid.tests.test_config)
result = config.absolute_asset_spec('files')
self.assertEqual(result, 'pyramid.tests.test_config:files')
def test__fix_registry_has_listeners(self):
reg = DummyRegistry()
config = self._makeOne(reg)
config._fix_registry()
self.assertEqual(reg.has_listeners, True)
def test__fix_registry_notify(self):
reg = DummyRegistry()
config = self._makeOne(reg)
config._fix_registry()
self.assertEqual(reg.notify(1), None)
self.assertEqual(reg.events, (1,))
def test__fix_registry_queryAdapterOrSelf(self):
from zope.interface import Interface
from zope.interface import implementer
class IFoo(Interface):
pass
@implementer(IFoo)
class Foo(object):
pass
class Bar(object):
pass
adaptation = ()
foo = Foo()
bar = Bar()
reg = DummyRegistry(adaptation)
config = self._makeOne(reg)
config._fix_registry()
self.assertTrue(reg.queryAdapterOrSelf(foo, IFoo) is foo)
self.assertTrue(reg.queryAdapterOrSelf(bar, IFoo) is adaptation)
def test__fix_registry_registerSelfAdapter(self):
reg = DummyRegistry()
config = self._makeOne(reg)
config._fix_registry()
reg.registerSelfAdapter('required', 'provided', name='abc')
self.assertEqual(len(reg.adapters), 1)
args, kw = reg.adapters[0]
self.assertEqual(args[0]('abc'), 'abc')
self.assertEqual(kw,
{'info': '', 'provided': 'provided',
'required': 'required', 'name': 'abc', 'event': True})
def test_setup_registry_calls_fix_registry(self):
reg = DummyRegistry()
config = self._makeOne(reg)
config.add_view = lambda *arg, **kw: False
config._add_tween = lambda *arg, **kw: False
config.setup_registry()
self.assertEqual(reg.has_listeners, True)
def test_setup_registry_registers_default_exceptionresponse_views(self):
from webob.exc import WSGIHTTPException
from pyramid.interfaces import IExceptionResponse
from pyramid.view import default_exceptionresponse_view
reg = DummyRegistry()
config = self._makeOne(reg)
views = []
config.add_view = lambda *arg, **kw: views.append((arg, kw))
config.add_default_view_predicates = lambda *arg: None
config._add_tween = lambda *arg, **kw: False
config.setup_registry()
self.assertEqual(views[0], ((default_exceptionresponse_view,),
{'context':IExceptionResponse}))
self.assertEqual(views[1], ((default_exceptionresponse_view,),
{'context':WSGIHTTPException}))
def test_setup_registry_registers_default_view_predicates(self):
reg = DummyRegistry()
config = self._makeOne(reg)
vp_called = []
config.add_view = lambda *arg, **kw: None
config.add_default_view_predicates = lambda *arg: vp_called.append(True)
config._add_tween = lambda *arg, **kw: False
config.setup_registry()
self.assertTrue(vp_called)
def test_setup_registry_registers_default_webob_iresponse_adapter(self):
from webob import Response
from pyramid.interfaces import IResponse
config = self._makeOne()
config.setup_registry()
response = Response()
self.assertTrue(
config.registry.queryAdapter(response, IResponse) is response)
def test_setup_registry_explicit_notfound_trumps_iexceptionresponse(self):
from pyramid.renderers import null_renderer
from zope.interface import implementedBy
from pyramid.interfaces import IRequest
from pyramid.httpexceptions import HTTPNotFound
from pyramid.registry import Registry
reg = Registry()
config = self._makeOne(reg, autocommit=True)
config.setup_registry() # registers IExceptionResponse default view
def myview(context, request):
return 'OK'
config.add_view(myview, context=HTTPNotFound, renderer=null_renderer)
request = self._makeRequest(config)
view = self._getViewCallable(config,
ctx_iface=implementedBy(HTTPNotFound),
request_iface=IRequest)
result = view(None, request)
self.assertEqual(result, 'OK')
def test_setup_registry_custom_settings(self):
from pyramid.registry import Registry
from pyramid.interfaces import ISettings
settings = {'reload_templates':True,
'mysetting':True}
reg = Registry()
config = self._makeOne(reg)
config.setup_registry(settings=settings)
settings = reg.getUtility(ISettings)
self.assertEqual(settings['reload_templates'], True)
self.assertEqual(settings['debug_authorization'], False)
self.assertEqual(settings['mysetting'], True)
def test_setup_registry_debug_logger_None_default(self):
from pyramid.registry import Registry
from pyramid.interfaces import IDebugLogger
reg = Registry()
config = self._makeOne(reg)
config.setup_registry()
logger = reg.getUtility(IDebugLogger)
self.assertEqual(logger.name, 'pyramid.tests.test_config')
def test_setup_registry_debug_logger_non_None(self):
from pyramid.registry import Registry
from pyramid.interfaces import IDebugLogger
logger = object()
reg = Registry()
config = self._makeOne(reg)
config.setup_registry(debug_logger=logger)
result = reg.getUtility(IDebugLogger)
self.assertEqual(logger, result)
def test_setup_registry_debug_logger_name(self):
from pyramid.registry import Registry
from pyramid.interfaces import IDebugLogger
reg = Registry()
config = self._makeOne(reg)
config.setup_registry(debug_logger='foo')
result = reg.getUtility(IDebugLogger)
self.assertEqual(result.name, 'foo')
def test_setup_registry_authentication_policy(self):
from pyramid.registry import Registry
from pyramid.interfaces import IAuthenticationPolicy
policy = object()
reg = Registry()
config = self._makeOne(reg)
config.setup_registry(authentication_policy=policy)
config.commit()
result = reg.getUtility(IAuthenticationPolicy)
self.assertEqual(policy, result)
def test_setup_registry_authentication_policy_dottedname(self):
from pyramid.registry import Registry
from pyramid.interfaces import IAuthenticationPolicy
reg = Registry()
config = self._makeOne(reg)
config.setup_registry(authentication_policy='pyramid.tests.test_config')
config.commit()
result = reg.getUtility(IAuthenticationPolicy)
import pyramid.tests.test_config
self.assertEqual(result, pyramid.tests.test_config)
def test_setup_registry_authorization_policy_dottedname(self):
from pyramid.registry import Registry
from pyramid.interfaces import IAuthorizationPolicy
reg = Registry()
config = self._makeOne(reg)
dummy = object()
config.setup_registry(authentication_policy=dummy,
authorization_policy='pyramid.tests.test_config')
config.commit()
result = reg.getUtility(IAuthorizationPolicy)
import pyramid.tests.test_config
self.assertEqual(result, pyramid.tests.test_config)
def test_setup_registry_authorization_policy_only(self):
from pyramid.registry import Registry
policy = object()
reg = Registry()
config = self._makeOne(reg)
config.setup_registry(authorization_policy=policy)
config = self.assertRaises(ConfigurationExecutionError, config.commit)
def test_setup_registry_no_default_root_factory(self):
from pyramid.registry import Registry
from pyramid.interfaces import IRootFactory
reg = Registry()
config = self._makeOne(reg)
config.setup_registry()
config.commit()
self.assertEqual(reg.queryUtility(IRootFactory), None)
def test_setup_registry_dottedname_root_factory(self):
from pyramid.registry import Registry
from pyramid.interfaces import IRootFactory
reg = Registry()
config = self._makeOne(reg)
import pyramid.tests.test_config
config.setup_registry(root_factory='pyramid.tests.test_config')
self.assertEqual(reg.queryUtility(IRootFactory), None)
config.commit()
self.assertEqual(reg.getUtility(IRootFactory),
pyramid.tests.test_config)
def test_setup_registry_locale_negotiator_dottedname(self):
from pyramid.registry import Registry
from pyramid.interfaces import ILocaleNegotiator
reg = Registry()
config = self._makeOne(reg)
import pyramid.tests.test_config
config.setup_registry(locale_negotiator='pyramid.tests.test_config')
self.assertEqual(reg.queryUtility(ILocaleNegotiator), None)
config.commit()
utility = reg.getUtility(ILocaleNegotiator)
self.assertEqual(utility, pyramid.tests.test_config)
def test_setup_registry_locale_negotiator(self):
from pyramid.registry import Registry
from pyramid.interfaces import ILocaleNegotiator
reg = Registry()
config = self._makeOne(reg)
negotiator = object()
config.setup_registry(locale_negotiator=negotiator)
self.assertEqual(reg.queryUtility(ILocaleNegotiator), None)
config.commit()
utility = reg.getUtility(ILocaleNegotiator)
self.assertEqual(utility, negotiator)
def test_setup_registry_request_factory(self):
from pyramid.registry import Registry
from pyramid.interfaces import IRequestFactory
reg = Registry()
config = self._makeOne(reg)
factory = object()
config.setup_registry(request_factory=factory)
self.assertEqual(reg.queryUtility(IRequestFactory), None)
config.commit()
utility = reg.getUtility(IRequestFactory)
self.assertEqual(utility, factory)
def test_setup_registry_request_factory_dottedname(self):
from pyramid.registry import Registry
from pyramid.interfaces import IRequestFactory
reg = Registry()
config = self._makeOne(reg)
import pyramid.tests.test_config
config.setup_registry(request_factory='pyramid.tests.test_config')
self.assertEqual(reg.queryUtility(IRequestFactory), None)
config.commit()
utility = reg.getUtility(IRequestFactory)
self.assertEqual(utility, pyramid.tests.test_config)
def test_setup_registry_renderer_globals_factory(self):
from pyramid.registry import Registry
from pyramid.interfaces import IRendererGlobalsFactory
reg = Registry()
config = self._makeOne(reg)
factory = object()
with warnings.catch_warnings():
warnings.filterwarnings('ignore')
config.setup_registry(renderer_globals_factory=factory)
self.assertEqual(reg.queryUtility(IRendererGlobalsFactory), None)
config.commit()
utility = reg.getUtility(IRendererGlobalsFactory)
self.assertEqual(utility, factory)
def test_setup_registry_renderer_globals_factory_dottedname(self):
from pyramid.registry import Registry
from pyramid.interfaces import IRendererGlobalsFactory
reg = Registry()
config = self._makeOne(reg)
import pyramid.tests.test_config
with warnings.catch_warnings():
warnings.filterwarnings('ignore')
config.setup_registry(
renderer_globals_factory='pyramid.tests.test_config')
self.assertEqual(reg.queryUtility(IRendererGlobalsFactory), None)
config.commit()
utility = reg.getUtility(IRendererGlobalsFactory)
self.assertEqual(utility, pyramid.tests.test_config)
def test_setup_registry_alternate_renderers(self):
from pyramid.registry import Registry
from pyramid.interfaces import IRendererFactory
renderer = object()
reg = Registry()
config = self._makeOne(reg)
config.setup_registry(renderers=[('yeah', renderer)])
config.commit()
self.assertEqual(reg.getUtility(IRendererFactory, 'yeah'),
renderer)
def test_setup_registry_default_permission(self):
from pyramid.registry import Registry
from pyramid.interfaces import IDefaultPermission
reg = Registry()
config = self._makeOne(reg)
config.setup_registry(default_permission='view')
config.commit()
self.assertEqual(reg.getUtility(IDefaultPermission), 'view')
def test_setup_registry_includes(self):
from pyramid.registry import Registry
reg = Registry()
config = self._makeOne(reg)
settings = {
'pyramid.includes':
"""pyramid.tests.test_config.dummy_include
pyramid.tests.test_config.dummy_include2""",
}
config.setup_registry(settings=settings)
self.assertTrue(reg.included)
self.assertTrue(reg.also_included)
def test_setup_registry_includes_spaces(self):
from pyramid.registry import Registry
reg = Registry()
config = self._makeOne(reg)
settings = {
'pyramid.includes':
"""pyramid.tests.test_config.dummy_include pyramid.tests.test_config.dummy_include2""",
}
config.setup_registry(settings=settings)
self.assertTrue(reg.included)
self.assertTrue(reg.also_included)
def test_setup_registry_tweens(self):
from pyramid.interfaces import ITweens
from pyramid.registry import Registry
reg = Registry()
config = self._makeOne(reg)
settings = {
'pyramid.tweens':
'pyramid.tests.test_config.dummy_tween_factory'
}
config.setup_registry(settings=settings)
config.commit()
tweens = config.registry.getUtility(ITweens)
self.assertEqual(
tweens.explicit,
[('pyramid.tests.test_config.dummy_tween_factory',
dummy_tween_factory)])
def test_introspector_decorator(self):
inst = self._makeOne()
default = inst.introspector
self.assertTrue(hasattr(default, 'add'))
self.assertEqual(inst.introspector, inst.registry.introspector)
introspector = object()
inst.introspector = introspector
new = inst.introspector
self.assertTrue(new is introspector)
self.assertEqual(inst.introspector, inst.registry.introspector)
del inst.introspector
default = inst.introspector
self.assertFalse(default is new)
self.assertTrue(hasattr(default, 'add'))
def test_make_wsgi_app(self):
import pyramid.config
from pyramid.router import Router
from pyramid.interfaces import IApplicationCreated
manager = DummyThreadLocalManager()
config = self._makeOne()
subscriber = self._registerEventListener(config, IApplicationCreated)
config.manager = manager
app = config.make_wsgi_app()
self.assertEqual(app.__class__, Router)
self.assertEqual(manager.pushed['registry'], config.registry)
self.assertEqual(manager.pushed['request'], None)
self.assertTrue(manager.popped)
self.assertEqual(pyramid.config.global_registries.last, app.registry)
self.assertEqual(len(subscriber), 1)
self.assertTrue(IApplicationCreated.providedBy(subscriber[0]))
pyramid.config.global_registries.empty()
def test_include_with_dotted_name(self):
from pyramid.tests import test_config
config = self._makeOne()
config.include('pyramid.tests.test_config.dummy_include')
after = config.action_state
actions = after.actions
self.assertEqual(len(actions), 1)
action = after.actions[0]
self.assertEqual(action['discriminator'], 'discrim')
self.assertEqual(action['callable'], None)
self.assertEqual(action['args'], test_config)
def test_include_with_python_callable(self):
from pyramid.tests import test_config
config = self._makeOne()
config.include(dummy_include)
after = config.action_state
actions = after.actions
self.assertEqual(len(actions), 1)
action = actions[0]
self.assertEqual(action['discriminator'], 'discrim')
self.assertEqual(action['callable'], None)
self.assertEqual(action['args'], test_config)
def test_include_with_module_defaults_to_includeme(self):
from pyramid.tests import test_config
config = self._makeOne()
config.include('pyramid.tests.test_config')
after = config.action_state
actions = after.actions
self.assertEqual(len(actions), 1)
action = actions[0]
self.assertEqual(action['discriminator'], 'discrim')
self.assertEqual(action['callable'], None)
self.assertEqual(action['args'], test_config)
def test_include_with_module_defaults_to_includeme_missing(self):
from pyramid.exceptions import ConfigurationError
config = self._makeOne()
self.assertRaises(ConfigurationError, config.include, 'pyramid.tests')
def test_include_with_route_prefix(self):
root_config = self._makeOne(autocommit=True)
def dummy_subapp(config):
self.assertEqual(config.route_prefix, 'root')
root_config.include(dummy_subapp, route_prefix='root')
def test_include_with_nested_route_prefix(self):
root_config = self._makeOne(autocommit=True, route_prefix='root')
def dummy_subapp2(config):
self.assertEqual(config.route_prefix, 'root/nested')
def dummy_subapp3(config):
self.assertEqual(config.route_prefix, 'root/nested/nested2')
config.include(dummy_subapp4)
def dummy_subapp4(config):
self.assertEqual(config.route_prefix, 'root/nested/nested2')
def dummy_subapp(config):
self.assertEqual(config.route_prefix, 'root/nested')
config.include(dummy_subapp2)
config.include(dummy_subapp3, route_prefix='nested2')
root_config.include(dummy_subapp, route_prefix='nested')
def test_include_with_missing_source_file(self):
from pyramid.exceptions import ConfigurationError
import inspect
config = self._makeOne()
class DummyInspect(object):
def getmodule(self, c):
return inspect.getmodule(c)
def getsourcefile(self, c):
return None
config.inspect = DummyInspect()
try:
config.include('pyramid.tests.test_config.dummy_include')
except ConfigurationError as e:
self.assertEqual(
e.args[0],
"No source file for module 'pyramid.tests.test_config' (.py "
"file must exist, refusing to use orphan .pyc or .pyo file).")
else: # pragma: no cover
raise AssertionError
def test_action_branching_kw_is_None(self):
config = self._makeOne(autocommit=True)
self.assertEqual(config.action('discrim'), None)
def test_action_branching_kw_is_not_None(self):
config = self._makeOne(autocommit=True)
self.assertEqual(config.action('discrim', kw={'a':1}), None)
def test_action_autocommit_with_introspectables(self):
from pyramid.util import ActionInfo
config = self._makeOne(autocommit=True)
intr = DummyIntrospectable()
config.action('discrim', introspectables=(intr,))
self.assertEqual(len(intr.registered), 1)
self.assertEqual(intr.registered[0][0], config.introspector)
self.assertEqual(intr.registered[0][1].__class__, ActionInfo)
def test_action_autocommit_with_introspectables_introspection_off(self):
config = self._makeOne(autocommit=True)
config.introspection = False
intr = DummyIntrospectable()
config.action('discrim', introspectables=(intr,))
self.assertEqual(len(intr.registered), 0)
def test_action_branching_nonautocommit_with_config_info(self):
config = self._makeOne(autocommit=False)
config.info = 'abc'
state = DummyActionState()
state.autocommit = False
config.action_state = state
config.action('discrim', kw={'a':1})
self.assertEqual(
state.actions,
[((),
{'args': (),
'callable': None,
'discriminator': 'discrim',
'includepath': (),
'info': 'abc',
'introspectables': (),
'kw': {'a': 1},
'order': 0})])
def test_action_branching_nonautocommit_without_config_info(self):
config = self._makeOne(autocommit=False)
config.info = ''
config._ainfo = ['z']
state = DummyActionState()
config.action_state = state
state.autocommit = False
config.action('discrim', kw={'a':1})
self.assertEqual(
state.actions,
[((),
{'args': (),
'callable': None,
'discriminator': 'discrim',
'includepath': (),
'info': 'z',
'introspectables': (),
'kw': {'a': 1},
'order': 0})])
def test_action_branching_nonautocommit_with_introspectables(self):
config = self._makeOne(autocommit=False)
config.info = ''
config._ainfo = []
state = DummyActionState()
config.action_state = state
state.autocommit = False
intr = DummyIntrospectable()
config.action('discrim', introspectables=(intr,))
self.assertEqual(
state.actions[0][1]['introspectables'], (intr,))
def test_action_nonautocommit_with_introspectables_introspection_off(self):
config = self._makeOne(autocommit=False)
config.info = ''
config._ainfo = []
config.introspection = False
state = DummyActionState()
config.action_state = state
state.autocommit = False
intr = DummyIntrospectable()
config.action('discrim', introspectables=(intr,))
self.assertEqual(
state.actions[0][1]['introspectables'], ())
def test_scan_integration(self):
from zope.interface import alsoProvides
from pyramid.interfaces import IRequest
from pyramid.view import render_view_to_response
import pyramid.tests.test_config.pkgs.scannable as package
config = self._makeOne(autocommit=True)
config.scan(package)
ctx = DummyContext()
req = DummyRequest()
alsoProvides(req, IRequest)
req.registry = config.registry
req.method = 'GET'
result = render_view_to_response(ctx, req, '')
self.assertEqual(result, 'grokked')
req.method = 'POST'
result = render_view_to_response(ctx, req, '')
self.assertEqual(result, 'grokked_post')
result= render_view_to_response(ctx, req, 'grokked_class')
self.assertEqual(result, 'grokked_class')
result= render_view_to_response(ctx, req, 'grokked_instance')
self.assertEqual(result, 'grokked_instance')
result= render_view_to_response(ctx, req, 'oldstyle_grokked_class')
self.assertEqual(result, 'oldstyle_grokked_class')
req.method = 'GET'
result = render_view_to_response(ctx, req, 'another')
self.assertEqual(result, 'another_grokked')
req.method = 'POST'
result = render_view_to_response(ctx, req, 'another')
self.assertEqual(result, 'another_grokked_post')
result= render_view_to_response(ctx, req, 'another_grokked_class')
self.assertEqual(result, 'another_grokked_class')
result= render_view_to_response(ctx, req, 'another_grokked_instance')
self.assertEqual(result, 'another_grokked_instance')
result= render_view_to_response(ctx, req,
'another_oldstyle_grokked_class')
self.assertEqual(result, 'another_oldstyle_grokked_class')
result = render_view_to_response(ctx, req, 'stacked1')
self.assertEqual(result, 'stacked')
result = render_view_to_response(ctx, req, 'stacked2')
self.assertEqual(result, 'stacked')
result = render_view_to_response(ctx, req, 'another_stacked1')
self.assertEqual(result, 'another_stacked')
result = render_view_to_response(ctx, req, 'another_stacked2')
self.assertEqual(result, 'another_stacked')
result = render_view_to_response(ctx, req, 'stacked_class1')
self.assertEqual(result, 'stacked_class')
result = render_view_to_response(ctx, req, 'stacked_class2')
self.assertEqual(result, 'stacked_class')
result = render_view_to_response(ctx, req, 'another_stacked_class1')
self.assertEqual(result, 'another_stacked_class')
result = render_view_to_response(ctx, req, 'another_stacked_class2')
self.assertEqual(result, 'another_stacked_class')
# NB: on Jython, a class without an __init__ apparently accepts
# any number of arguments without raising a TypeError, so the next
# assertion may fail there. We don't support Jython at the moment,
# this is just a note to a future self.
self.assertRaises(TypeError,
render_view_to_response, ctx, req, 'basemethod')
result = render_view_to_response(ctx, req, 'method1')
self.assertEqual(result, 'method1')
result = render_view_to_response(ctx, req, 'method2')
self.assertEqual(result, 'method2')
result = render_view_to_response(ctx, req, 'stacked_method1')
self.assertEqual(result, 'stacked_method')
result = render_view_to_response(ctx, req, 'stacked_method2')
self.assertEqual(result, 'stacked_method')
result = render_view_to_response(ctx, req, 'subpackage_init')
self.assertEqual(result, 'subpackage_init')
result = render_view_to_response(ctx, req, 'subpackage_notinit')
self.assertEqual(result, 'subpackage_notinit')
result = render_view_to_response(ctx, req, 'subsubpackage_init')
self.assertEqual(result, 'subsubpackage_init')
result = render_view_to_response(ctx, req, 'pod_notinit')
self.assertEqual(result, None)
def test_scan_integration_with_ignore(self):
from zope.interface import alsoProvides
from pyramid.interfaces import IRequest
from pyramid.view import render_view_to_response
import pyramid.tests.test_config.pkgs.scannable as package
config = self._makeOne(autocommit=True)
config.scan(package,
ignore='pyramid.tests.test_config.pkgs.scannable.another')
ctx = DummyContext()
req = DummyRequest()
alsoProvides(req, IRequest)
req.registry = config.registry
req.method = 'GET'
result = render_view_to_response(ctx, req, '')
self.assertEqual(result, 'grokked')
# ignored
v = render_view_to_response(ctx, req, 'another_stacked_class2')
self.assertEqual(v, None)
def test_scan_integration_dottedname_package(self):
from zope.interface import alsoProvides
from pyramid.interfaces import IRequest
from pyramid.view import render_view_to_response
config = self._makeOne(autocommit=True)
config.scan('pyramid.tests.test_config.pkgs.scannable')
ctx = DummyContext()
req = DummyRequest()
alsoProvides(req, IRequest)
req.registry = config.registry
req.method = 'GET'
result = render_view_to_response(ctx, req, '')
self.assertEqual(result, 'grokked')
def test_scan_integration_with_extra_kw(self):
config = self._makeOne(autocommit=True)
config.scan('pyramid.tests.test_config.pkgs.scanextrakw', a=1)
self.assertEqual(config.a, 1)
def test_scan_integration_with_onerror(self):
# fancy sys.path manipulation here to appease "setup.py test" which
# fails miserably when it can't import something in the package
import sys
try:
here = os.path.dirname(__file__)
path = os.path.join(here, 'path')
sys.path.append(path)
config = self._makeOne(autocommit=True)
class FooException(Exception):
pass
def onerror(name):
raise FooException
self.assertRaises(FooException, config.scan, 'scanerror',
onerror=onerror)
finally:
sys.path.remove(path)
def test_scan_integration_conflict(self):
from pyramid.tests.test_config.pkgs import selfscan
from pyramid.config import Configurator
c = Configurator()
c.scan(selfscan)
c.scan(selfscan)
try:
c.commit()
except ConfigurationConflictError as why:
def scanconflicts(e):
conflicts = e._conflicts.values()
for conflict in conflicts:
for confinst in conflict:
yield confinst.src
which = list(scanconflicts(why))
self.assertEqual(len(which), 4)
self.assertTrue("@view_config(renderer='string')" in which)
self.assertTrue("@view_config(name='two', renderer='string')" in
which)
@skip_on('py3')
def test_hook_zca(self):
from zope.component import getSiteManager
def foo():
'123'
try:
config = self._makeOne()
config.hook_zca()
config.begin()
sm = getSiteManager()
self.assertEqual(sm, config.registry)
finally:
getSiteManager.reset()
@skip_on('py3')
def test_unhook_zca(self):
from zope.component import getSiteManager
def foo():
'123'
try:
getSiteManager.sethook(foo)
config = self._makeOne()
config.unhook_zca()
sm = getSiteManager()
self.assertNotEqual(sm, '123')
finally:
getSiteManager.reset()
def test_commit_conflict_simple(self):
config = self._makeOne()
def view1(request): pass
def view2(request): pass
config.add_view(view1)
config.add_view(view2)
self.assertRaises(ConfigurationConflictError, config.commit)
def test_commit_conflict_resolved_with_include(self):
config = self._makeOne()
def view1(request): pass
def view2(request): pass
def includeme(config):
config.add_view(view2)
config.add_view(view1)
config.include(includeme)
config.commit()
registeredview = self._getViewCallable(config)
self.assertEqual(registeredview.__name__, 'view1')
def test_commit_conflict_with_two_includes(self):
config = self._makeOne()
def view1(request): pass
def view2(request): pass
def includeme1(config):
config.add_view(view1)
def includeme2(config):
config.add_view(view2)
config.include(includeme1)
config.include(includeme2)
try:
config.commit()
except ConfigurationConflictError as why:
c1, c2 = _conflictFunctions(why)
self.assertEqual(c1, 'includeme1')
self.assertEqual(c2, 'includeme2')
else: #pragma: no cover
raise AssertionError
def test_commit_conflict_resolved_with_two_includes_and_local(self):
config = self._makeOne()
def view1(request): pass
def view2(request): pass
def view3(request): pass
def includeme1(config):
config.add_view(view1)
def includeme2(config):
config.add_view(view2)
config.include(includeme1)
config.include(includeme2)
config.add_view(view3)
config.commit()
registeredview = self._getViewCallable(config)
self.assertEqual(registeredview.__name__, 'view3')
def test_autocommit_no_conflicts(self):
from pyramid.renderers import null_renderer
config = self._makeOne(autocommit=True)
def view1(request): pass
def view2(request): pass
def view3(request): pass
config.add_view(view1, renderer=null_renderer)
config.add_view(view2, renderer=null_renderer)
config.add_view(view3, renderer=null_renderer)
config.commit()
registeredview = self._getViewCallable(config)
self.assertEqual(registeredview.__name__, 'view3')
def test_conflict_set_notfound_view(self):
config = self._makeOne()
def view1(request): pass
def view2(request): pass
config.set_notfound_view(view1)
config.set_notfound_view(view2)
try:
config.commit()
except ConfigurationConflictError as why:
c1, c2 = _conflictFunctions(why)
self.assertEqual(c1, 'test_conflict_set_notfound_view')
self.assertEqual(c2, 'test_conflict_set_notfound_view')
else: # pragma: no cover
raise AssertionError
def test_conflict_set_forbidden_view(self):
config = self._makeOne()
def view1(request): pass
def view2(request): pass
config.set_forbidden_view(view1)
config.set_forbidden_view(view2)
try:
config.commit()
except ConfigurationConflictError as why:
c1, c2 = _conflictFunctions(why)
self.assertEqual(c1, 'test_conflict_set_forbidden_view')
self.assertEqual(c2, 'test_conflict_set_forbidden_view')
else: # pragma: no cover
raise AssertionError
def test___getattr__missing_when_directives_exist(self):
config = self._makeOne()
directives = {}
config.registry._directives = directives
self.assertRaises(AttributeError, config.__getattr__, 'wontexist')
def test___getattr__missing_when_directives_dont_exist(self):
config = self._makeOne()
self.assertRaises(AttributeError, config.__getattr__, 'wontexist')
def test___getattr__matches(self):
config = self._makeOne()
def foo(config): pass
directives = {'foo':(foo, True)}
config.registry._directives = directives
foo_meth = config.foo
self.assertTrue(getattr(foo_meth, im_func).__docobj__ is foo)
def test___getattr__matches_no_action_wrap(self):
config = self._makeOne()
def foo(config): pass
directives = {'foo':(foo, False)}
config.registry._directives = directives
foo_meth = config.foo
self.assertTrue(getattr(foo_meth, im_func) is foo)
class TestConfiguratorDeprecatedFeatures(unittest.TestCase):
def setUp(self):
self.warnings = warnings.catch_warnings()
self.warnings.__enter__()
warnings.filterwarnings('ignore')
def tearDown(self):
self.warnings.__exit__(None, None, None)
def _makeOne(self, *arg, **kw):
from pyramid.config import Configurator
config = Configurator(*arg, **kw)
config.registry._dont_resolve_responses = True
return config
def _getRouteRequestIface(self, config, name):
from pyramid.interfaces import IRouteRequest
iface = config.registry.getUtility(IRouteRequest, name)
return iface
def _getViewCallable(self, config, ctx_iface=None, request_iface=None,
name='', exception_view=False):
from zope.interface import Interface
from pyramid.interfaces import IView
from pyramid.interfaces import IViewClassifier
from pyramid.interfaces import IExceptionViewClassifier
if exception_view:
classifier = IExceptionViewClassifier
else:
classifier = IViewClassifier
if ctx_iface is None:
ctx_iface = Interface
return config.registry.adapters.lookup(
(classifier, request_iface, ctx_iface), IView, name=name,
default=None)
def _registerRenderer(self, config, name='.txt'):
from pyramid.interfaces import IRendererFactory
from pyramid.interfaces import ITemplateRenderer
from zope.interface import implementer
@implementer(ITemplateRenderer)
class Renderer:
def __init__(self, info):
self.__class__.info = info
def __call__(self, *arg):
return 'Hello!'
config.registry.registerUtility(Renderer, IRendererFactory, name=name)
return Renderer
def _assertRoute(self, config, name, path, num_predicates=0):
from pyramid.interfaces import IRoutesMapper
mapper = config.registry.getUtility(IRoutesMapper)
routes = mapper.get_routes()
route = routes[0]
self.assertEqual(len(routes), 1)
self.assertEqual(route.name, name)
self.assertEqual(route.path, path)
self.assertEqual(len(routes[0].predicates), num_predicates)
return route
def _makeRequest(self, config):
request = DummyRequest()
request.registry = config.registry
return request
def test_add_route_with_view(self):
from pyramid.renderers import null_renderer
config = self._makeOne(autocommit=True)
view = lambda *arg: 'OK'
config.add_route('name', 'path', view=view, view_renderer=null_renderer)
request_type = self._getRouteRequestIface(config, 'name')
wrapper = self._getViewCallable(config, None, request_type)
self.assertEqual(wrapper(None, None), 'OK')
self._assertRoute(config, 'name', 'path')
def test_add_route_with_view_context(self):
from pyramid.renderers import null_renderer
config = self._makeOne(autocommit=True)
view = lambda *arg: 'OK'
config.add_route('name', 'path', view=view, view_context=IDummy,
view_renderer=null_renderer)
request_type = self._getRouteRequestIface(config, 'name')
wrapper = self._getViewCallable(config, IDummy, request_type)
self.assertEqual(wrapper(None, None), 'OK')
self._assertRoute(config, 'name', 'path')
wrapper = self._getViewCallable(config, IOther, request_type)
self.assertEqual(wrapper, None)
def test_add_route_with_view_exception(self):
from pyramid.renderers import null_renderer
from zope.interface import implementedBy
config = self._makeOne(autocommit=True)
view = lambda *arg: 'OK'
config.add_route('name', 'path', view=view, view_context=RuntimeError,
view_renderer=null_renderer)
request_type = self._getRouteRequestIface(config, 'name')
wrapper = self._getViewCallable(
config, ctx_iface=implementedBy(RuntimeError),
request_iface=request_type, exception_view=True)
self.assertEqual(wrapper(None, None), 'OK')
self._assertRoute(config, 'name', 'path')
wrapper = self._getViewCallable(
config, ctx_iface=IOther,
request_iface=request_type, exception_view=True)
self.assertEqual(wrapper, None)
def test_add_route_with_view_for(self):
from pyramid.renderers import null_renderer
config = self._makeOne(autocommit=True)
view = lambda *arg: 'OK'
config.add_route('name', 'path', view=view, view_for=IDummy,
view_renderer=null_renderer)
request_type = self._getRouteRequestIface(config, 'name')
wrapper = self._getViewCallable(config, IDummy, request_type)
self.assertEqual(wrapper(None, None), 'OK')
self._assertRoute(config, 'name', 'path')
wrapper = self._getViewCallable(config, IOther, request_type)
self.assertEqual(wrapper, None)
def test_add_route_with_for_(self):
from pyramid.renderers import null_renderer
config = self._makeOne(autocommit=True)
view = lambda *arg: 'OK'
config.add_route('name', 'path', view=view, for_=IDummy,
view_renderer=null_renderer)
request_type = self._getRouteRequestIface(config, 'name')
wrapper = self._getViewCallable(config, IDummy, request_type)
self.assertEqual(wrapper(None, None), 'OK')
self._assertRoute(config, 'name', 'path')
wrapper = self._getViewCallable(config, IOther, request_type)
self.assertEqual(wrapper, None)
def test_add_route_with_view_renderer(self):
config = self._makeOne(autocommit=True)
self._registerRenderer(config)
view = lambda *arg: 'OK'
config.add_route('name', 'path', view=view,
view_renderer='files/minimal.txt')
request_type = self._getRouteRequestIface(config, 'name')
wrapper = self._getViewCallable(config, None, request_type)
self._assertRoute(config, 'name', 'path')
self.assertEqual(wrapper(None, None).body, b'Hello!')
def test_add_route_with_view_attr(self):
from pyramid.renderers import null_renderer
config = self._makeOne(autocommit=True)
self._registerRenderer(config)
class View(object):
def __init__(self, context, request):
pass
def alt(self):
return 'OK'
config.add_route('name', 'path', view=View, view_attr='alt',
view_renderer=null_renderer)
request_type = self._getRouteRequestIface(config, 'name')
wrapper = self._getViewCallable(config, None, request_type)
self._assertRoute(config, 'name', 'path')
request = self._makeRequest(config)
self.assertEqual(wrapper(None, request), 'OK')
def test_add_route_with_view_renderer_alias(self):
config = self._makeOne(autocommit=True)
self._registerRenderer(config)
view = lambda *arg: 'OK'
config.add_route('name', 'path', view=view,
renderer='files/minimal.txt')
request_type = self._getRouteRequestIface(config, 'name')
wrapper = self._getViewCallable(config, None, request_type)
self._assertRoute(config, 'name', 'path')
self.assertEqual(wrapper(None, None).body, b'Hello!')
def test_add_route_with_view_permission(self):
from pyramid.interfaces import IAuthenticationPolicy
from pyramid.interfaces import IAuthorizationPolicy
config = self._makeOne(autocommit=True)
policy = lambda *arg: None
config.registry.registerUtility(policy, IAuthenticationPolicy)
config.registry.registerUtility(policy, IAuthorizationPolicy)
view = lambda *arg: 'OK'
config.add_route('name', 'path', view=view, view_permission='edit')
request_type = self._getRouteRequestIface(config, 'name')
wrapper = self._getViewCallable(config, None, request_type)
self._assertRoute(config, 'name', 'path')
self.assertTrue(hasattr(wrapper, '__call_permissive__'))
def test_add_route_with_view_permission_alias(self):
from pyramid.interfaces import IAuthenticationPolicy
from pyramid.interfaces import IAuthorizationPolicy
config = self._makeOne(autocommit=True)
policy = lambda *arg: None
config.registry.registerUtility(policy, IAuthenticationPolicy)
config.registry.registerUtility(policy, IAuthorizationPolicy)
view = lambda *arg: 'OK'
config.add_route('name', 'path', view=view, permission='edit')
request_type = self._getRouteRequestIface(config, 'name')
wrapper = self._getViewCallable(config, None, request_type)
self._assertRoute(config, 'name', 'path')
self.assertTrue(hasattr(wrapper, '__call_permissive__'))
def test_conflict_route_with_view(self):
config = self._makeOne()
def view1(request): pass
def view2(request): pass
config.add_route('a', '/a', view=view1)
config.add_route('a', '/a', view=view2)
try:
config.commit()
except ConfigurationConflictError as why:
c1, c2 = _conflictFunctions(why)
self.assertEqual(c1, 'test_conflict_route_with_view')
self.assertEqual(c2, 'test_conflict_route_with_view')
else: # pragma: no cover
raise AssertionError
class TestConfigurator_add_directive(unittest.TestCase):
def setUp(self):
from pyramid.config import Configurator
self.config = Configurator()
def test_extend_with_dotted_name(self):
from pyramid.tests import test_config
config = self.config
config.add_directive(
'dummy_extend', 'pyramid.tests.test_config.dummy_extend')
self.assertTrue(hasattr(config, 'dummy_extend'))
config.dummy_extend('discrim')
after = config.action_state
action = after.actions[-1]
self.assertEqual(action['discriminator'], 'discrim')
self.assertEqual(action['callable'], None)
self.assertEqual(action['args'], test_config)
def test_add_directive_with_partial(self):
from pyramid.tests import test_config
config = self.config
config.add_directive(
'dummy_partial', 'pyramid.tests.test_config.dummy_partial')
self.assertTrue(hasattr(config, 'dummy_partial'))
config.dummy_partial()
after = config.action_state
action = after.actions[-1]
self.assertEqual(action['discriminator'], 'partial')
self.assertEqual(action['callable'], None)
self.assertEqual(action['args'], test_config)
def test_add_directive_with_custom_callable(self):
from pyramid.tests import test_config
config = self.config
config.add_directive(
'dummy_callable', 'pyramid.tests.test_config.dummy_callable')
self.assertTrue(hasattr(config, 'dummy_callable'))
config.dummy_callable('discrim')
after = config.action_state
action = after.actions[-1]
self.assertEqual(action['discriminator'], 'discrim')
self.assertEqual(action['callable'], None)
self.assertEqual(action['args'], test_config)
def test_extend_with_python_callable(self):
from pyramid.tests import test_config
config = self.config
config.add_directive(
'dummy_extend', dummy_extend)
self.assertTrue(hasattr(config, 'dummy_extend'))
config.dummy_extend('discrim')
after = config.action_state
action = after.actions[-1]
self.assertEqual(action['discriminator'], 'discrim')
self.assertEqual(action['callable'], None)
self.assertEqual(action['args'], test_config)
def test_extend_same_name_doesnt_conflict(self):
config = self.config
config.add_directive(
'dummy_extend', dummy_extend)
config.add_directive(
'dummy_extend', dummy_extend2)
self.assertTrue(hasattr(config, 'dummy_extend'))
config.dummy_extend('discrim')
after = config.action_state
action = after.actions[-1]
self.assertEqual(action['discriminator'], 'discrim')
self.assertEqual(action['callable'], None)
self.assertEqual(action['args'], config.registry)
def test_extend_action_method_successful(self):
config = self.config
config.add_directive(
'dummy_extend', dummy_extend)
config.dummy_extend('discrim')
config.dummy_extend('discrim')
self.assertRaises(ConfigurationConflictError, config.commit)
def test_directive_persists_across_configurator_creations(self):
config = self.config
config.add_directive('dummy_extend', dummy_extend)
config2 = config.with_package('pyramid.tests')
config2.dummy_extend('discrim')
after = config2.action_state
actions = after.actions
self.assertEqual(len(actions), 1)
action = actions[0]
self.assertEqual(action['discriminator'], 'discrim')
self.assertEqual(action['callable'], None)
self.assertEqual(action['args'], config2.package)
class TestActionState(unittest.TestCase):
def _makeOne(self):
from pyramid.config import ActionState
return ActionState()
def test_it(self):
c = self._makeOne()
self.assertEqual(c.actions, [])
def test_action_simple(self):
from pyramid.tests.test_config import dummyfactory as f
c = self._makeOne()
c.actions = []
c.action(1, f, (1,), {'x':1})
self.assertEqual(
c.actions,
[{'args': (1,),
'callable': f,
'discriminator': 1,
'includepath': (),
'info': None,
'introspectables': (),
'kw': {'x': 1},
'order': 0}])
c.action(None)
self.assertEqual(
c.actions,
[{'args': (1,),
'callable': f,
'discriminator': 1,
'includepath': (),
'info': None,
'introspectables': (),
'kw': {'x': 1},
'order': 0},
{'args': (),
'callable': None,
'discriminator': None,
'includepath': (),
'info': None,
'introspectables': (),
'kw': {},
'order': 0},])
def test_action_with_includepath(self):
c = self._makeOne()
c.actions = []
c.action(None, includepath=('abc',))
self.assertEqual(
c.actions,
[{'args': (),
'callable': None,
'discriminator': None,
'includepath': ('abc',),
'info': None,
'introspectables': (),
'kw': {},
'order': 0}])
def test_action_with_info(self):
c = self._makeOne()
c.action(None, info='abc')
self.assertEqual(
c.actions,
[{'args': (),
'callable': None,
'discriminator': None,
'includepath': (),
'info': 'abc',
'introspectables': (),
'kw': {},
'order': 0}])
def test_action_with_includepath_and_info(self):
c = self._makeOne()
c.action(None, includepath=('spec',), info='bleh')
self.assertEqual(
c.actions,
[{'args': (),
'callable': None,
'discriminator': None,
'includepath': ('spec',),
'info': 'bleh',
'introspectables': (),
'kw': {},
'order': 0}])
def test_action_with_order(self):
c = self._makeOne()
c.actions = []
c.action(None, order=99999)
self.assertEqual(
c.actions,
[{'args': (),
'callable': None,
'discriminator': None,
'includepath': (),
'info': None,
'introspectables': (),
'kw': {},
'order': 99999}])
def test_action_with_introspectables(self):
c = self._makeOne()
c.actions = []
intr = DummyIntrospectable()
c.action(None, introspectables=(intr,))
self.assertEqual(
c.actions,
[{'args': (),
'callable': None,
'discriminator': None,
'includepath': (),
'info': None,
'introspectables': (intr,),
'kw': {},
'order': 0}])
def test_processSpec(self):
c = self._makeOne()
self.assertTrue(c.processSpec('spec'))
self.assertFalse(c.processSpec('spec'))
def test_execute_actions_tuples(self):
output = []
def f(*a, **k):
output.append((a, k))
c = self._makeOne()
c.actions = [
(1, f, (1,)),
(1, f, (11,), {}, ('x', )),
(2, f, (2,)),
(None, None),
]
c.execute_actions()
self.assertEqual(output, [((1,), {}), ((2,), {})])
def test_execute_actions_dicts(self):
output = []
def f(*a, **k):
output.append((a, k))
c = self._makeOne()
c.actions = [
{'discriminator':1, 'callable':f, 'args':(1,), 'kw':{},
'order':0, 'includepath':(), 'info':None,
'introspectables':()},
{'discriminator':1, 'callable':f, 'args':(11,), 'kw':{},
'includepath':('x',), 'order': 0, 'info':None,
'introspectables':()},
{'discriminator':2, 'callable':f, 'args':(2,), 'kw':{},
'order':0, 'includepath':(), 'info':None,
'introspectables':()},
{'discriminator':None, 'callable':None, 'args':(), 'kw':{},
'order':0, 'includepath':(), 'info':None,
'introspectables':()},
]
c.execute_actions()
self.assertEqual(output, [((1,), {}), ((2,), {})])
def test_execute_actions_with_introspectables(self):
output = []
def f(*a, **k):
output.append((a, k))
c = self._makeOne()
intr = DummyIntrospectable()
c.actions = [
{'discriminator':1, 'callable':f, 'args':(1,), 'kw':{},
'order':0, 'includepath':(), 'info':None,
'introspectables':(intr,)},
]
introspector = object()
c.execute_actions(introspector=introspector)
self.assertEqual(output, [((1,), {})])
self.assertEqual(intr.registered, [(introspector, None)])
def test_execute_actions_with_introspectable_no_callable(self):
c = self._makeOne()
intr = DummyIntrospectable()
c.actions = [
{'discriminator':1, 'callable':None, 'args':(1,), 'kw':{},
'order':0, 'includepath':(), 'info':None,
'introspectables':(intr,)},
]
introspector = object()
c.execute_actions(introspector=introspector)
self.assertEqual(intr.registered, [(introspector, None)])
def test_execute_actions_error(self):
output = []
def f(*a, **k):
output.append(('f', a, k))
def bad():
raise NotImplementedError
c = self._makeOne()
c.actions = [
(1, f, (1,)),
(1, f, (11,), {}, ('x', )),
(2, f, (2,)),
(3, bad, (), {}, (), 'oops')
]
self.assertRaises(ConfigurationExecutionError, c.execute_actions)
self.assertEqual(output, [('f', (1,), {}), ('f', (2,), {})])
class Test_resolveConflicts(unittest.TestCase):
def _callFUT(self, actions):
from pyramid.config import resolveConflicts
return resolveConflicts(actions)
def test_it_success_tuples(self):
from pyramid.tests.test_config import dummyfactory as f
result = self._callFUT([
(None, f),
(1, f, (1,), {}, (), 'first'),
(1, f, (2,), {}, ('x',), 'second'),
(1, f, (3,), {}, ('y',), 'third'),
(4, f, (4,), {}, ('y',), 'should be last', 99999),
(3, f, (3,), {}, ('y',)),
(None, f, (5,), {}, ('y',)),
])
result = list(result)
self.assertEqual(
result,
[{'info': None,
'args': (),
'callable': f,
'introspectables': (),
'kw': {},
'discriminator': None,
'includepath': (),
'order': 0},
{'info': 'first',
'args': (1,),
'callable': f,
'introspectables': (),
'kw': {},
'discriminator': 1,
'includepath': (),
'order': 0},
{'info': None,
'args': (3,),
'callable': f,
'introspectables': (),
'kw': {},
'discriminator': 3,
'includepath': ('y',),
'order': 0},
{'info': None,
'args': (5,),
'callable': f,
'introspectables': (),
'kw': {},
'discriminator': None,
'includepath': ('y',),
'order': 0},
{'info': 'should be last',
'args': (4,),
'callable': f,
'introspectables': (),
'kw': {},
'discriminator': 4,
'includepath': ('y',),
'order': 99999}
]
)
def test_it_success_dicts(self):
from pyramid.tests.test_config import dummyfactory as f
from pyramid.config import expand_action
result = self._callFUT([
expand_action(None, f),
expand_action(1, f, (1,), {}, (), 'first'),
expand_action(1, f, (2,), {}, ('x',), 'second'),
expand_action(1, f, (3,), {}, ('y',), 'third'),
expand_action(4, f, (4,), {}, ('y',), 'should be last', 99999),
expand_action(3, f, (3,), {}, ('y',)),
expand_action(None, f, (5,), {}, ('y',)),
])
result = list(result)
self.assertEqual(
result,
[{'info': None,
'args': (),
'callable': f,
'introspectables': (),
'kw': {},
'discriminator': None,
'includepath': (),
'order': 0},
{'info': 'first',
'args': (1,),
'callable': f,
'introspectables': (),
'kw': {},
'discriminator': 1,
'includepath': (),
'order': 0},
{'info': None,
'args': (3,),
'callable': f,
'introspectables': (),
'kw': {},
'discriminator': 3,
'includepath': ('y',),
'order': 0},
{'info': None,
'args': (5,),
'callable': f,
'introspectables': (),
'kw': {},
'discriminator': None,
'includepath': ('y',),
'order': 0},
{'info': 'should be last',
'args': (4,),
'callable': f,
'introspectables': (),
'kw': {},
'discriminator': 4,
'includepath': ('y',),
'order': 99999}
]
)
def test_it_conflict(self):
from pyramid.tests.test_config import dummyfactory as f
result = self._callFUT([
(None, f),
(1, f, (2,), {}, ('x',), 'eek'), # will conflict
(1, f, (3,), {}, ('y',), 'ack'), # will conflict
(4, f, (4,), {}, ('y',)),
(3, f, (3,), {}, ('y',)),
(None, f, (5,), {}, ('y',)),
])
self.assertRaises(ConfigurationConflictError, list, result)
def test_it_with_actions_grouped_by_order(self):
from pyramid.tests.test_config import dummyfactory as f
from pyramid.config import expand_action
result = self._callFUT([
expand_action(None, f), # X
expand_action(1, f, (1,), {}, (), 'third', 10), # X
expand_action(1, f, (2,), {}, ('x',), 'fourth', 10),
expand_action(1, f, (3,), {}, ('y',), 'fifth', 10),
expand_action(2, f, (1,), {}, (), 'sixth', 10), # X
expand_action(3, f, (1,), {}, (), 'seventh', 10), # X
expand_action(5, f, (4,), {}, ('y',), 'eighth', 99999), # X
expand_action(4, f, (3,), {}, (), 'first', 5), # X
expand_action(4, f, (5,), {}, ('y',), 'second', 5),
])
result = list(result)
self.assertEqual(len(result), 6)
# resolved actions should be grouped by (order, i)
self.assertEqual(
result,
[{'info': None,
'args': (),
'callable': f,
'introspectables': (),
'kw': {},
'discriminator': None,
'includepath': (),
'order': 0},
{'info': 'first',
'args': (3,),
'callable': f,
'introspectables': (),
'kw': {},
'discriminator': 4,
'includepath': (),
'order': 5},
{'info': 'third',
'args': (1,),
'callable': f,
'introspectables': (),
'kw': {},
'discriminator': 1,
'includepath': (),
'order': 10},
{'info': 'sixth',
'args': (1,),
'callable': f,
'introspectables': (),
'kw': {},
'discriminator': 2,
'includepath': (),
'order': 10},
{'info': 'seventh',
'args': (1,),
'callable': f,
'introspectables': (),
'kw': {},
'discriminator': 3,
'includepath': (),
'order': 10},
{'info': 'eighth',
'args': (4,),
'callable': f,
'introspectables': (),
'kw': {},
'discriminator': 5,
'includepath': ('y',),
'order': 99999}
]
)
class TestGlobalRegistriesIntegration(unittest.TestCase):
def setUp(self):
from pyramid.config import global_registries
global_registries.empty()
tearDown = setUp
def _makeConfigurator(self, *arg, **kw):
from pyramid.config import Configurator
config = Configurator(*arg, **kw)
return config
def test_global_registries_empty(self):
from pyramid.config import global_registries
self.assertEqual(global_registries.last, None)
def test_global_registries(self):
from pyramid.config import global_registries
config1 = self._makeConfigurator()
config1.make_wsgi_app()
self.assertEqual(global_registries.last, config1.registry)
config2 = self._makeConfigurator()
config2.make_wsgi_app()
self.assertEqual(global_registries.last, config2.registry)
self.assertEqual(list(global_registries),
[config1.registry, config2.registry])
global_registries.remove(config2.registry)
self.assertEqual(global_registries.last, config1.registry)
class DummyRequest:
subpath = ()
matchdict = None
def __init__(self, environ=None):
if environ is None:
environ = {}
self.environ = environ
self.params = {}
self.cookies = {}
class DummyResponse:
status = '200 OK'
headerlist = ()
app_iter = ()
body = ''
class DummyThreadLocalManager(object):
pushed = None
popped = False
def push(self, d):
self.pushed = d
def pop(self):
self.popped = True
from zope.interface import implementer
@implementer(IDummy)
class DummyEvent:
pass
class DummyRegistry(object):
def __init__(self, adaptation=None, util=None):
self.utilities = []
self.adapters = []
self.adaptation = adaptation
self.util = util
def subscribers(self, events, name):
self.events = events
return events
def registerUtility(self, *arg, **kw):
self.utilities.append((arg, kw))
def registerAdapter(self, *arg, **kw):
self.adapters.append((arg, kw))
def queryAdapter(self, *arg, **kw):
return self.adaptation
def queryUtility(self, *arg, **kw):
return self.util
from pyramid.interfaces import IResponse
@implementer(IResponse)
class DummyResponse(object):
pass
from zope.interface import Interface
class IOther(Interface):
pass
def _conflictFunctions(e):
conflicts = e._conflicts.values()
for conflict in conflicts:
for confinst in conflict:
yield confinst.function
class DummyActionState(object):
autocommit = False
info = ''
def __init__(self):
self.actions = []
def action(self, *arg, **kw):
self.actions.append((arg, kw))
class DummyIntrospectable(object):
def __init__(self):
self.registered = []
def register(self, introspector, action_info):
self.registered.append((introspector, action_info))
|