-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_create_ojp2_request.py
More file actions
55 lines (47 loc) · 3.07 KB
/
test_create_ojp2_request.py
File metadata and controls
55 lines (47 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python3
import datetime
from xsdata.models.datatype import XmlDateTime
from ojp2 import Ojp, Ojprequest, ServiceRequest, OjptripRequest, PlaceContextStructure, TripParamStructure, \
PlaceRefStructure, InternationalTextStructure, NaturalLanguageStringStructure
# simple test
def test_create_ojp2_trip_request_simple_1() -> Ojp:
origin='8507000'
destination='8503000'
starttime=datetime.datetime.utcnow()+ datetime.timedelta(days=2) #10 days in the future
return test_create_ojp2_trip_request_long(origin,destination,starttime)
# very long trip. Currently offers no result
def test_create_ojp2_trip_request_simple_2() -> Ojp:
origin='857868'
destination='8574945'
starttime=datetime.datetime.utcnow()+ datetime.timedelta(days=10) #10 days in the future
return test_create_ojp2_trip_request_long(origin,destination,starttime)
# train splitting example
def test_create_ojp2_trip_request_simple_3() -> Ojp:
origin='8507000' #Bern
destination='8504221' # Neuchâtel
starttime=datetime.datetime.utcnow()+ datetime.timedelta(days=10) #10 days in the future
return test_create_ojp2_trip_request_long(origin,destination,starttime)
# builds the requests
def test_create_ojp2_trip_request_long(origin,destination,starttime) -> Ojp:
starttime = starttime.isoformat() + "Z"
starttime = XmlDateTime.from_string(starttime)
return Ojp(ojprequest=
Ojprequest(service_request=
ServiceRequest(requestor_ref="OJP2TONOVA",
request_timestamp=starttime,
ojptrip_request=
[OjptripRequest(
request_timestamp=starttime,
origin=[PlaceContextStructure(place_ref=
PlaceRefStructure(stop_point_ref=str(origin),
name=InternationalTextStructure(text=NaturalLanguageStringStructure("origin"))),
dep_arr_time=starttime)],
destination=[PlaceContextStructure(place_ref=
PlaceRefStructure(stop_point_ref=str(destination),
name=InternationalTextStructure(text=NaturalLanguageStringStructure("destination"))))
],
params=TripParamStructure(number_of_results=5,
include_track_sections=False,
include_leg_projection=False,
include_turn_description=False,
include_intermediate_stops=True))])))