Skip to content
This repository has been archived by the owner on Dec 25, 2022. It is now read-only.

Commit

Permalink
Merge pull request #133 from tubone24/create_sqllite
Browse files Browse the repository at this point in the history
add test
  • Loading branch information
tubone24 committed Jul 28, 2019
2 parents ad69f11 + 9afeae4 commit c2f5ad9
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 2 deletions.
19 changes: 18 additions & 1 deletion doc_src/_static/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ components:
version:
type: string
type: object
ListUploadFiles:
properties:
fileList:
items:
type: object
type: array
type: object
UploadIdResp:
properties:
release_date:
Expand Down Expand Up @@ -70,7 +77,7 @@ info:
name: MIT
url: https://opensource.org/licenses/MIT
title: Ebook-homebrew
version: 2.0.3
version: 2.0.7
openapi: 3.0.2
paths:
/status:
Expand All @@ -83,6 +90,16 @@ paths:
schema:
$ref: '#/components/schemas/HealthCheck'
description: OK
/data/upload/list:
get:
description: Get file list
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/ListUploadFiles'
description: OK
/data/upload:
post:
requestBody:
Expand Down
7 changes: 7 additions & 0 deletions ebook_homebrew/models/rest_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ def __init__(self, status, version):
self.version = version


class ListUploadFiles:
"""ListUploadFiles Model"""

def __init__(self, file_list):
self.fileList = file_list


class UploadModel:
"""Upload_id Model"""

Expand Down
33 changes: 32 additions & 1 deletion ebook_homebrew/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@

from .convert import Image2PDF
from .utils.logging import get_logger
from .models.rest_models import UploadModel, ErrorModel, FileNotFoundModel, StatusModel
from .models.rest_models import (
UploadModel,
ErrorModel,
FileNotFoundModel,
StatusModel,
ListUploadFiles,
)
from .rdb import UploadedFile
from .__init__ import __version__

Expand Down Expand Up @@ -51,6 +57,11 @@ class HealthCheckSchema(Schema):
version = fields.Str()


@api.schema("ListUploadFiles")
class ListUploadFilesSchema(Schema):
fileList = fields.List(fields.Dict(fields.Str()))


@api.schema("UploadImagesReq")
class UploadImagesReqSchema(Schema):
contentType = fields.Str(required=True)
Expand Down Expand Up @@ -107,6 +118,26 @@ def status(_, resp):
resp.media = HealthCheckSchema().dump(StatusModel("ok", __version__)).data


@api.route("/data/upload/list")
def list_upload_files(_, resp):
"""Responce File List.
---
get:
description: Get file list
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/ListUploadFiles"
"""
_logger.debug("List File")
upload_file = UploadedFile()
file_list = upload_file.get_all_uploaded_file()
resp.media = ListUploadFilesSchema().dump(ListUploadFiles(file_list)).data


@api.route("/data/upload")
async def upload_image_file(req, resp):
"""Upload Image files.
Expand Down
17 changes: 17 additions & 0 deletions tests/ut/assets/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ components:
version:
type: string
type: object
ListUploadFiles:
properties:
fileList:
items:
type: object
type: array
type: object
UploadIdResp:
properties:
release_date:
Expand Down Expand Up @@ -83,6 +90,16 @@ paths:
schema:
$ref: '#/components/schemas/HealthCheck'
description: OK
/data/upload/list:
get:
description: Get file list
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/ListUploadFiles'
description: OK
/data/upload:
post:
requestBody:
Expand Down
20 changes: 20 additions & 0 deletions tests/ut/test_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,26 @@ def test_status(api):
assert actual == expect


def test_list_upload_files(api):
file_list = {"id": 1,
"name": "test",
"file_path": "/tmp/test",
"file_type": "image/png",
"last_index": 0,
"created_at": "2019-07-28 16:21:14",
"updated_at": "2019-07-28 16:21:14"}
mock_uploadedfile = MagicMock()
mock_get_all_uploaded_file = MagicMock(return_value=[file_list])
mock_uploadedfile.get_all_uploaded_file = mock_get_all_uploaded_file
with patch.object(target, "UploadedFile", return_value=mock_uploadedfile):
r = api.requests.get("/data/upload/list")
json_response = json.loads(r.text)
assert "fileList" in json_response
actual = json_response["fileList"]
expect = [file_list]
assert actual == expect


def test_upload_image_file(api, image_b64, tmpdir):
event = json.dumps({"fileName": "test.pdf",
"contentType": "image/png",
Expand Down

0 comments on commit c2f5ad9

Please sign in to comment.