From 0d6d707eaa83fe90edfbbcdf76c62c807536f21d Mon Sep 17 00:00:00 2001 From: Jonas Baumann Date: Fri, 6 Sep 2024 22:16:33 +0200 Subject: [PATCH] api: add empty import endpoint --- api/app/server.py | 7 +++++++ api/poetry.lock | 16 +++++++++++++++- api/pyproject.toml | 1 + api/tests/test_http.py | 12 ++++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/api/app/server.py b/api/app/server.py index 9f9d5d2..2914ebd 100644 --- a/api/app/server.py +++ b/api/app/server.py @@ -1,5 +1,7 @@ from fastapi import FastAPI +from fastapi import File from fastapi import Query +from fastapi import UploadFile from fastapi.responses import RedirectResponse from app.elastic import Elastic @@ -30,3 +32,8 @@ async def health(): async def photos(longitude: float = Query(...), latitude: float = Query(...), radius: float = Query(...)): """The photos endpoint queries the database for fotos in a specific radious of a location.""" return Elastic().search_documents(longitude=longitude, latitude=latitude, radius=f"{radius}m") + + +@app.post("/api/import") +async def import_data(file: UploadFile = File(...)): + return file.filename diff --git a/api/poetry.lock b/api/poetry.lock index aa0f4c7..604259e 100644 --- a/api/poetry.lock +++ b/api/poetry.lock @@ -604,6 +604,20 @@ files = [ [package.extras] cli = ["click (>=5.0)"] +[[package]] +name = "python-multipart" +version = "0.0.9" +description = "A streaming multipart parser for Python" +optional = false +python-versions = ">=3.8" +files = [ + {file = "python_multipart-0.0.9-py3-none-any.whl", hash = "sha256:97ca7b8ea7b05f977dc3849c3ba99d51689822fab725c3703af7c866a0c2b215"}, + {file = "python_multipart-0.0.9.tar.gz", hash = "sha256:03f54688c663f1b7977105f021043b0793151e4cb1c1a9d4a11fc13d622c4026"}, +] + +[package.extras] +dev = ["atomicwrites (==1.4.1)", "attrs (==23.2.0)", "coverage (==7.4.1)", "hatch", "invoke (==2.2.0)", "more-itertools (==10.2.0)", "pbr (==6.0.0)", "pluggy (==1.4.0)", "py (==1.11.0)", "pytest (==8.0.0)", "pytest-cov (==4.1.0)", "pytest-timeout (==2.2.0)", "pyyaml (==6.0.1)", "ruff (==0.2.1)"] + [[package]] name = "pyyaml" version = "6.0.2" @@ -995,4 +1009,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.12" -content-hash = "85156cfe27c35b68a4cf0a92b10911248670d8d36b0e21637d41bd97d33f7231" +content-hash = "53d72e2e1ee54f1c5fd69fcb4de30f2f7a0eaf3a1ea1f39d58c76d461b8217b4" diff --git a/api/pyproject.toml b/api/pyproject.toml index cc791d7..a6ae8af 100644 --- a/api/pyproject.toml +++ b/api/pyproject.toml @@ -9,6 +9,7 @@ fastapi = "^0.113.0" uvicorn = {extras = ["standard"], version = "^0.30.6"} pydantic-settings = "^2.4.0" elasticsearch = "^8.15.0" +python-multipart = "^0.0.9" [tool.poetry.group.test.dependencies] pytest = "^8.3.1" diff --git a/api/tests/test_http.py b/api/tests/test_http.py index 729def5..1f03995 100644 --- a/api/tests/test_http.py +++ b/api/tests/test_http.py @@ -1,3 +1,6 @@ +from pathlib import Path +from tempfile import NamedTemporaryFile + from tests.case import TestCase @@ -53,3 +56,12 @@ def test_photos_querying(self): ) self.assertEqual(response.status_code, 200) self.assert_json_equal([seeblick], response.json()) + + def test_data_import(self): + with NamedTemporaryFile(suffix=".csv") as fio: + fio.write(b"title") + fio.flush() + fio.seek(0) + response = self.client.post("/api/import/", files={"file": (Path(fio.name).name, fio, "text/csv")}) + self.assertEqual(200, response.status_code, response.content) + self.assertEqual(Path(fio.name).name, response.json())