def test_uuid(self): varLittle = 1 varBig = 5678912 varLittle_res = 'TcH4FR09ROSA4b42WJX6i/NzzjzbX3p7U62YCZUE4CE=\n' varBig_res = 'TcH4FR09ROSA4b42WJX6i7vdGEPO+K9i9fJybUAKFA0=\n' # assert that the start data is correct self.assertEquals(varLittle, decrypt_uuid(varLittle_res)) self.assertEquals(varBig, decrypt_uuid(varBig_res)) # test creating UUID testLittle = create_uuid(varLittle) testBig = create_uuid(varBig) self.assertEquals(testLittle, varLittle_res) self.assertEquals(testBig, varBig_res) # test decryption testLittle = decrypt_uuid(testLittle) testBig = decrypt_uuid(testBig) self.assertEquals(testLittle, varLittle) self.assertEquals(testBig, varBig)
def post(self, request, format=None): data = request.data id = decrypt_uuid(data[settings.JSON_KEYS['RIDER_ID']]) try: rider = Rider.objects.get(id=id) rider.push_id = data.get(settings.JSON_KEYS['RIDER_PUSH_ID'], '') rider.save() return Response( { settings.JSON_KEYS['RIDER_ID']: data[settings.JSON_KEYS['RIDER_ID']] }, status=status.HTTP_201_CREATED) except Exception as ex: return Response({settings.JSON_KEYS['BAD_REQ']: ex.message}, status=status.HTTP_400_BAD_REQUEST)
def post(self, request, format=None): data = request.data id = decrypt_uuid(data[settings.JSON_KEYS['RIDER_ID']]) try: rider = Rider.objects.get(id=id) rider.push_id = data.get(settings.JSON_KEYS['RIDER_PUSH_ID'], '') rider.save() return Response( {settings.JSON_KEYS['RIDER_ID']: data[settings.JSON_KEYS['RIDER_ID']]}, status=status.HTTP_201_CREATED ) except Exception as ex: return Response( {settings.JSON_KEYS['BAD_REQ']: ex.message}, status=status.HTTP_400_BAD_REQUEST )
def post(self, request, format=None): try: ### # This won't work without the header # 'Content-Type: application/json' : data = request.DATA ### # Get the Locations from Data loc_data = data.get(settings.JSON_KEYS['LOCATIONS']) # Get the Tour_Id name from Data tour_id = data.get('tour_id') # Get and decrypt the UUID rider = decrypt_uuid(data[settings.JSON_KEYS['RIDER_ID']]) logger.error("RIDER TO PRINT HERE: ", rider) # Check if the parameters passed in # exist in the database before saving # Get Current Tour curr_tour = TourConfig.objects.get(tour_id=tour_id) if curr_tour is None: raise Exception("Tour '%s' Does Not Exist" % (data.get('tour_id')) ) if rider is None: raise Exception("Rider Id Does Not Exist") # Go through the points and store it into the database loc_list = [] for point in loc_data: time = long(point.get(settings.JSON_KEYS['LOC']['TIME'])) location = Location( rider=Rider(pk=rider), tour_id=TourConfig(tour_id=tour_id), coords=Point( point.get(settings.JSON_KEYS['LOC']['LON']), point.get(settings.JSON_KEYS['LOC']['LAT']) ), accuracy=point.get( settings.JSON_KEYS['LOC']['ACC']), speed=point.get( settings.JSON_KEYS['LOC']['SPEED']), bearing=point.get( settings.JSON_KEYS['LOC']['BEARING']), battery=point.get( settings.JSON_KEYS['LOC']['BATT_LVL']), provider=point.get( settings.JSON_KEYS['LOC']['PROVIDER']), time=(time/1000) ) loc_list.append(location) # if there was not any errors send back a 201 # other wise send 400 and a response # This is where the locations are # being saved the database Location.objects.bulk_create(loc_list) # Get server polling rate from db server_polling_rate = curr_tour.server_polling_rate # Get server polling range from db server_polling_range = curr_tour.server_polling_range # Get location polling rate from db location_polling_rate = curr_tour.location_polling_rate return Response( { settings.JSON_KEYS['SERVER_POLLING_RATE']: server_polling_rate, settings.JSON_KEYS['SERVER_POLLING_RANGE']: server_polling_range, settings.JSON_KEYS['LOCATION_POLLING_RATE']: location_polling_rate }, status=status.HTTP_201_CREATED ) except Exception as ex: logger.info(traceback.format_exc()) return Response( {settings.JSON_KEYS['BAD_REQ']: ex.args}, status=status.HTTP_400_BAD_REQUEST )