title: Mock Stripe Methods in Python for testing
body: <p>So I am trying to mock all the <code>stripe web hooks</code> in the method so that I can write the <code>Unit test</code> for it. I am using the <a href="https://docs.python.org/3/library/unittest.mock.html">mock library</a> for mocking the stripe methods. Here is the method I am trying to mock:</p>
  
  <pre><code>class AddCardView(APIView):
  """
  * Add card for the customer
  """
  
  permission_classes = (
      CustomerPermission,
  )
  
  def post(self, request, format=None):
      name = request.DATA.get('name', None)
      cvc = request.DATA.get('cvc', None)
      number = request.DATA.get('number', None)
      expiry = request.DATA.get('expiry', None)
  
      expiry_month, expiry_year = expiry.split("/")
  
      customer_obj = request.user.contact.business.customer
  
      customer = stripe.Customer.retrieve(customer_obj.stripe_id)
  
      try:
          card = customer.sources.create(
              source={
                  "object": "card",
                  "number": number,
                  "exp_month": expiry_month,
                  "exp_year": expiry_year,
                  "cvc": cvc,
                  "name": name
              }
          )
          # making it the default card
          customer.default_source = card.id
          customer.save()
      except CardError as ce:
          logger.error("Got CardError for customer_id={0}, CardError={1}".format(customer_obj.pk, ce.json_body))
          return Response({"success": False, "error": "Failed to add card"})
      else:
          customer_obj.card_last_4 = card.get('last4')
          customer_obj.card_kind = card.get('type', '')
          customer_obj.card_fingerprint = card.get('fingerprint')
          customer_obj.save()
  
      return Response({"success": True})
  </code></pre>
  
  <p>This is the method for <code>unit testing</code>:</p>
  
  <pre><code>@mock.patch('stripe.Customer.retrieve')
  @mock.patch('stripe.Customer.create')
  def test_add_card(self,create_mock,retrieve_mock):
      response = {
          'default_card': None,
          'cards': {
              "count": 0,
              "data": []
          }
      }
  
      # save_mock.return_value = response
      create_mock.return_value = response
      retrieve_mock.return_value = response
  
      self.api_client.client.login(username = self.username, password = self.password)
      res = self.api_client.post('/biz/api/auth/card/add')
  
      print res
  </code></pre>
  
  <p>Now <code>stripe.Customer.retrieve</code> is being mocked properly. But I am not able to mock <code>customer.sources.create</code>. I am really stuck on this.</p>