
Added a unittest for added function, an exception handling when the trip_id is not expected format, fixed typos
@86699999fabfc407c93a4c888cffd4e05b81ef71
--- action.py
+++ action.py
... | ... | @@ -166,14 +166,16 @@ |
166 | 166 |
def post(self): |
167 | 167 |
db = DB() |
168 | 168 |
data = request.get_json() |
169 |
- |
|
169 |
+ if len(data["trip_id"]) !=64: |
|
170 |
+ return jsonify({500 :"ERROR! INVALID TRIP_ID!"}) |
|
171 |
+ |
|
170 | 172 |
df = pd.DataFrame(data["trip_log"]) |
171 | 173 |
df["user_id"] = data["user_id"] |
172 | 174 |
df["trip_id"] = data["trip_id"] |
173 | 175 |
|
176 |
+ |
|
174 | 177 |
columns = df.columns |
175 |
- data_csv_block = df.to_csv(header=False) |
|
176 |
- |
|
178 |
+ data_csv_block = df.to_csv(header=False, index=False) |
|
177 | 179 |
|
178 | 180 |
token = request.headers.get('Authorization') |
179 | 181 |
if not token: |
--- database/database.py
+++ database/database.py
... | ... | @@ -1,5 +1,6 @@ |
1 | 1 |
import psycopg2 # driver 임포트 |
2 | 2 |
import time |
3 |
+from io import StringIO |
|
3 | 4 |
from datetime import datetime, timedelta |
4 | 5 |
|
5 | 6 |
|
... | ... | @@ -200,7 +201,6 @@ |
200 | 201 |
|
201 | 202 |
def insert_gps_data(self, csv_block, columns): |
202 | 203 |
cur = self.conn.cursor() |
203 |
- |
|
204 | 204 |
data = StringIO(csv_block) |
205 | 205 |
|
206 | 206 |
# using COPY instead of INSERT to do even less operation per data. |
+++ unit_test_insert_gps_command.sh
... | ... | @@ -0,0 +1,43 @@ |
1 | +curl -d '{ | |
2 | + "user_id":"testaccountsingle", | |
3 | + "trip_id":"1a3db65c589afaffd8cb7f7eae6ab53ffecde6f3d96bd8a0d8686070f44dfac3", | |
4 | + "trip_log": { | |
5 | + "latitude":[37.778282], | |
6 | + "longitude":[128.129373], | |
7 | + "timestamp":["2024-07-11 16:23:19.667"] | |
8 | + } | |
9 | +}' -H "Content-Type: application/json" -X POST http://192.168.0.195:15857/action/gps_update | |
10 | + | |
11 | + | |
12 | + | |
13 | +curl -d '{ | |
14 | + "user_id":"testaccountdouble", | |
15 | + "trip_id":"7e46b2c35651611a5269f0f9190b02b80866a76bc7e457fab32ef5ff65b492bc", | |
16 | + "trip_log": { | |
17 | + "latitude":[37.778282, 37.778300], | |
18 | + "longitude":[128.129373, 128.129400], | |
19 | + "timestamp":["2024-07-11 16:23:19.667", "2024-07-11 16:30:43.175"] | |
20 | + } | |
21 | +}' -H "Content-Type: application/json" -X POST http://192.168.0.195:15857/action/gps_update | |
22 | + | |
23 | +curl -d '{ | |
24 | + "user_id":"testaccountinvaliduserid", | |
25 | + "trip_id":"edgecase_test", | |
26 | + "trip_log": { | |
27 | + "latitude":[37.778282, 37.778300], | |
28 | + "longitude":[128.129373, 128.129400], | |
29 | + "timestamp":["2024-07-11 16:23:19.667", "2024-07-11 16:30:43.175"] | |
30 | + } | |
31 | +}' -H "Content-Type: application/json" -X POST http://192.168.0.195:15857/action/gps_update | |
32 | + | |
33 | + | |
34 | +curl -d '{ | |
35 | + "user_id":"testaccount-fifteen", | |
36 | + "trip_id":"9911c80c165b85c7cfbaedd89cb0e0d39bea6d7eb93cadab9b264abc350bb888", | |
37 | + "trip_log": { | |
38 | + "latitude":[37.778282, 37.778283, 37.778284, 37.778285, 37.778286, 37.778287, 37.778288, 37.778289, 37.778290, 37.778291, 37.778292, 37.778293, 37.778294, 37.778295, 37.778296], | |
39 | + "longitude":[128.129373, 128.129374, 128.129375, 128.129376, 128.129377, 128.129378, 128.129379, 128.129380, 128.129381, 128.129382, 128.129383, 128.129384, 128.129385, 128.129386, 128.129387], | |
40 | + "timestamp":["2024-07-11 16:23:19.667", "2024-07-11 16:24:19.667", "2024-07-11 16:25:19.667", "2024-07-11 16:26:19.667", "2024-07-11 16:27:19.667", "2024-07-11 16:28:19.667", "2024-07-11 16:29:19.667", "2024-07-11 16:30:19.667", "2024-07-11 16:31:19.667", "2024-07-11 16:32:19.667", "2024-07-11 16:33:19.667", "2024-07-11 16:34:19.667", "2024-07-11 16:35:19.667", "2024-07-11 16:36:19.667", "2024-07-11 16:37:19.667"] | |
41 | + } | |
42 | +}' -H "Content-Type: application/json" -X POST http://192.168.0.195:15857/action/gps_update | |
43 | + |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?