init
This commit is contained in:
parent
175f52dc0c
commit
d7bb7ee7c1
2
.gitignore
vendored
2
.gitignore
vendored
@ -158,5 +158,5 @@ cython_debug/
|
||||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||
#.idea/
|
||||
.idea/
|
||||
|
||||
|
@ -1,3 +1,9 @@
|
||||
# falcon-example
|
||||
|
||||
学习 Python 的 Web 框架 Falcon
|
||||
学习 Python 的 Web 框架 Falcon
|
||||
|
||||
## 安装依赖
|
||||
|
||||
```
|
||||
python3 -m pip install -r requirements.txt
|
||||
```
|
0
app/__init__.py
Normal file
0
app/__init__.py
Normal file
7
app/app.py
Normal file
7
app/app.py
Normal file
@ -0,0 +1,7 @@
|
||||
import falcon
|
||||
|
||||
from .images import Resource
|
||||
|
||||
app = application = falcon.App()
|
||||
|
||||
app.add_route('/images', Resource())
|
18
app/images.py
Normal file
18
app/images.py
Normal file
@ -0,0 +1,18 @@
|
||||
import falcon
|
||||
import msgpack
|
||||
|
||||
|
||||
class Resource:
|
||||
|
||||
def on_get(self, req, resp):
|
||||
doc = {
|
||||
'images': [
|
||||
{
|
||||
'href': '/images/1eaf6ef1-7f2d-4ecc-a8d5-6e8adba7cc0e.png',
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
resp.data = msgpack.packb(doc, use_bin_type=True)
|
||||
resp.content_type = falcon.MEDIA_MSGPACK
|
||||
resp.status = falcon.HTTP_200
|
7
requirements.txt
Normal file
7
requirements.txt
Normal file
@ -0,0 +1,7 @@
|
||||
falcon
|
||||
requests
|
||||
gunicorn
|
||||
httpie
|
||||
orjson==3.9.2
|
||||
msgpack-python==0.5.6
|
||||
pytest==7.4.0
|
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
27
tests/test_app.py
Normal file
27
tests/test_app.py
Normal file
@ -0,0 +1,27 @@
|
||||
import falcon
|
||||
from falcon import testing
|
||||
import msgpack
|
||||
import pytest
|
||||
|
||||
from app.app import app
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def client():
|
||||
return testing.TestClient(app)
|
||||
|
||||
|
||||
def test_list_images(client):
|
||||
doc = {
|
||||
'images': [
|
||||
{
|
||||
'href': '/images/1eaf6ef1-7f2d-4ecc-a8d5-6e8adba7cc0e.png',
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
response = client.simulate_get('/images')
|
||||
result_doc = msgpack.unpackb(response.content, raw=False)
|
||||
|
||||
assert result_doc == doc
|
||||
assert response.status == falcon.HTTP_OK
|
Loading…
Reference in New Issue
Block a user