class TestJOSETransportRESTCalls(unittest.TestCase):

    def setUp(self):
        self._http_client = MagicMock(spec=RequestsTransport)
        self._transport = JOSETransport(http_client=self._http_client)
        self._transport.verify_jwt_response = MagicMock()
        self._transport._build_jwt_signature = MagicMock()
        self._transport.content_hash_function = MagicMock()
        self._transport.decrypt_response = MagicMock()
        self._transport._encrypt_request = MagicMock()

    def test_get(self):
        self.assertEqual(self._transport.get('/path'), self._http_client.get.return_value)

    def test_get_with_subject(self):
        self.assertEqual(self._transport.get('/path', ANY), self._http_client.get.return_value)

    def test_post(self):
        self.assertEqual(self._transport.post('/path', ANY), self._http_client.post.return_value)

    def test_put(self):
        self.assertEqual(self._transport.put('/path', ANY), self._http_client.put.return_value)

    def test_delete(self):
        self.assertEqual(self._transport.delete('/path', ANY), self._http_client.delete.return_value)

    def test_patch(self):
        self.assertEqual(self._transport.patch('/path', ANY), self._http_client.patch.return_value)
Beispiel #2
0
class TestJOSETransportRESTCalls(unittest.TestCase):
    def setUp(self):
        self._http_client = MagicMock(spec=RequestsTransport)
        self._transport = JOSETransport(http_client=self._http_client)
        self._transport.verify_jwt_response = MagicMock()
        self._transport._build_jwt_signature = MagicMock()
        self._transport.content_hash_function = MagicMock()
        self._transport.decrypt_response = MagicMock()
        self._transport._encrypt_request = MagicMock()

    def test_get(self):
        self.assertEqual(self._transport.get('/path'),
                         self._http_client.get.return_value)

    def test_get_with_subject(self):
        self.assertEqual(self._transport.get('/path', ANY),
                         self._http_client.get.return_value)

    def test_post(self):
        self.assertEqual(self._transport.post('/path', ANY),
                         self._http_client.post.return_value)

    def test_put(self):
        self.assertEqual(self._transport.put('/path', ANY),
                         self._http_client.put.return_value)

    def test_delete(self):
        self.assertEqual(self._transport.delete('/path', ANY),
                         self._http_client.delete.return_value)

    def test_patch(self):
        self.assertEqual(self._transport.patch('/path', ANY),
                         self._http_client.patch.return_value)
Beispiel #3
0
class TestJOSETransportRESTCalls(unittest.TestCase):
    def setUp(self):
        self._transport = JOSETransport()
        self._transport.verify_jwt_response = MagicMock()
        self._transport._build_jwt_signature = MagicMock()
        self._transport.content_hash_function = MagicMock()
        self._transport.decrypt_response = MagicMock()
        self._transport._encrypt_request = MagicMock()

    @patch('requests.get')
    def test_get(self, requests_patch):
        requests_patch.return_value = MagicMock()
        self.assertIsInstance(self._transport.get('/path'), APIResponse)

    @patch('requests.get')
    def test_get_with_subject(self, requests_patch):
        requests_patch.return_value = MagicMock()
        self.assertIsInstance(self._transport.get('/path', ANY), APIResponse)

    @patch('requests.post')
    def test_post(self, requests_patch):
        requests_patch.return_value = MagicMock()
        self.assertIsInstance(self._transport.post('/path', ANY), APIResponse)

    @patch('requests.put')
    def test_put(self, requests_patch):
        requests_patch.return_value = MagicMock()
        self.assertIsInstance(self._transport.put('/path', ANY), APIResponse)

    @patch('requests.delete')
    def test_delete(self, requests_patch):
        requests_patch.return_value = MagicMock()
        self.assertIsInstance(self._transport.delete('/path', ANY),
                              APIResponse)

    @patch('requests.patch')
    def test_patch(self, requests_patch):
        requests_patch.return_value = MagicMock()
        self.assertIsInstance(self._transport.patch('/path', ANY), APIResponse)