0
def post_driver(l):
    def id_generator(size = 6, chars = string.ascii_uppercase + string.digits):
        return ''.join(random.choice(chars) for _ in range(size))
    data = {"startLocation":{"address":{"fullAddress":"\n,  ","fullAddressInLine":", ,  ","line1":"10407 Water Hyacinth Dr","city":"Orlando","state":"FL","zip":"32825"},"latitude":28.52144,"longitude":-81.23301},"endLocation":{"address":{"fullAddress":"\n,  ","fullAddressInLine":", ,  ","line1":"1434 N Alafaya Trail","city":"Orlando","state":"FL","zip":"32819"},"latitude":28.52144,"longitude":-81.23301},"user":{"firstName":"Test" + id_generator(),"lastName":"doe","Username":"","Password":"","userId":"","role":"","email":"zbaker@productivityapex.com","username":"Test" + id_generator() + "","newPassword":"test"},"vehicle":{"vehicleNumber":"" + id_generator(),"licensePlate":"3216549877","maxCapacity":200000,"maxCapacityUnits":"units","costPerMile":3500,"fixedCost":35000,"costPerHour":35,"odometer":0,"tags":[{"text":"vehicle"}],"constraintTags":[],"id":"59fcca46520a6e2bb4a397ed"},"earliestStartTimeDate":"Mon Nov 13 2017 07:00:00 GMT-0500 (Eastern Standard Time)","restBreakDurationDate":"Mon Nov 13 2017 01:00:00 GMT-0500 (Eastern Standard Time)","maximumWorkingHours":9,"maximumDrivingHours":8,"fixedCost":0,"costPerMile":0,"costPerHour":0,"restBreakWindows":[{"startTime":"2017-11-03T19:30:35.275Z","endTime":"2017-11-04T05:00:35.275Z"}],"color":"#1c7c11","tags":[{"text":"test"}],"driverNumber":"" + id_generator(),"phoneNumber":"7894651231","earliestStartTime":"07:00:00","restBreakDuration":"01:00:00","customFields":{}}

    # json_str = json.dumps(data)
    r = l.client.post('/api/v1/drivers', data=str(data))
    # content = r.json()
    # return content["id"]

I am currently having issues with posting the data variable and having it succeed in my locust file. I've done this with other locust files with similar formats, but it's failing every time on this particular request... can someone please help me?

Z.Baker
  • 1
  • 1
  • 3
  • What is the error that you are getting? – Abhimanyu singh Jan 05 '18 at 07:56
  • HTTPError('400 Client Error: Bad Request for url: http://localhost:62840/api/v1/drivers',) – Z.Baker Jan 10 '18 at 22:16
  • When I printed the JSON data from the response, it gave me back the following: '{'isValid': False, 'errors': [{'propertyName': 'driverNumber', 'messages': ['Number is required', 'Starting location is required', 'End location is required', 'Start location address is invalid', 'End location address is invalid']}]}' – Z.Baker Jan 17 '18 at 17:18
  • I guess that solves your issue? Seems to be some problem with the data that you are posting – Abhimanyu singh Jan 22 '18 at 11:04
  • Yes it does, thank you for the help Abhimanyu singh. – Z.Baker Jan 30 '18 at 21:24

0 Answers0