示例#1
0
    def test_index_raises_connection_exception(self, mock_index):
        """Index service raises a IndexConnectionError."""
        mock_index.get_document.side_effect = IndexConnectionError

        with self.assertRaises(InternalServerError):
            response_data, code, headers = simple.retrieve_document('124.5678')
        self.assertEqual(mock_index.get_document.call_count, 1,
                         "A search should be attempted")
        call_args, call_kwargs = mock_index.get_document.call_args
        self.assertIsInstance(call_args[0], str, "arXiv ID is passed")
示例#2
0
    def test_document_not_found(self, mock_index):
        """The document is not found."""
        def _raiseDocumentNotFound(*args, **kwargs):
            raise DocumentNotFound('What now')

        mock_index.get_document.side_effect = _raiseDocumentNotFound

        with self.assertRaises(NotFound):
            try:
                response_data, code, headers = simple.retrieve_document(1)
            except DocumentNotFound as e:
                self.fail("DocumentNotFound should be handled (caught %s)" % e)

        self.assertEqual(mock_index.get_document.call_count, 1,
                         "A search should be attempted")
示例#3
0
    def test_encounters_queryerror(self, mock_index):
        """There is a bug in the index or query."""
        def _raiseQueryError(*args, **kwargs):
            raise QueryError('What now')

        mock_index.get_document.side_effect = _raiseQueryError

        with self.assertRaises(InternalServerError):
            try:
                response_data, code, headers = simple.retrieve_document(1)
            except QueryError as e:
                self.fail("QueryError should be handled (caught %s)" % e)

        self.assertEqual(mock_index.get_document.call_count, 1,
                         "A search should be attempted")
示例#4
0
    def test_index_raises_connection_exception(self, mock_index):
        """Index service raises a IndexConnectionError."""
        # We need to explicit assign the exception to the mock, otherwise the
        #  exception raised in the side-effect will just be a mock object (not
        #  inheriting from BaseException).
        mock_index.IndexConnectionError = IndexConnectionError
        mock_index.QueryError = QueryError

        # def _raiseIndexConnectionError(*args, **kwargs):
        #     raise IndexConnectionError('What now')

        mock_index.get_document.side_effect = IndexConnectionError

        with self.assertRaises(InternalServerError):
            response_data, code, headers = simple.retrieve_document('124.5678')
        self.assertEqual(mock_index.get_document.call_count, 1,
                         "A search should be attempted")
        call_args, call_kwargs = mock_index.get_document.call_args
        self.assertIsInstance(call_args[0], str, "arXiv ID is passed")
示例#5
0
    def test_encounters_queryerror(self, mock_index):
        """There is a bug in the index or query."""
        # We need to explicit assign the exception to the mock, otherwise the
        #  exception raised in the side-effect will just be a mock object (not
        #  inheriting from BaseException).
        mock_index.QueryError = QueryError
        mock_index.IndexConnectionError = IndexConnectionError

        def _raiseQueryError(*args, **kwargs):
            raise QueryError('What now')

        mock_index.get_document.side_effect = _raiseQueryError

        with self.assertRaises(InternalServerError):
            try:
                response_data, code, headers = simple.retrieve_document(1)
            except QueryError as e:
                self.fail("QueryError should be handled (caught %s)" % e)

        self.assertEqual(mock_index.get_document.call_count, 1,
                         "A search should be attempted")
示例#6
0
    def test_document_not_found(self, mock_index):
        """The document is not found."""
        # We need to explicit assign the exception to the mock, otherwise the
        #  exception raised in the side-effect will just be a mock object (not
        #  inheriting from BaseException).
        mock_index.QueryError = QueryError
        mock_index.IndexConnectionError = IndexConnectionError
        mock_index.DocumentNotFound = DocumentNotFound

        def _raiseDocumentNotFound(*args, **kwargs):
            raise DocumentNotFound('What now')

        mock_index.get_document.side_effect = _raiseDocumentNotFound

        with self.assertRaises(NotFound):
            try:
                response_data, code, headers = simple.retrieve_document(1)
            except DocumentNotFound as e:
                self.fail("DocumentNotFound should be handled (caught %s)" % e)

        self.assertEqual(mock_index.get_document.call_count, 1,
                         "A search should be attempted")