Programming My Life - pytest
  1. [TIL] Mocking Chained Calls

    At work last week, I was asked to write tests for code that reaches out to Twilio's verify service. Here is what that code looks like (from the Twilio docs):

    client = Client(account_sid, auth_token)
    
    verification = client.verify \
                         .v2 \
                         .services('VAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') \
                         .verifications \
                         .create(to='+15017122661', channel='sms')
    

    I was able to …