Skip to content

Commit a9baa83

Browse files
committed
Avoid a use of tuple and update approved specs
Tuples aren't supported by apispec yet marshmallow-code/apispec#399
1 parent 36d089f commit a9baa83

File tree

6 files changed

+63
-13
lines changed

6 files changed

+63
-13
lines changed

flowclient/flowclient/client.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1540,6 +1540,7 @@ def nocturnal_events(
15401540
stop : str
15411541
ISO format date of the day _after_ the final date for which to count nocturnal events, e.g. "2016-01-08"
15421542
hours: tuple(int,int)
1543+
Tuple defining beginning and end of night
15431544
15441545
subscriber_subset : dict or None, default None
15451546
Subset of subscribers to include in event counts. Must be None
@@ -1556,7 +1557,8 @@ def nocturnal_events(
15561557
"query_kind": "nocturnal_events",
15571558
"start": start,
15581559
"stop": stop,
1559-
"hours": hours,
1560+
"night_start_hour": hours[0],
1561+
"night_end_hour": hours[1],
15601562
"subscriber_subset": subscriber_subset,
15611563
}
15621564

flowmachine/flowmachine/core/server/query_schemas/nocturnal_events.py

+16-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
44

55
from marshmallow import fields, post_load
6-
from marshmallow.validate import OneOf, Length
6+
from marshmallow.validate import OneOf, Length, Range
77

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

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

2932

3033
class NocturnalEventsExposed(BaseExposedQueryWithSampling):
31-
def __init__(self, *, start, stop, hours, subscriber_subset=None, sampling=None):
34+
def __init__(
35+
self,
36+
*,
37+
start,
38+
stop,
39+
night_start_hour,
40+
night_end_hour,
41+
subscriber_subset=None,
42+
sampling=None
43+
):
3244
# Note: all input parameters need to be defined as attributes on `self`
3345
# so that marshmallow can serialise the object correctly.
3446
self.start = start
3547
self.stop = stop
36-
self.hours = hours
48+
self.hours = (night_start_hour, night_end_hour)
3749
self.subscriber_subset = subscriber_subset
3850
self.sampling = sampling
3951

integration_tests/tests/flowapi_tests/test_api_spec.test_generated_openapi_json_spec.approved.txt

+11-2
Original file line numberDiff line numberDiff line change
@@ -1079,8 +1079,17 @@
10791079
},
10801080
"NocturnalEvents": {
10811081
"properties": {
1082-
"hours": {
1083-
"type": "string"
1082+
"night_end_hour": {
1083+
"format": "int32",
1084+
"maximum": 23,
1085+
"minimum": 0,
1086+
"type": "integer"
1087+
},
1088+
"night_start_hour": {
1089+
"format": "int32",
1090+
"maximum": 23,
1091+
"minimum": 0,
1092+
"type": "integer"
10841093
},
10851094
"query_kind": {
10861095
"enum": [

integration_tests/tests/flowapi_tests/test_api_spec.test_generated_openapi_redoc_spec.approved.txt

+11-2
Original file line numberDiff line numberDiff line change
@@ -1012,8 +1012,17 @@
10121012
},
10131013
"NocturnalEvents": {
10141014
"properties": {
1015-
"hours": {
1016-
"type": "string"
1015+
"night_end_hour": {
1016+
"format": "int32",
1017+
"maximum": 23,
1018+
"minimum": 0,
1019+
"type": "integer"
1020+
},
1021+
"night_start_hour": {
1022+
"format": "int32",
1023+
"maximum": 23,
1024+
"minimum": 0,
1025+
"type": "integer"
10171026
},
10181027
"query_kind": {
10191028
"enum": [

integration_tests/tests/flowapi_tests/test_api_spec.test_generated_openapi_yaml_spec.approved.txt

+11-2
Original file line numberDiff line numberDiff line change
@@ -1079,8 +1079,17 @@
10791079
},
10801080
"NocturnalEvents": {
10811081
"properties": {
1082-
"hours": {
1083-
"type": "string"
1082+
"night_end_hour": {
1083+
"format": "int32",
1084+
"maximum": 23,
1085+
"minimum": 0,
1086+
"type": "integer"
1087+
},
1088+
"night_start_hour": {
1089+
"format": "int32",
1090+
"maximum": 23,
1091+
"minimum": 0,
1092+
"type": "integer"
10841093
},
10851094
"query_kind": {
10861095
"enum": [

integration_tests/tests/flowmachine_server_tests/test_server.test_api_spec_of_flowmachine_query_schemas.approved.txt

+11-2
Original file line numberDiff line numberDiff line change
@@ -1060,8 +1060,17 @@
10601060
},
10611061
"NocturnalEvents": {
10621062
"properties": {
1063-
"hours": {
1064-
"type": "string"
1063+
"night_end_hour": {
1064+
"format": "int32",
1065+
"maximum": 23,
1066+
"minimum": 0,
1067+
"type": "integer"
1068+
},
1069+
"night_start_hour": {
1070+
"format": "int32",
1071+
"maximum": 23,
1072+
"minimum": 0,
1073+
"type": "integer"
10651074
},
10661075
"query_kind": {
10671076
"enum": [

0 commit comments

Comments
 (0)