コード例 #1
0
ファイル: tests.py プロジェクト: disqus/mockhttp
    def test_patching(self):
        with mockhttp.patch('urllib', (
                # no params is default
                (('http://foo.bar.com',), p('fixtures', 'sample.html')),
                (('http://foo.bar.com', 'GET'), p('fixtures', 'sample.html')),
                (('http://foo.bar.com', 'GET', {'a': 'b'}), p('fixtures', 'sample.html')),
                (('http://foo.bar.com', 'POST', {'a': 'b'}), p('fixtures', 'sample.html')),
                (('http://foo.bar.com', 'POST', {'a': 'b'}), mockhttp.response(status=404, headers=())),
            )):

            resp = urllib.urlopen('http://foo.bar.com/')
            self.assertEquals(resp.read(), '<strong>hello!</strong>')
コード例 #2
0
ファイル: tests.py プロジェクト: disqus/mockhttp
    def test_patching(self):
        with mockhttp.patch('httplib', (
                # no params is default
                (('http://foo.bar.com',), p('fixtures', 'sample.html')),
                (('http://foo.bar.com', 'GET'), p('fixtures', 'sample.html')),
                (('http://foo.bar.com', 'GET', {'a': 'b'}), p('fixtures', 'sample.html')),
                (('http://foo.bar.com', 'POST', {'a': 'b'}), p('fixtures', 'sample.html')),
                (('http://foo.bar.com', 'POST', {'a': 'b'}), mockhttp.response(status=404, headers=())),
            )):

            conn = httplib.HTTPConnection('foo.bar.com')
            conn.request('GET', '/')
            
            resp = conn.getresponse()
            self.assertEquals(resp.read(), '<strong>hello!</strong>')