リビジョン | e11098cadf7e846bfd69c07568e1cd0a7f4eccb3 (tree) |
---|---|
日時 | 2019-08-26 23:04:33 |
作者 | ![]() |
コミッター | H. Turgut Uyar |
Add web app skeleton
@@ -0,0 +1,7 @@ | ||
1 | +:orphan: | |
2 | + | |
3 | +:mod:`humphrey.endpoints` | |
4 | +========================= | |
5 | + | |
6 | +.. automodule:: humphrey.endpoints | |
7 | + :members: |
@@ -0,0 +1,7 @@ | ||
1 | +:orphan: | |
2 | + | |
3 | +:mod:`humphrey.server` | |
4 | +====================== | |
5 | + | |
6 | +.. automodule:: humphrey.server | |
7 | + :members: |
@@ -0,0 +1,27 @@ | ||
1 | +# Copyright (c) 2019 H. Turgut Uyar <uyar@tekir.org> | |
2 | +# | |
3 | +# This file is part of Humphrey. | |
4 | +# | |
5 | +# Humphrey is free software: you can redistribute it and/or modify | |
6 | +# it under the terms of the GNU General Public License as published by | |
7 | +# the Free Software Foundation, either version 3 of the License, or | |
8 | +# (at your option) any later version. | |
9 | +# | |
10 | +# Humphrey is distributed in the hope that it will be useful, | |
11 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | +# GNU General Public License for more details. | |
14 | +# | |
15 | +# You should have received a copy of the GNU General Public License | |
16 | +# along with Humphrey. If not, see <http://www.gnu.org/licenses/>. | |
17 | + | |
18 | +"""Handlers for incoming requests.""" | |
19 | + | |
20 | + | |
21 | +def root(): | |
22 | + """Get the context for the root route. | |
23 | + | |
24 | + :sig: () -> Dict | |
25 | + :return: Root context. | |
26 | + """ | |
27 | + return {} |
@@ -0,0 +1,5 @@ | ||
1 | +# THIS FILE IS AUTOMATICALLY GENERATED, DO NOT EDIT MANUALLY. | |
2 | + | |
3 | +from typing import Dict | |
4 | + | |
5 | +def root() -> Dict: ... |
@@ -0,0 +1,42 @@ | ||
1 | +# Copyright (c) 2019 H. Turgut Uyar <uyar@tekir.org> | |
2 | +# | |
3 | +# This file is part of Humphrey. | |
4 | +# | |
5 | +# Humphrey is free software: you can redistribute it and/or modify | |
6 | +# it under the terms of the GNU General Public License as published by | |
7 | +# the Free Software Foundation, either version 3 of the License, or | |
8 | +# (at your option) any later version. | |
9 | +# | |
10 | +# Humphrey is distributed in the hope that it will be useful, | |
11 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | +# GNU General Public License for more details. | |
14 | +# | |
15 | +# You should have received a copy of the GNU General Public License | |
16 | +# along with Humphrey. If not, see <http://www.gnu.org/licenses/>. | |
17 | + | |
18 | +"""Web server components.""" | |
19 | + | |
20 | +from clastic import Application | |
21 | +from clastic.render.chameleon_templates import ChameleonRenderFactory | |
22 | +from pathstring import Path | |
23 | + | |
24 | +from . import endpoints | |
25 | + | |
26 | + | |
27 | +TEMPLATES_PATH = Path(__file__).with_name("templates") # sig: str | |
28 | + | |
29 | + | |
30 | +def create_app(): | |
31 | + """Create a new application. | |
32 | + | |
33 | + :sig: () -> Application | |
34 | + :return: Created application. | |
35 | + """ | |
36 | + ui_routes = [("/", endpoints.root, "index.pt")] | |
37 | + ui_render_factory = ChameleonRenderFactory(TEMPLATES_PATH) | |
38 | + ui_app = Application(ui_routes, render_factory=ui_render_factory) | |
39 | + | |
40 | + routes = [("/", ui_app)] | |
41 | + app = Application(routes) | |
42 | + return app |
@@ -0,0 +1,7 @@ | ||
1 | +# THIS FILE IS AUTOMATICALLY GENERATED, DO NOT EDIT MANUALLY. | |
2 | + | |
3 | +from clastic import Application | |
4 | + | |
5 | +TEMPLATES_PATH = ... # type: str | |
6 | + | |
7 | +def create_app() -> Application: ... |
@@ -349,6 +349,14 @@ | ||
349 | 349 | six = "*" |
350 | 350 | |
351 | 351 | [[package]] |
352 | +category = "main" | |
353 | +description = "String with path operations." | |
354 | +name = "pathstring" | |
355 | +optional = false | |
356 | +python-versions = ">=3.5,<4.0" | |
357 | +version = "1.0.0" | |
358 | + | |
359 | +[[package]] | |
352 | 360 | category = "dev" |
353 | 361 | description = "plugin and hook calling mechanisms for python" |
354 | 362 | name = "pluggy" |
@@ -731,7 +739,7 @@ | ||
731 | 739 | testing = ["pathlib2", "contextlib2", "unittest2"] |
732 | 740 | |
733 | 741 | [metadata] |
734 | -content-hash = "8671cd09879c93e0db6b5536502a9b41e793877f08e75e2de20b21b3c9d29dd9" | |
742 | +content-hash = "c07799bdb82fd3ad0b1945cad8bb3347d349336709379397ba1687d7ba991314" | |
735 | 743 | python-versions = "^3.5" |
736 | 744 | |
737 | 745 | [metadata.hashes] |
@@ -767,6 +775,7 @@ | ||
767 | 775 | more-itertools = ["409cd48d4db7052af495b09dec721011634af3753ae1ef92d2b32f73a745f832", "92b8c4b06dac4f0611c0729b2f2ede52b2e1bac1ab48f089c7ddc12e26bb60c4"] |
768 | 776 | packaging = ["a7ac867b97fdc07ee80a8058fe4435ccd274ecc3b0ed61d852d7d53055528cf9", "c491ca87294da7cc01902edbe30a5bc6c4c28172b5138ab4e4aa1b9d7bfaeafe"] |
769 | 777 | pathlib2 = ["2156525d6576d21c4dcaddfa427fae887ef89a7a9de5cbfe0728b3aafa78427e", "446014523bb9be5c28128c4d2a10ad6bb60769e78bd85658fe44a450674e0ef8"] |
778 | +pathstring = ["8a89d029d8ccffb4a0c27d393ddae688ba2a5e88a1d5207c02f9902654c7e0d2", "98173829639fcb239ca4c2cc8078854a92c30c57d9307e0ad60fabebc689e11e"] | |
770 | 779 | pluggy = ["0825a152ac059776623854c1543d65a4ad408eb3d33ee114dff91e57ec6ae6fc", "b9817417e95936bf75d85d3f8767f7df6cdde751fc40aed3bb3074cbcb77757c"] |
771 | 780 | py = ["64f65755aee5b381cea27766a3a147c3f15b9b6b9ac88676de66ba2ae36793fa", "dc639b046a6e2cff5bbe40194ad65936d6ba360b52b3c3fe1d08a82dd50b5e53"] |
772 | 781 | pycodestyle = ["95a2219d12372f05704562a14ec30bc76b05a5b297b21a5dfe3f6fac3491ae56", "e40a936c9a450ad81df37f549d676d127b1b66000a6c500caa2b085bc0ca976c"] |
@@ -37,6 +37,7 @@ | ||
37 | 37 | python = "^3.5" |
38 | 38 | clastic = {git = "https://github.com/mahmoud/clastic.git"} |
39 | 39 | chameleon = "^3.6.2" |
40 | +pathstring = "^1.0.0" | |
40 | 41 | |
41 | 42 | [tool.poetry.dev-dependencies] |
42 | 43 | pytest = "^5.1.1" |
@@ -5,5 +5,6 @@ | ||
5 | 5 | line_length = 96 |
6 | 6 | lines_after_imports = 2 |
7 | 7 | known_first_party = humphrey |
8 | -known_test = pytest | |
8 | +known_third_party = clastic | |
9 | +known_test = pytest,webtest | |
9 | 10 | sections = TEST,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER |
@@ -0,0 +1,11 @@ | ||
1 | +from pytest import fixture | |
2 | +from webtest import TestApp | |
3 | + | |
4 | +from humphrey.server import create_app | |
5 | + | |
6 | + | |
7 | +@fixture(scope="session") | |
8 | +def humphrey(): | |
9 | + """A Humphrey application in a test environment.""" | |
10 | + app = create_app() | |
11 | + yield TestApp(app) |
@@ -0,0 +1,5 @@ | ||
1 | +from humphrey import endpoints | |
2 | + | |
3 | + | |
4 | +def test_root_context_should_be_empty(): | |
5 | + assert endpoints.root() == {} |
@@ -0,0 +1,3 @@ | ||
1 | +def test_response_should_be_html(humphrey): | |
2 | + response = humphrey.get("/") | |
3 | + assert response.content_type == "text/html" |