diff --git a/requirements.txt b/requirements.txt index 34fc9cb..cbe73e9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +requests==2.26.0 fastapi==0.88.0 pytest==7.1.3 pytest-asyncio==0.20.3 diff --git a/src/dtos/ISayHelloDto.py b/src/dtos/ISayHelloDto.py deleted file mode 100644 index f81f0aa..0000000 --- a/src/dtos/ISayHelloDto.py +++ /dev/null @@ -1,4 +0,0 @@ -from pydantic import BaseModel - -class ISayHelloDto(BaseModel): - message: str \ No newline at end of file diff --git a/src/index.py b/src/index.py index 246f9fb..a6f6a34 100644 --- a/src/index.py +++ b/src/index.py @@ -1,20 +1,17 @@ +import requests from fastapi import FastAPI - -from src.dtos.ISayHelloDto import ISayHelloDto +from fastapi.responses import RedirectResponse app = FastAPI() @app.get("/") async def root(): - return {"message": "Hello World"} - - -@app.get("/hello/{name}") -async def say_hello(name: str): - return {"message": f"Hello {name}"} + return "Hello World!" -@app.post("/hello") -async def hello_message(dto: ISayHelloDto): - return {"message": f"Hello {dto.message}"} +@app.get("/bing/daily") +async def bing(): + response = requests.get("https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1") + image_url = "https://www.bing.com" + response.json()["images"][0]["url"] + return RedirectResponse(url=image_url) \ No newline at end of file diff --git a/test_index.http b/test_index.http deleted file mode 100644 index 9053072..0000000 --- a/test_index.http +++ /dev/null @@ -1,20 +0,0 @@ -# Test your FastAPI endpoints - -GET http://127.0.0.1:8000/ -Accept: application/json - -### - -GET http://127.0.0.1:8000/hello/User -Accept: application/json - -### - -POST /hello HTTP/1.1 -Host: 127.0.0.1:8000 -Content-Type: application/json -Content-Length: 28 - -{ - "message": "Fulano!" -} \ No newline at end of file diff --git a/test_index.py b/test_index.py deleted file mode 100644 index 99258ad..0000000 --- a/test_index.py +++ /dev/null @@ -1,23 +0,0 @@ -import pytest - -from src.dtos.ISayHelloDto import ISayHelloDto -from src.index import root, say_hello, hello_message - - -@pytest.mark.asyncio -async def test_root(): - result = await root() - assert result == {'message': 'Hello World'} - - -@pytest.mark.asyncio -async def test_say_hello(): - result = await say_hello("John") - assert result == {'message': 'Hello John'} - - -@pytest.mark.asyncio -async def test_hello_message(): - dto = ISayHelloDto(message="Alice") - result = await hello_message(dto) - assert result == {'message': 'Hello Alice'}