예제 #1
0
파일: test_http.py 프로젝트: Tim1512/then
    def test_execute_content_type(self):
        self.session_mock.post(self.url, request_headers={'content-type': 'foo'})
        Http(self.url, method='post', content_type='foo').send()
        self.assertEqual(self.session_mock.call_count, 1)

        with self.assertRaises(NoMockAddress):
            Http(self.url, method='post', content_type='bar').send()
예제 #2
0
파일: test_http.py 프로젝트: Tim1512/then
    def test_execute_body(self):
        self.session_mock.post(self.url, additional_matcher=lambda r: r.body == 'foo')
        Http(self.url, method='post').send(body='foo')
        self.assertEqual(self.session_mock.call_count, 1)

        with self.assertRaises(NoMockAddress):
            Http(self.url, method='post').send(body='bar')
예제 #3
0
파일: test_http.py 프로젝트: Tim1512/then
    def test_execute_headers(self):
        self.session_mock.post(self.url, request_headers={'authorization': 'foo'})
        Http(self.url, method='post', headers={'authorization': 'foo'}).send()
        self.assertEqual(self.session_mock.call_count, 1)

        with self.assertRaises(NoMockAddress):
            Http(self.url, method='post', headers={'authorization': 'bar'}).send()
예제 #4
0
파일: test_http.py 프로젝트: Tim1512/then
 def test_authorization(self):
     auth = b'Basic ' + base64.b64encode(b'foo:bar')
     auth = auth.decode('utf-8')
     self.session_mock.post(self.url, request_headers={'Authorization': auth})
     Http(self.url, method='post', auth='foo:bar').send()
예제 #5
0
파일: test_http.py 프로젝트: Tim1512/then
 def test_execute_400(self):
     self.session_mock.post(self.url, status_code=400)
     with self.assertRaises(ExecuteError):
         Http(self.url, method='post').send()
예제 #6
0
파일: test_http.py 프로젝트: Tim1512/then
 def test_execute_exception(self):
     self.session_mock.post(self.url, exc=requests.exceptions.ConnectTimeout)
     with self.assertRaises(ExecuteError):
         Http(self.url, method='post').send()
예제 #7
0
파일: test_http.py 프로젝트: Tim1512/then
 def test_send(self):
     Http(self.url).send()
     self.assertTrue(self.get_mock.called_once)
예제 #8
0
파일: test_http.py 프로젝트: Tim1512/then
 def test_form_invalid_data(self):
     with self.assertRaises(ValidationError):
         Http(self.url, method='post', content_type='form').message(body='inval')
예제 #9
0
파일: test_http.py 프로젝트: Tim1512/then
 def test_dict_invalid_content_type(self):
     with self.assertRaises(ValidationError):
         Http(self.url, method='post', content_type='plain').message(body={'foo': 3})
예제 #10
0
파일: test_http.py 프로젝트: Tim1512/then
 def test_invalid_json_data(self):
     with self.assertRaises(ValidationError):
         Http(self.url, method='post').message(body={'foo': lambda x: x})
예제 #11
0
파일: test_http.py 프로젝트: Tim1512/then
 def test_json_data(self):
     data = {'foo': 'bar'}
     message = Http(self.url, method='post').message(body=data)
     self.assertEqual(message._body, json.dumps(data))
     self.assertEqual(message.content_type, 'application/json')
예제 #12
0
파일: test_http.py 프로젝트: Tim1512/then
 def test_body_invalid_method(self):
     for method in self.no_body_methods:
         with self.assertRaises(ValidationError):
             Http(self.url, method=method).send(body='spam')
예제 #13
0
파일: test_http.py 프로젝트: Tim1512/then
 def test_content_type_invalid_method(self):
     for method in self.no_body_methods:
         with self.assertRaises(ValidationError):
             Http(self.url, method=method, content_type='form').send()
예제 #14
0
파일: test_http.py 프로젝트: Tim1512/then
 def test_invalid_method(self):
     with self.assertRaises(ValidationError):
         Http(self.url, method='spam').message()