Example #1
0
    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()
Example #2
0
    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')
Example #3
0
    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()
Example #4
0
 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()
Example #5
0
 def test_execute_400(self):
     self.session_mock.post(self.url, status_code=400)
     with self.assertRaises(ExecuteError):
         Http(self.url, method='post').send()
Example #6
0
 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()
Example #7
0
 def test_send(self):
     Http(self.url).send()
     self.assertTrue(self.get_mock.called_once)
Example #8
0
 def test_form_invalid_data(self):
     with self.assertRaises(ValidationError):
         Http(self.url, method='post', content_type='form').message(body='inval')
Example #9
0
 def test_dict_invalid_content_type(self):
     with self.assertRaises(ValidationError):
         Http(self.url, method='post', content_type='plain').message(body={'foo': 3})
Example #10
0
 def test_invalid_json_data(self):
     with self.assertRaises(ValidationError):
         Http(self.url, method='post').message(body={'foo': lambda x: x})
Example #11
0
 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')
Example #12
0
 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')
Example #13
0
 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()
Example #14
0
 def test_invalid_method(self):
     with self.assertRaises(ValidationError):
         Http(self.url, method='spam').message()