File: guide-callback-regex-ipdb.py

package info (click to toggle)
python-httpretty 1.1.4-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 712 kB
  • sloc: python: 4,233; makefile: 72
file content (20 lines) | stat: -rw-r--r-- 621 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import re
import json
import requests
from httpretty import httprettified, HTTPretty


@httprettified(verbose=True, allow_net_connect=False)
def test_basic_body():

   def my_callback(request, url, headers):
       body = {}
       import ipdb;ipdb.set_trace()
       return (200, headers, json.dumps(body))

   # Match any url via the regular expression
   HTTPretty.register_uri(HTTPretty.GET, re.compile(r'.*'), body=my_callback)
   HTTPretty.register_uri(HTTPretty.POST, re.compile(r'.*'), body=my_callback)

   # will trigger ipdb
   response = requests.post('https://test.com', data=json.dumps({'hello': 'world'}))