示例#1
0
 def test_form_data(self):
     data = {'foo': 'bar'}
     execute_url = ExecuteUrl(
         'key',
         dict(self.get_default_data(), method='post',
              body=json.dumps(data)))
     execute_url.validate()
     self.assertEqual(execute_url.data['body'], data)
示例#2
0
 def test_body_invalid_method(self):
     data = dict(self.get_default_data(), **{
         'body': 'foo',
     })
     for method in self.no_body_methods:
         with self.assertRaises(InvalidConfig):
             ExecuteUrl('key', dict(data, method=method)).validate()
示例#3
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()
示例#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 self.assertRaises(ExecuteError):
         execute_url.execute()
示例#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 self.assertRaises(ExecuteError):
         execute_url.execute()
示例#6
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()
示例#7
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()
示例#8
0
 def test_verify(self):
     ExecuteUrl('key', dict(self.get_default_data(),
                            verify=False)).execute()
     self.assertFalse(self.session_mock.last_request.verify)
示例#9
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()
示例#10
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()
示例#11
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)
示例#12
0
 def test_form_invalid_data(self):
     execute_url = ExecuteUrl(
         'key', dict(self.get_default_data(), method='post',
                     body='{{inval'))
     with self.assertRaises(InvalidConfig):
         execute_url.validate()