def test_plain_response(self): content = '<html>foobar</html>' predefined_response = StringResponse( {'Status': 200, 'Content-Type': 'text/html'}, content ) client = SimpleMockClient('/api', 'user', 'pw', responses=[predefined_response,]) url = '/some/url' response = client.get(url) self.assertEqual(response.content, content) self.assertEqual(response.status_code, 200) self.assertEqual(response['Content-Type'], 'text/html')
def test_request_string_response(self): predefined_response = StringResponse( {'Foo': 'Bar'}, '{}' ) client = SimpleMockClient('/api', 'user', 'pw', responses=[predefined_response,]) url = '/some/url' response = client.get(url) self.assertEqual(response.content, {}) self.assertEqual(response.status_code, 0) self.assertEqual(response['Content-Type'], 'application/json') self.assertEqual(response['Foo'], 'Bar') self.assertEqual(response.request['PATH_INFO'], '/api%s' % url)
def test_json_response(self): content = { 'some_field': 'some_value' } predefined_response = StringResponse( {'Status': 200}, json.dumps(content) ) client = SimpleMockClient('/api', 'user', 'pw', responses=[predefined_response,]) url = '/some/url' response = client.get(url) self.assertEqual(response.content, content) self.assertEqual(response.status_code, 200) self.assertEqual(response['Content-Type'], 'application/json')
def test_request_file_response(self): non_existent_file = '__does_not_exist__.tmp' self.assertFalse(os.path.isfile(non_existent_file)) self.assertRaises(ValueError, FileResponse, {}, non_existent_file) predefined_response = FileResponse( {'Foo': 'Bar', 'Content-Type': 'text/python'}, '%s' % __file__ ) client = SimpleMockClient('/api', 'user', 'pw', responses=[predefined_response,]) url = '/some/url' response = client.get(url) self.assertTrue(self.__class__.__name__ in response.content) self.assertEqual(response.status_code, 0) self.assertEqual(response['Content-Type'], 'text/python') self.assertEqual(response['Foo'], 'Bar') self.assertEqual(response.request['PATH_INFO'], '/api%s' % url)