예제 #1
0
 def test_send_failure(self):
     transport = SubmissionServiceTransport(
         self.valid_url, self.valid_option_string)
     requests.post.return_value = MagicMock(name='response')
     requests.post.return_value.status_code = 412
     requests.post.return_value.text = 'Some error'
     # Oops, raise_for_status doesn't get fooled by my mocking,
     # so I have to mock *that* method as well..
     requests.post.return_value.raise_for_status = MagicMock(
         side_effect=HTTPError)
     with self.assertRaises(TransportError):
         transport.send(self.sample_archive)
예제 #2
0
    def test_send_failure(self):
        transport = CertificationTransport(self.valid_url,
                                           self.valid_option_string)

        requests.post.return_value = MagicMock(name='response')
        requests.post.return_value.status_code = 412
        requests.post.return_value.text = 'Some error'
        #Oops, raise_for_status doesn't get fooled by my mocking,
        #so I have to mock *that* method as well..
        requests.post.return_value.raise_for_status = MagicMock(
            side_effect=HTTPError)

        with self.assertRaises(HTTPError):
            result = transport.send(self.sample_xml)
            self.assertIsNotNone(result)
예제 #3
0
 def test_send_success(self):
     transport = SubmissionServiceTransport(
         self.valid_url, self.valid_option_string)
     requests.post.return_value = MagicMock(name='response')
     requests.post.return_value.status_code = 200
     requests.post.return_value.text = '{"id": 768}'
     result = transport.send(self.sample_archive)
     self.assertTrue(result)
예제 #4
0
    def proxy_test(self, environment, proxies):
        test_environment = environment
        test_proxies = proxies
        test_config = PlainBoxConfig()
        test_config.environment = test_environment

        transport = SubmissionServiceTransport(
            self.valid_url, self.valid_option_string)
        dummy_data = BytesIO(b"some data to send")

        requests.post.return_value = MagicMock(name='response')
        requests.post.return_value.status_code = 200
        requests.post.return_value.text = '{"id": 768}'
        result = transport.send(dummy_data, config=test_config)
        self.assertTrue(result)
        requests.post.assert_called_with(
            self.valid_url, data=dummy_data,
            proxies=test_proxies)
예제 #5
0
    def proxy_test(self, environment, proxies):
        test_environment = environment
        test_proxies = proxies
        test_config = PlainBoxConfig()
        test_config.environment = test_environment

        transport = CertificationTransport(
            self.valid_url, self.valid_option_string)
        dummy_data = BytesIO(b"some data to send")

        requests.post.return_value = MagicMock(name='response')
        requests.post.return_value.status_code = 200
        requests.post.return_value.text = '{"id": 768}'
        result = transport.send(dummy_data, config=test_config)
        self.assertTrue(result)
        requests.post.assert_called_with(
            self.valid_url, files={'data': dummy_data},
            headers={'X_HARDWARE_ID': self.valid_secure_id},
            proxies=test_proxies)