title: How to Test Stripe Webhooks with Mock Data
body: <p>I'm trying to write a unit test that posts a mock event to my stripe webhook.</p>
  
  <p>I went and pulled an event from my logs and tried sending that with the test mode enabled, but I (somewhat predictably) got an error:</p>
  
  <blockquote>
    <p>a similar object exists in live mode, but a test mode key was used to make this request.</p>
  </blockquote>
  
  <p>Fair enough. So how do I create a mock event that I can actually send to my webhook and get it processed correctly? </p>
  
  <p>Here's my current test:</p>
  
  <pre><code>class StripeTest(TestCase):
      def setUp(self):
          self.client = Client()
  
      def test_receiving_a_callback(self):
          with open('donate/test_assets/stripe_event.json', 'r') as f:
              stripe_event = simplejson.load(f)
  
          self.client.post('/donate/callbacks/stripe/',
                           data=simplejson.dumps(stripe_event),
                           content_type='application/json')
  </code></pre>