mocket.mockhttp.Response

Here are the examples of the python api mocket.mockhttp.Response taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

6 Examples 7

Example 1

Project: python-mocket
Source File: test_http.py
View license
    @mocketize
    def test_sendall_double(self):
        Entry.register(Entry.GET, 'http://testme.org/', Response(status=404), Response())
        self.assertRaises(HTTPError, urlopen, 'http://testme.org/')
        response = urlopen('http://testme.org/')
        self.assertEqual(response.code, 200)
        response = urlopen('http://testme.org/')
        self.assertEqual(response.code, 200)
        self.assertEqual(len(Mocket._requests), 3)

Example 2

Project: python-mocket
Source File: test_http.py
View license
    @mocketize
    def test_sendall_double(self):
        Entry.register(Entry.GET, 'http://testme.org/', Response(status=404), Response())
        self.assertRaises(HTTPError, urlopen, 'http://testme.org/')
        response = urlopen('http://testme.org/')
        self.assertEqual(response.code, 200)
        response = urlopen('http://testme.org/')
        self.assertEqual(response.code, 200)
        self.assertEqual(len(Mocket._requests), 3)

Example 3

Project: python-mocket
Source File: test_http.py
View license
    @mocketize
    def test_wrongpath_truesendall(self):
        Entry.register(Entry.GET, 'http://httpbin.org/user.agent', Response())
        response = urlopen('http://httpbin.org/ip')
        self.assertEqual(response.code, 200)

Example 4

Project: python-mocket
Source File: test_http.py
View license
    def test_register(self):
        with mock.patch('time.gmtime') as tt:
            tt.return_value = time.struct_time((2013, 4, 30, 10, 39, 21, 1, 120, 0))
            Entry.register(
                Entry.GET,
                'http://testme.org/get?a=1&b=2#test',
                Response('{"a": "€"}', headers={'content-type': 'application/json'})
            )
        entries = Mocket._entries[('testme.org', 80)]
        self.assertEqual(len(entries), 1)
        entry = entries[0]
        self.assertEqual(entry.method, 'GET')
        self.assertEqual(entry.schema, 'http')
        self.assertEqual(entry.path, '/get')
        self.assertEqual(entry.query, 'a=1&b=2')
        self.assertEqual(len(entry.responses), 1)
        response = entry.responses[0]
        self.assertEqual(response.body, b'{"a": "\xe2\x82\xac"}')
        self.assertEqual(response.status, 200)
        self.assertEqual(response.headers, {
            u'Status': u'200',
            u'Date': u'Tue, 30 Apr 2013 10:39:21 GMT',
            u'Connection': u'close',
            u'Server': u'Python/Mocket',
            u'Content-Length': u'12',
            u'Content-Type': u'application/json',
        })

Example 5

Project: python-mocket
Source File: test_http.py
View license
    @mocketize
    def test_wrongpath_truesendall(self):
        Entry.register(Entry.GET, 'http://httpbin.org/user.agent', Response())
        response = urlopen('http://httpbin.org/ip')
        self.assertEqual(response.code, 200)

Example 6

Project: python-mocket
Source File: test_http.py
View license
    def test_register(self):
        with mock.patch('time.gmtime') as tt:
            tt.return_value = time.struct_time((2013, 4, 30, 10, 39, 21, 1, 120, 0))
            Entry.register(
                Entry.GET,
                'http://testme.org/get?a=1&b=2#test',
                Response('{"a": "€"}', headers={'content-type': 'application/json'})
            )
        entries = Mocket._entries[('testme.org', 80)]
        self.assertEqual(len(entries), 1)
        entry = entries[0]
        self.assertEqual(entry.method, 'GET')
        self.assertEqual(entry.schema, 'http')
        self.assertEqual(entry.path, '/get')
        self.assertEqual(entry.query, 'a=1&b=2')
        self.assertEqual(len(entry.responses), 1)
        response = entry.responses[0]
        self.assertEqual(response.body, b'{"a": "\xe2\x82\xac"}')
        self.assertEqual(response.status, 200)
        self.assertEqual(response.headers, {
            u'Status': u'200',
            u'Date': u'Tue, 30 Apr 2013 10:39:21 GMT',
            u'Connection': u'close',
            u'Server': u'Python/Mocket',
            u'Content-Length': u'12',
            u'Content-Type': u'application/json',
        })