title: Assert body of HTTP requests using requests_mock
body: <p>I am using <a href="http://requests-mock.readthedocs.io/en/latest/" rel="noreferrer">requests-mock</a> with pytest to facilitate unit testing my library, which uses <a href="http://docs.python-requests.org/en/master/" rel="noreferrer">requests</a> for API calls.</p>
  
  <p>In addition to mocking server responses, I often need to verify that my library sends the expected payload in the HTTP body.</p>
  
  <p>I have been able to do this, albeit indirectly, using an <a href="http://requests-mock.readthedocs.io/en/latest/matching.html#additional-matchers" rel="noreferrer">additional_matcher</a> callback in my tests:</p>
  
  <pre><code>def mylibrary_foo():
      """Library method that is under test."""
      r = requests.post('http://example.com/foo', data='hellxo')
      return r.text
  
  @requests_mock.Mocker()
  def test_foo(m):
      def matcher(request):
          assert request.body == 'hello'
          return True
  
      m.post('http://example.com/foo', text='bar', additional_matcher=matcher)
  
      result = mylibrary_foo()
      assert result == 'bar'
  </code></pre>
  
  <p>But it feels a little funny to be using the <code>additional_matcher</code> callback to verify the request format, as it is really intended to determine whether or not this particular request call should be mocked at all. Were I not using requests-mock, it seems I would be doing something more like:</p>
  
  <pre><code>def test_foo():
     # setup api_mock here...
     mylibrary_foo()
     api_mock.assert_called_with(data='hello')
  </code></pre>
  
  <p>Is there a pattern commonly used with requests-mock to support HTTP request verification?</p>