윤영준 윤영준 2024-07-17
added another boundary condition : this is for when the data itself is incomplete, where its missing some one or two data
@6beb404c145a4e71a6755337ad8fa13329b0a543
action.py
--- action.py
+++ action.py
@@ -164,6 +164,15 @@
 @Action.route('/gps_update')
 class fileUpload(Resource):
     def post(self):
+        token = request.headers.get('Authorization')
+        if not token:
+            return jsonify({'result': 'fail', 'msg': '토큰이 없습니다.'})
+        else:
+            # Decode the token to verify it
+            decoded_token = jwt.decode(token, "secret", algorithms=['HS256'])
+            #print(decoded_token)
+            user_id = decoded_token['id']
+    
         db = DB()
         data = request.get_json()
         if len(data["trip_id"]) !=64:
@@ -171,6 +180,17 @@
             
         if len(data["trip_log"]["timestamp"]) == 0:
             return jsonify({500 :"ERROR! 'trip_log' is empty!"})
+        
+        time_stamp_len = len(data["trip_log"]["timestamp"])
+        latitude_len = len(data["trip_log"]["latitude"])
+        longitude_len = len(data["trip_log"]["longitude"])
+       
+        if time_stamp_len != latitude_len or latitude_len != longitude_len:
+            return jsonify(
+                {
+                    500: f"ERROR! Mismatching length of data in trip_log! \n timestamp : {time_stamp_len} \n latitude : {latitude_len} \n longitude : {longitude_len}"
+                }
+            )
          
         df = pd.DataFrame(data["trip_log"])
         df["user_id"] = data["user_id"]
@@ -179,16 +199,6 @@
        	
         columns = df.columns
         data_csv_block = df.to_csv(header=False, index=False)
-        
-        token = request.headers.get('Authorization')
-        if not token:
-            return jsonify({'result': 'fail', 'msg': '토큰이 없습니다.'})
-        
-        else:
-            # Decode the token to verify it
-            decoded_token = jwt.decode(token, "secret", algorithms=['HS256'])
-            #print(decoded_token)
-            user_id = decoded_token['id']
         
         # GPS 데이터베이스에 삽입
         db.insert_gps_data(data_csv_block, columns)
unit_test_insert_gps_command.sh
--- unit_test_insert_gps_command.sh
+++ unit_test_insert_gps_command.sh
@@ -41,3 +41,35 @@
    }
 }' -H "Content-Type: application/json" -X POST http://192.168.0.195:15857/action/gps_update
 
+
+curl -d '{
+   "user_id":"testaccount-mismatchlen-long",
+   "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],
+      "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
+
+curl -d '{
+   "user_id":"testaccount-mismatchlen-lat",
+   "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],
+      "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
+
+
+curl -d '{
+   "user_id":"testaccount-fifteen-timestamp",
+   "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: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