Esempio n. 1
0
 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')
Esempio n. 2
0
 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)
Esempio n. 3
0
 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')
Esempio n. 4
0
    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)