윤영준 윤영준 2024-07-17
Added a unittest for added function, an exception handling when the trip_id is not expected format, fixed typos
@86699999fabfc407c93a4c888cffd4e05b81ef71
action.py
--- action.py
+++ action.py
@@ -166,14 +166,16 @@
     def post(self):
         db = DB()
         data = request.get_json()
-        
+        if len(data["trip_id"]) !=64:
+            return jsonify({500 :"ERROR! INVALID TRIP_ID!"})
+         
         df = pd.DataFrame(data["trip_log"])
         df["user_id"] = data["user_id"]
         df["trip_id"] = data["trip_id"]
         
+       	
         columns = df.columns
-        data_csv_block = df.to_csv(header=False)
-        
+        data_csv_block = df.to_csv(header=False, index=False)
         
         token = request.headers.get('Authorization')
         if not token:
database/database.py
--- database/database.py
+++ database/database.py
@@ -1,5 +1,6 @@
 import psycopg2 # driver 임포트
 import time
+from io import StringIO
 from datetime import datetime, timedelta
 
 
@@ -200,7 +201,6 @@
 
     def insert_gps_data(self, csv_block, columns):
         cur = self.conn.cursor()
-        
         data = StringIO(csv_block)
         
         # using COPY instead of INSERT to do even less operation per data. 
 
unit_test_insert_gps_command.sh (added)
+++ unit_test_insert_gps_command.sh
@@ -0,0 +1,43 @@
+curl -d '{
+   "user_id":"testaccountsingle",
+   "trip_id":"1a3db65c589afaffd8cb7f7eae6ab53ffecde6f3d96bd8a0d8686070f44dfac3",
+   "trip_log": {
+      "latitude":[37.778282],
+      "longitude":[128.129373],
+      "timestamp":["2024-07-11 16:23:19.667"]
+   }
+}' -H "Content-Type: application/json" -X POST http://192.168.0.195:15857/action/gps_update
+
+
+
+curl -d '{
+   "user_id":"testaccountdouble",
+   "trip_id":"7e46b2c35651611a5269f0f9190b02b80866a76bc7e457fab32ef5ff65b492bc",
+   "trip_log": {
+      "latitude":[37.778282, 37.778300],
+      "longitude":[128.129373, 128.129400],
+      "timestamp":["2024-07-11 16:23:19.667", "2024-07-11 16:30:43.175"]
+   }
+}' -H "Content-Type: application/json" -X POST http://192.168.0.195:15857/action/gps_update
+
+curl -d '{
+   "user_id":"testaccountinvaliduserid",
+   "trip_id":"edgecase_test",
+   "trip_log": {
+      "latitude":[37.778282, 37.778300],
+      "longitude":[128.129373, 128.129400],
+      "timestamp":["2024-07-11 16:23:19.667", "2024-07-11 16:30:43.175"]
+   }
+}' -H "Content-Type: application/json" -X POST http://192.168.0.195:15857/action/gps_update
+
+
+curl -d '{
+   "user_id":"testaccount-fifteen",
+   "trip_id":"9911c80c165b85c7cfbaedd89cb0e0d39bea6d7eb93cadab9b264abc350bb888",
+   "trip_log": {
+      "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],
+      "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],
+      "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"]
+   }
+}' -H "Content-Type: application/json" -X POST http://192.168.0.195:15857/action/gps_update
+
Add a comment
List