Skip to content

Commit

Permalink
Avoid a use of tuple and update approved specs
Browse files Browse the repository at this point in the history
Tuples aren't supported by apispec yet marshmallow-code/apispec#399
  • Loading branch information
greenape committed Sep 18, 2019
1 parent 36d089f commit a9baa83
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 13 deletions.
4 changes: 3 additions & 1 deletion flowclient/flowclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1540,6 +1540,7 @@ def nocturnal_events(
stop : str
ISO format date of the day _after_ the final date for which to count nocturnal events, e.g. "2016-01-08"
hours: tuple(int,int)
Tuple defining beginning and end of night
subscriber_subset : dict or None, default None
Subset of subscribers to include in event counts. Must be None
Expand All @@ -1556,7 +1557,8 @@ def nocturnal_events(
"query_kind": "nocturnal_events",
"start": start,
"stop": stop,
"hours": hours,
"night_start_hour": hours[0],
"night_end_hour": hours[1],
"subscriber_subset": subscriber_subset,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

from marshmallow import fields, post_load
from marshmallow.validate import OneOf, Length
from marshmallow.validate import OneOf, Length, Range

from flowmachine.features import NocturnalEvents
from .custom_fields import SubscriberSubset
Expand All @@ -19,7 +19,10 @@ class NocturnalEventsSchema(BaseQueryWithSamplingSchema):
query_kind = fields.String(validate=OneOf(["nocturnal_events"]))
start = fields.Date(required=True)
stop = fields.Date(required=True)
hours = fields.Tuple((fields.Integer(), fields.Integer()))
night_start_hour = fields.Integer(
validate=Range(0, 23)
) # Tuples aren't supported by apispec https://github.com/marshmallow-code/apispec/issues/399
night_end_hour = fields.Integer(validate=Range(0, 23))
subscriber_subset = SubscriberSubset()

@post_load
Expand All @@ -28,12 +31,21 @@ def make_query_object(self, params, **kwargs):


class NocturnalEventsExposed(BaseExposedQueryWithSampling):
def __init__(self, *, start, stop, hours, subscriber_subset=None, sampling=None):
def __init__(
self,
*,
start,
stop,
night_start_hour,
night_end_hour,
subscriber_subset=None,
sampling=None
):
# Note: all input parameters need to be defined as attributes on `self`
# so that marshmallow can serialise the object correctly.
self.start = start
self.stop = stop
self.hours = hours
self.hours = (night_start_hour, night_end_hour)
self.subscriber_subset = subscriber_subset
self.sampling = sampling

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1079,8 +1079,17 @@
},
"NocturnalEvents": {
"properties": {
"hours": {
"type": "string"
"night_end_hour": {
"format": "int32",
"maximum": 23,
"minimum": 0,
"type": "integer"
},
"night_start_hour": {
"format": "int32",
"maximum": 23,
"minimum": 0,
"type": "integer"
},
"query_kind": {
"enum": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1012,8 +1012,17 @@
},
"NocturnalEvents": {
"properties": {
"hours": {
"type": "string"
"night_end_hour": {
"format": "int32",
"maximum": 23,
"minimum": 0,
"type": "integer"
},
"night_start_hour": {
"format": "int32",
"maximum": 23,
"minimum": 0,
"type": "integer"
},
"query_kind": {
"enum": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1079,8 +1079,17 @@
},
"NocturnalEvents": {
"properties": {
"hours": {
"type": "string"
"night_end_hour": {
"format": "int32",
"maximum": 23,
"minimum": 0,
"type": "integer"
},
"night_start_hour": {
"format": "int32",
"maximum": 23,
"minimum": 0,
"type": "integer"
},
"query_kind": {
"enum": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1060,8 +1060,17 @@
},
"NocturnalEvents": {
"properties": {
"hours": {
"type": "string"
"night_end_hour": {
"format": "int32",
"maximum": 23,
"minimum": 0,
"type": "integer"
},
"night_start_hour": {
"format": "int32",
"maximum": 23,
"minimum": 0,
"type": "integer"
},
"query_kind": {
"enum": [
Expand Down

0 comments on commit a9baa83

Please sign in to comment.