|
1
|
|
|
import unittest |
|
2
|
|
|
|
|
3
|
|
|
from route4me.exceptions import ParamValueException |
|
4
|
|
|
from route4me.constants import OPTIMIZE, ALGORITHM_TYPE, TRAVEL_MODE, DEVICE_TYPE, DISTANCE_UNIT |
|
5
|
|
|
|
|
6
|
|
|
from tests.base import Route4MeAPITestSuite |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
class Route4MeOptimizationTests(Route4MeAPITestSuite): |
|
10
|
|
|
""" |
|
11
|
|
|
Route4Me Optimization Tests |
|
12
|
|
|
""" |
|
13
|
|
|
|
|
14
|
|
|
def test_api_key(self): |
|
15
|
|
|
""" |
|
16
|
|
|
Test that API key is set |
|
17
|
|
|
:return: |
|
18
|
|
|
""" |
|
19
|
|
|
self.assertEquals(self.route4me.key, '11111111111111111111111111111111') |
|
20
|
|
|
|
|
21
|
|
|
def test_route_name(self): |
|
22
|
|
|
""" |
|
23
|
|
|
Test that route_name is set correctly |
|
24
|
|
|
:return: |
|
25
|
|
|
""" |
|
26
|
|
|
route_name = 'Single Driver Round Trip' |
|
27
|
|
|
self.route4me.optimization.route_name(route_name) |
|
28
|
|
|
data = self.route4me.optimization.data['parameters'] |
|
29
|
|
|
self.assertEquals(route_name, data['route_name']) |
|
30
|
|
|
|
|
31
|
|
|
def test_route_name_validation(self): |
|
32
|
|
|
""" |
|
33
|
|
|
Test route_name validation |
|
34
|
|
|
:return: |
|
35
|
|
|
""" |
|
36
|
|
|
route_name = 234567890 |
|
37
|
|
|
optimization = self.route4me.optimization |
|
38
|
|
|
self.assertRaises(ParamValueException, |
|
39
|
|
|
optimization.route_name, route_name) |
|
40
|
|
|
|
|
41
|
|
|
def test_tsp_optimization(self): |
|
42
|
|
|
optimization = self.route4me.optimization |
|
43
|
|
|
address = self.route4me.address |
|
44
|
|
|
optimization.add(data={ |
|
45
|
|
|
'algorithm_type': ALGORITHM_TYPE.TSP, |
|
46
|
|
|
'share_route': 0, |
|
47
|
|
|
'store_route': 0, |
|
48
|
|
|
'route_time': 0, |
|
49
|
|
|
'route_max_duration': 86400, |
|
50
|
|
|
'vehicle_capacity': 1, |
|
51
|
|
|
'vehicle_max_distance_mi': 10000, |
|
52
|
|
|
'route_name': 'Single Driver Round Trip', |
|
53
|
|
|
'optimize': OPTIMIZE.DISTANCE, |
|
54
|
|
|
'distance_unit': DISTANCE_UNIT.MI, |
|
55
|
|
|
'device_type': DEVICE_TYPE.WEB, |
|
56
|
|
|
'travel_mode': TRAVEL_MODE.DRIVING, |
|
57
|
|
|
}) |
|
58
|
|
|
address.add_address( |
|
59
|
|
|
address='754 5th Ave New York, NY 10019', |
|
60
|
|
|
lat=40.7636197, |
|
61
|
|
|
lng=-73.9744388, |
|
62
|
|
|
alias='Bergdorf Goodman', |
|
63
|
|
|
is_depot=1, |
|
64
|
|
|
time=0 |
|
65
|
|
|
) |
|
66
|
|
|
address.add_address( |
|
67
|
|
|
address='717 5th Ave New York, NY 10022', |
|
68
|
|
|
lat=40.7669692, |
|
69
|
|
|
lng=-73.9693864, |
|
70
|
|
|
alias='Giorgio Armani', |
|
71
|
|
|
time=0 |
|
72
|
|
|
) |
|
73
|
|
|
address.add_address( |
|
74
|
|
|
address='888 Madison Ave New York, NY 10014', |
|
75
|
|
|
lat=40.7715154, |
|
76
|
|
|
lng=-73.9669241, |
|
77
|
|
|
alias='Ralph Lauren Women\'s and Home', |
|
78
|
|
|
time=0 |
|
79
|
|
|
) |
|
80
|
|
|
address.add_address( |
|
81
|
|
|
address='1011 Madison Ave New York, NY 10075', |
|
82
|
|
|
lat=40.7772129, |
|
83
|
|
|
lng=-73.9669, |
|
84
|
|
|
alias='Yigal Azrou\u00ebl', |
|
85
|
|
|
time=0 |
|
86
|
|
|
) |
|
87
|
|
|
address.add_address( |
|
88
|
|
|
address='440 Columbus Ave New York, NY 10024', |
|
89
|
|
|
lat=40.7808364, |
|
90
|
|
|
lng=-73.9732729, |
|
91
|
|
|
alias='Frank Stella Clothier', |
|
92
|
|
|
time=0 |
|
93
|
|
|
) |
|
94
|
|
|
address.add_address( |
|
95
|
|
|
address='324 Columbus Ave #1 New York, NY 10023', |
|
96
|
|
|
lat=40.7803123, |
|
97
|
|
|
lng=-73.9793079, |
|
98
|
|
|
alias='Liana', |
|
99
|
|
|
time=0 |
|
100
|
|
|
) |
|
101
|
|
|
address.add_address( |
|
102
|
|
|
address='110 W End Ave New York, NY 10023', |
|
103
|
|
|
lat=40.7753077, |
|
104
|
|
|
lng=-73.9861529, |
|
105
|
|
|
alias='Toga Bike Shop', |
|
106
|
|
|
time=0 |
|
107
|
|
|
) |
|
108
|
|
|
address.add_address( |
|
109
|
|
|
address='555 W 57th St New York, NY 10019', |
|
110
|
|
|
lat=40.7718005, |
|
111
|
|
|
lng=-73.9897716, |
|
112
|
|
|
alias='BMW of Manhattan', |
|
113
|
|
|
time=0 |
|
114
|
|
|
) |
|
115
|
|
|
address.add_address( |
|
116
|
|
|
address='57 W 57th St New York, NY 10019', |
|
117
|
|
|
lat=40.7558695, |
|
118
|
|
|
lng=-73.9862019, |
|
119
|
|
|
alias='Verizon Wireless', |
|
120
|
|
|
time=0 |
|
121
|
|
|
) |
|
122
|
|
|
response = self.route4me.run_optimization() |
|
123
|
|
|
self.assertEqual(4, response.get('state')) |
|
124
|
|
|
|
|
125
|
|
|
|
|
126
|
|
|
if __name__ == '__main__': |
|
127
|
|
|
unittest.main() |