예제 #1
0
 def test_search_when_bad_request_raised_and_token_not_in_query_raises_bad_request(
         self, mock_invalid_page_token_connection):
     query = _create_test_query()
     query.page_token = None
     service = FileEventService(mock_invalid_page_token_connection)
     with pytest.raises(Py42BadRequestError):
         service.search(query)
예제 #2
0
 def test_unicode_query_search_calls_post_with_query(
         self, connection, successful_response):
     service = FileEventService(connection)
     connection.post.return_value = successful_response
     service.search(RAW_UNICODE_QUERY)
     connection.post.assert_called_once_with(FILE_EVENT_URI,
                                             data=RAW_UNICODE_QUERY)
예제 #3
0
 def test_search_calls_post_with_uri_and_query(
     self, connection, successful_response
 ):
     service = FileEventService(connection)
     connection.post.return_value = successful_response
     query = _create_test_query()
     service.search(query)
     connection.post.assert_called_once_with(FILE_EVENT_URI, json=dict(query))
예제 #4
0
 def test_unicode_query_search_calls_post_with_query(
         self, connection, successful_response):
     service = FileEventService(connection)
     connection.post.return_value = successful_response
     query = _create_test_query(u"我能吞")
     expected = str(query)
     service.search(query)
     connection.post.assert_called_once_with(FILE_EVENT_URI, data=expected)
예제 #5
0
 def test_search_when_given_str_type_query_calls_post_with_uri_and_query(
     self, connection, successful_response
 ):
     service = FileEventService(connection)
     connection.post.return_value = successful_response
     query = str(_create_test_query())
     service.search(query)
     expected = json.loads(query)
     connection.post.assert_called_once_with(FILE_EVENT_URI, json=expected)
예제 #6
0
 def test_search_when_bad_request_raised_with_token_but_has_not_invalid_token_text_raises_bad_request(
         self, mocker, connection):
     connection.post.side_effect = create_mock_error(
         Py42BadRequestError, mocker, "DIFFERENT_ERROR")
     query = _create_test_query()
     query.page_token = "test_page_token"
     service = FileEventService(connection)
     with pytest.raises(Py42BadRequestError):
         service.search(query)
예제 #7
0
    def test_search_when_given_page_token_and_bad_request_with_invalid_page_token_occurs_raises_invalid_page_token_error(
            self, mock_invalid_page_token_connection):
        query = _create_test_query()
        query.page_token = "test_page_token"
        service = FileEventService(mock_invalid_page_token_connection)
        with pytest.raises(Py42InvalidPageTokenError) as err:
            service.search(query)

        assert str(err.value) == "Invalid page token: {}".format(
            query.page_token)
예제 #8
0
    def test_search_when_bad_request_raised_with_token_but_has_not_invalid_token_text_raises_bad_request(
            self, mocker, connection):
        def side_effect(*args, **kwargs):
            http_error = mocker.MagicMock(spec=HTTPError)
            response = mocker.MagicMock(spec=Response)
            response.text = "DIFFERENT_ERROR"
            http_error.response = response
            raise Py42BadRequestError(http_error)

        connection.post.side_effect = side_effect
        query = _create_test_query()
        query.page_token = "test_page_token"
        service = FileEventService(connection)
        with pytest.raises(Py42BadRequestError):
            service.search(query)