Example #1
0
    def test_handle_error(self):
        client = BoxClient('my_token')

        self.assertIsNone(client._check_for_errors(mocked_response()))

        with self.assertRaises(ItemAlreadyExists) as expected_exception:
            client._check_for_errors(mocked_response('something terrible', status_code=CONFLICT))
        self.assertEqual(CONFLICT, expected_exception.exception.status_code)
        self.assertEqual('something terrible', expected_exception.exception.message)

        with self.assertRaises(ItemDoesNotExist) as expected_exception:
            client._check_for_errors(mocked_response('something terrible', status_code=NOT_FOUND))
        self.assertEqual(NOT_FOUND, expected_exception.exception.status_code)
        self.assertEqual('something terrible', expected_exception.exception.message)

        with self.assertRaises(PreconditionFailed) as expected_exception:
            client._check_for_errors(mocked_response('something terrible', status_code=PRECONDITION_FAILED))
        self.assertEqual(PRECONDITION_FAILED, expected_exception.exception.status_code)
        self.assertEqual('something terrible', expected_exception.exception.message)

        with self.assertRaises(BoxAccountUnauthorized) as expected_exception:
            client._check_for_errors(mocked_response('something terrible', status_code=UNAUTHORIZED))
        self.assertEqual(UNAUTHORIZED, expected_exception.exception.status_code)
        self.assertEqual('something terrible', expected_exception.exception.message)

        # unknown code
        with self.assertRaises(BoxClientException) as expected_exception:
            client._check_for_errors(mocked_response('something terrible', status_code=599))
        self.assertEqual(599, expected_exception.exception.status_code)
        self.assertEqual('something terrible', expected_exception.exception.message)
Example #2
0
    def test_handle_error(self):
        client = BoxClient('my_token')

        self.assertIsNone(client._check_for_errors(mocked_response()))

        with self.assertRaises(ItemAlreadyExists) as expected_exception:
            client._check_for_errors(mocked_response('something terrible', status_code=CONFLICT))
        self.assertEqual(CONFLICT, expected_exception.exception.status_code)
        self.assertEqual('something terrible', expected_exception.exception.message)

        with self.assertRaises(ItemDoesNotExist) as expected_exception:
            client._check_for_errors(mocked_response('something terrible', status_code=NOT_FOUND))
        self.assertEqual(NOT_FOUND, expected_exception.exception.status_code)
        self.assertEqual('something terrible', expected_exception.exception.message)

        with self.assertRaises(PreconditionFailed) as expected_exception:
            client._check_for_errors(mocked_response('something terrible', status_code=PRECONDITION_FAILED))
        self.assertEqual(PRECONDITION_FAILED, expected_exception.exception.status_code)
        self.assertEqual('something terrible', expected_exception.exception.message)

        with self.assertRaises(BoxAccountUnauthorized) as expected_exception:
            client._check_for_errors(mocked_response('something terrible', status_code=UNAUTHORIZED))
        self.assertEqual(UNAUTHORIZED, expected_exception.exception.status_code)
        self.assertEqual('something terrible', expected_exception.exception.message)

        # unknown code
        with self.assertRaises(BoxClientException) as expected_exception:
            client._check_for_errors(mocked_response('something terrible', status_code=599))
        self.assertEqual(599, expected_exception.exception.status_code)
        self.assertEqual('something terrible', expected_exception.exception.message)