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

        self.assertIsNone(client._handle_error(flexmock(ok=True)))

        with self.assertRaises(ItemAlreadyExists) as expected_exception:
            client._handle_error(flexmock(ok=False, status_code=CONFLICT, text='something terrible'))
        self.assertEqual('something terrible', expected_exception.exception.message)

        with self.assertRaises(ItemDoesNotExist) as expected_exception:
            client._handle_error(flexmock(ok=False, status_code=NOT_FOUND, text='something terrible'))
        self.assertEqual('something terrible', expected_exception.exception.message)

        with self.assertRaises(PreconditionFailed) as expected_exception:
            client._handle_error(flexmock(ok=False, status_code=PRECONDITION_FAILED, text='something terrible'))
        self.assertEqual('something terrible', expected_exception.exception.message)

        with self.assertRaises(BoxAccountUnauthorized) as expected_exception:
            client._handle_error(flexmock(ok=False, status_code=UNAUTHORIZED, text='something terrible'))
        self.assertEqual('something terrible', expected_exception.exception.message)

        # unknown code
        with self.assertRaises(BoxClientException) as expected_exception:
            client._handle_error(flexmock(ok=False, status_code=599, text='something terrible'))
        self.assertEqual('something terrible', expected_exception.exception.message)