Exemplo n.º 1
0
 def test_execute_400(self):
     self.session_mock.post(self.url, status_code=400)
     execute_url = ExecuteUrl('key', dict(self.get_default_data(), method='post',
                                          **{'content-type': 'plain'}))
     execute_url.validate()
     with self.assertRaises(ExecuteError):
         execute_url.execute()
Exemplo n.º 2
0
 def test_authorization(self):
     auth = b'Basic ' + base64.b64encode(b'foo:bar')
     auth = auth.decode('utf-8') if sys.version_info > (3,) else auth
     self.session_mock.post(self.url, request_headers={'Authorization': auth})
     execute_url = ExecuteUrl('key', dict(self.get_default_data(), method='post', auth='foo:bar'))
     execute_url.validate()
     execute_url.execute()
Exemplo n.º 3
0
 def test_execute_exception(self):
     self.session_mock.post(self.url, exc=requests.exceptions.ConnectTimeout)
     execute_url = ExecuteUrl('key', dict(self.get_default_data(), method='post', body='foo',
                                          **{'content-type': 'plain'}))
     execute_url.validate()
     with self.assertRaises(ExecuteError):
         execute_url.execute()
Exemplo n.º 4
0
 def test_execute_400(self):
     self.session_mock.post(self.url, status_code=400)
     execute_url = ExecuteUrl('key', dict(self.get_default_data(), method='post',
                                          **{'content-type': 'plain'}))
     execute_url.validate()
     with mock_patch.object(logger, 'warning') as warning_mock:
         execute_url.execute()
         warning_mock.assert_called_once()
Exemplo n.º 5
0
 def test_execute_exception(self):
     self.session_mock.post(self.url, exc=requests.exceptions.ConnectTimeout)
     execute_url = ExecuteUrl('key', dict(self.get_default_data(), method='post', body='foo',
                                          **{'content-type': 'plain'}))
     execute_url.validate()
     with mock_patch.object(logger, 'warning') as warning_mock:
         execute_url.execute()
         warning_mock.assert_called_once()
Exemplo n.º 6
0
 def test_execute_content_type(self):
     self.session_mock.post(self.url, request_headers={'content-type': 'foo'})
     execute_url = ExecuteUrl('key', dict(self.get_default_data(), method='post',
                                          **{'content-type': 'foo'}))
     execute_url.validate()
     execute_url.execute()
     execute_url2 = ExecuteUrl('key', dict(self.get_default_data(), method='post',
                                          **{'content-type': 'bar'}))
     execute_url2.validate()
     with self.assertRaises(NoMockAddress):
         execute_url2.execute()
Exemplo n.º 7
0
 def test_execute_body(self):
     self.session_mock.post(self.url, additional_matcher=lambda r: r.body == 'foo')
     execute_url = ExecuteUrl('key', dict(self.get_default_data(), method='post', body='foo',
                                          **{'content-type': 'plain'}))
     execute_url.validate()
     execute_url.execute()
     execute_url2 = ExecuteUrl('key', dict(self.get_default_data(), method='post', body='bar',
                                          **{'content-type': 'plain'}))
     execute_url2.validate()
     with self.assertRaises(NoMockAddress):
         execute_url2.execute()
Exemplo n.º 8
0
 def test_execute(self):
     execute_url = ExecuteUrl('key', self.get_default_data())
     execute_url.validate()
     execute_url.execute()
     self.assertTrue(self.get_mock.called_once)