• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

AdCombo / flask-combo-jsonapi / 3771624463

pending completion
3771624463

push

github

GitHub
Merge pull request #68 from AdCombo/fix__init_subclass__for_multi_project

60 of 60 new or added lines in 1 file covered. (100.0%)

1351 of 1620 relevant lines covered (83.4%)

0.83 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.36
/flask_combo_jsonapi/data_layers/shared.py
1
from typing import Any
1✔
2

3
from marshmallow import fields, ValidationError
1✔
4

5
from flask_combo_jsonapi.exceptions import InvalidFilters
1✔
6

7

8
# Fields that are not of array type
9
STANDARD_MARSHMALLOW_FIELDS = {
1✔
10
    fields.Dict,
11
    fields.Tuple,
12
    fields.String,
13
    fields.UUID,
14
    fields.Number,
15
    fields.Integer,
16
    fields.Decimal,
17
    fields.Boolean,
18
    fields.Float,
19
    fields.DateTime,
20
    fields.Date,
21
    fields.TimeDelta,
22
    fields.Url,
23
    fields.Str,
24
    fields.Bool,
25
    fields.Int,
26
    fields.Constant,
27
}
28

29

30
def deserialize_field(marshmallow_field: fields.Field, value: Any) -> Any:
1✔
31
    """
32
    Deserialize filter/sort value
33
    :param marshmallow_field: marshmallow field type
34
    :param value: filter/sort value
35
    :return:
36
    """
37
    try:
1✔
38
        if isinstance(value, list) and type(marshmallow_field) in STANDARD_MARSHMALLOW_FIELDS:
1✔
39
            return [marshmallow_field.deserialize(i_value) for i_value in value]
1✔
40
        if not isinstance(value, list) and isinstance(marshmallow_field, fields.List):
1✔
41
            return marshmallow_field.deserialize([value])
×
42
        return marshmallow_field.deserialize(value)
1✔
43
    except ValidationError:
×
44
        raise InvalidFilters(f'Bad filter value: {value!r}')
×
45

46

47
def create_filters_or_sorts(model, filter_or_sort_info, resource, Node):
1✔
48
    """
49
    Apply filters / sorts from filters / sorts information to base query
50

51
    :param DeclarativeMeta model: the model of the node
52
    :param dict/list filter_or_sort_info: current node filter_or_sort information
53
    :param Node:
54
    :param Resource resource: the resource
55
    """
56
    filters_or_sorts = []
1✔
57
    joins = []
1✔
58
    schema = getattr(resource, 'schema') if resource else None
1✔
59
    for filter_or_sort in filter_or_sort_info:
1✔
60
        filters_or_sort, join = Node(model, filter_or_sort, resource, schema).resolve()
1✔
61
        filters_or_sorts.append(filters_or_sort)
1✔
62
        joins.extend(join)
1✔
63

64
    return filters_or_sorts, joins
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc