Skip to content

Commit

Permalink
global: inherit marshmallow 2 and 3 compatible schema
Browse files Browse the repository at this point in the history
* uses BaseSchema from invenio-rest
  • Loading branch information
kpsherva authored and lnielsen committed Aug 1, 2019
1 parent e4a30e8 commit a39e4f3
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 13 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ env:
- REQUIREMENTS=devel EXTRAS=all,mysql SQLALCHEMY_DATABASE_URI="mysql+pymysql://root@localhost:3306/invenio"
- REQUIREMENTS=devel EXTRAS=all,postgresql SQLALCHEMY_DATABASE_URI="postgresql+psycopg2://postgres@localhost:5432/invenio"


python:
- "2.7"
- "3.5"
Expand Down
6 changes: 4 additions & 2 deletions invenio_files_rest/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@
"""REST API serializers."""

import json
import warnings
from time import sleep

from flask import current_app, request, url_for
from marshmallow import Schema, fields, missing, post_dump
from invenio_rest.serializer import BaseSchema as InvenioRestBaseSchema
from marshmallow import fields, missing, post_dump

from .errors import FilesException
from .models import Bucket, MultipartObject, ObjectVersion, Part


class BaseSchema(Schema):
class BaseSchema(InvenioRestBaseSchema):
"""Base schema for all serializations."""

created = fields.DateTime(dump_only=True)
Expand Down
19 changes: 19 additions & 0 deletions invenio_files_rest/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,23 @@ def parse_header_tags():
load_from='partNumber',
location='query',
required=True,
data_key='partNumber',
),
'content_length': fields.Int(
load_from='Content-Length',
location='headers',
required=True,
validate=minsize_validator,
data_key='Content-Length',
),
'content_type': fields.Str(
load_from='Content-Type',
location='headers',
data_key='Content-Type',
),
'content_md5': fields.Str(
data_key='Content-MD5',
load_from='Content-MD5',
location='headers',
),
Expand All @@ -139,17 +144,20 @@ def default_partfactory(part_number=None, content_length=None,
@use_kwargs({
'content_md5': fields.Str(
load_from='Content-MD5',
data_key='Content-MD5',
location='headers',
missing=None,
),
'content_length': fields.Int(
load_from='Content-Length',
data_key='Content-Length',
location='headers',
required=True,
validate=minsize_validator,
),
'content_type': fields.Str(
load_from='Content-Type',
data_key='Content-Type',
location='headers',
missing='',
),
Expand All @@ -174,17 +182,20 @@ def stream_uploadfactory(content_md5=None, content_length=None,
@use_kwargs({
'part_number': fields.Int(
load_from='_chunkNumber',
data_key='_chunkNumber',
location='form',
required=True,
),
'content_length': fields.Int(
load_from='_currentChunkSize',
data_key='_currentChunkSize',
location='form',
required=True,
validate=minsize_validator,
),
'uploaded_file': fields.Raw(
load_from='file',
data_key='file',
location='files',
required=True,
),
Expand All @@ -206,16 +217,19 @@ def ngfileupload_partfactory(part_number=None, content_length=None,
@use_kwargs({
'content_length': fields.Int(
load_from='_totalSize',
data_key='_totalSize',
location='form',
required=True,
),
'content_type': fields.Str(
load_from='Content-Type',
data_key='Content-Type',
location='headers',
required=True,
),
'uploaded_file': fields.Raw(
load_from='file',
data_key='file',
location='files',
required=True,
),
Expand Down Expand Up @@ -444,11 +458,13 @@ class ObjectResource(ContentNegotiatedMethodView):
'version_id': fields.UUID(
location='query',
load_from='versionId',
data_key='versionId',
missing=None,
),
'upload_id': fields.UUID(
location='query',
load_from='uploadId',
data_key='uploadId',
missing=None,
),
'uploads': fields.Raw(
Expand All @@ -472,6 +488,7 @@ class ObjectResource(ContentNegotiatedMethodView):
'upload_id': fields.UUID(
location='query',
load_from='uploadId',
data_key='uploadId',
missing=None,
)
}
Expand All @@ -480,6 +497,7 @@ class ObjectResource(ContentNegotiatedMethodView):
'upload_id': fields.UUID(
location='query',
load_from='uploadId',
data_key='uploadId',
missing=None,
),
}
Expand All @@ -493,6 +511,7 @@ class ObjectResource(ContentNegotiatedMethodView):
locations=('query', 'json'),
missing=None,
load_from='partSize',
data_key='partSize',
),
}

Expand Down
5 changes: 1 addition & 4 deletions requirements-devel.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,4 @@
# Invenio is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.

-e git+https://github.com/inveniosoftware/invenio-access#egg=invenio-access
-e git+https://github.com/inveniosoftware/invenio-accounts#egg=invenio-accounts
-e git+https://github.com/inveniosoftware/invenio-admin#egg=invenio-admin
-e git+https://github.com/inveniosoftware/invenio-db#egg=invenio-db
-e git+https://github.com/marshmallow-code/marshmallow#egg=marshmallow
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
'pydocstyle>=1.0.0',
'pytest-cov>=1.8.0',
'pytest-pep8>=1.0.6',
'pytest>=3.7.0',
'pytest>=4.0.0,<5.0.0',
]

extras_require = {
Expand All @@ -50,23 +50,23 @@
'tests': tests_require,
}


extras_require['all'] = []
for name, reqs in extras_require.items():
if name in ('postgresql', 'mysql', 'sqlite'):
continue
extras_require['all'].extend(reqs)


install_requires = [
'Flask-CeleryExt>=0.3.1',
'Flask-Login>=0.3.2',
'Flask-WTF>=0.13.1',
'Flask>=0.11.1',
'fs>=0.5.4,<2.0',
'invenio-rest[cors]>=1.0.0',
'marshmallow>=2.15.1,<3.0.0',
'invenio-rest[cors]>=1.1.0',
'simplejson>=3.0.0',
'SQLAlchemy-Utils>=0.31.0',
'webargs>=1.1.1',
'WTForms>=2.0',
]

Expand Down
9 changes: 6 additions & 3 deletions tests/test_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@

from __future__ import absolute_import, print_function

from marshmallow import Schema, fields
from marshmallow import fields

from invenio_files_rest.serializer import json_serializer, serializer_mapping
from invenio_files_rest.serializer import BaseSchema, json_serializer, \
serializer_mapping


def test_serialize_pretty(app):
"""Test pretty JSON."""
class TestSchema(Schema):
class TestSchema(BaseSchema):
title = fields.Str(attribute='title')

data = {'title': 'test'}
Expand All @@ -26,6 +27,8 @@ class TestSchema(Schema):

serializer_mapping['TestSchema'] = TestSchema

# TODO This test should be checked if it shouldn't have
# BaseSchema instead of Schema
with app.test_request_context():
assert json_serializer(data=data, context=context).data == \
b'{"title":"test"}'
Expand Down

0 comments on commit a39e4f3

Please sign in to comment.