# AUTO-GENERATED FILE - DO NOT EDIT
# This file was automatically generated by the XDK build tool.
# Any manual changes will be overwritten on the next generation.
"""
Auto-generated contract tests for {"class_name": "Posts", "display_name": "posts", "import_name": "posts", "original": ["posts"], "property_name": "posts"} client.

This module contains tests that validate the request/response contracts
of the {"class_name": "Posts", "display_name": "posts", "import_name": "posts", "original": ["posts"], "property_name": "posts"} client against the OpenAPI specification.

Generated automatically - do not edit manually.
"""

import pytest
import json
import requests
from unittest.mock import Mock, patch
from xdk.posts.client import PostsClient
from xdk import Client


class TestPostsContracts:
    """Test the API contracts of PostsClient."""


    def setup_class(self):
        """Set up test fixtures."""
        self.client = Client(base_url="https://api.example.com")
        self.posts_client = getattr(self.client, "posts")


    def test_get_insights28hr_request_structure(self):
        """Test get_insights28hr request structure."""
        # Mock the session to capture request details
        with patch.object(self.client, "session") as mock_session:
            mock_response = Mock()
            mock_response.status_code = 200
            mock_response.json.return_value = {
                "data": None,
            }
            mock_response.raise_for_status.return_value = None
            mock_session.get.return_value = mock_response
            # Prepare test parameters
            kwargs = {}
            # Add required parameters
            kwargs["tweet_ids"] = ["test_item"]
            kwargs["granularity"] = "test_granularity"
            kwargs["requested_metrics"] = ["test_item"]
            # Add request body if required
            # Call the method
            try:
                method = getattr(self.posts_client, "get_insights28hr")
                # Check if this might be a streaming operation by inspecting return type
                import types
                import inspect
                sig = inspect.signature(method)
                return_annotation = str(sig.return_annotation)
                might_be_streaming = (
                    "Generator" in return_annotation or "Iterator" in return_annotation
                )
                # Set up streaming mock if it might be streaming (before calling method)
                if might_be_streaming:
                    mock_streaming_response = Mock()
                    mock_streaming_response.status_code = 200
                    mock_streaming_response.raise_for_status.return_value = None
                    # Make it a proper context manager
                    mock_streaming_response.__enter__ = Mock(
                        return_value=mock_streaming_response
                    )
                    mock_streaming_response.__exit__ = Mock(return_value=None)
                    # Set up iter_content to return an iterator that yields test data
                    # iter_content with decode_unicode=True returns strings, not bytes
                    test_data = '{"data": "test"}\n'
                    # iter_content is called as a method, so we need to make it return an iterator
                    mock_streaming_response.iter_content = Mock(
                        side_effect=lambda *args, **kwargs: iter([test_data])
                    )
                    # Make session.get return the context manager
                    mock_session.get.return_value = mock_streaming_response
                result = method(**kwargs)
                # Check if this is actually a streaming operation (returns Generator)
                is_streaming = isinstance(result, types.GeneratorType)
                if is_streaming:
                    # Consume the generator to trigger the HTTP request
                    # The HTTP request happens when entering the 'with' block inside the generator
                    # We need to actually iterate to trigger the request
                    try:
                        # Try to get first item - this will trigger the HTTP request
                        # The 'with' statement inside the generator will call session.get()
                        next(result)
                    except StopIteration:
                        # Generator exhausted immediately - request was still made
                        pass
                    except (
                        requests.exceptions.RequestException,
                        json.JSONDecodeError,
                        AttributeError,
                        ValueError,
                    ) as e:
                        # These exceptions can occur during streaming (request errors, JSON parsing, etc.)
                        # The request should still have been attempted
                        pass
                    # Don't catch other exceptions - if there's an error during setup (before the request),
                    # we want to know about it, and the request verification below will fail appropriately
                # Verify the request was made
                # For streaming operations, the request happens when entering the 'with' block
                # which occurs when we call next() on the generator
                mock_session.get.assert_called_once()
                # Verify request structure
                call_args = mock_session.get.call_args
                # Check URL structure
                called_url = (
                    call_args[0][0] if call_args[0] else call_args[1].get("url", "")
                )
                expected_path = "/2/insights/28hr"
                assert expected_path.replace("{", "").replace(
                    "}", ""
                ) in called_url or any(
                    param in called_url for param in ["test_", "42"]
                ), f"URL should contain path template elements: {called_url}"
                # Verify response structure
                if is_streaming:
                    # For streaming, verify we got a generator
                    assert isinstance(
                        result, types.GeneratorType
                    ), "Streaming method should return a generator"
                else:
                    # For regular operations, verify we got a result
                    assert result is not None, "Method should return a result"
            except Exception as e:
                pytest.fail(f"Contract test failed for get_insights28hr: {e}")


    def test_get_insights28hr_required_parameters(self):
        """Test that get_insights28hr handles parameters correctly."""
        method = getattr(self.posts_client, "get_insights28hr")
        # Test with missing required parameters - mock the request to avoid network calls
        with patch.object(self.client, "session") as mock_session:
            # Mock a 400 response (typical for missing required parameters)
            mock_response = Mock()
            mock_response.status_code = 400
            mock_response.json.return_value = {"error": "Missing required parameters"}
            mock_response.raise_for_status.side_effect = Exception("Bad Request")
            mock_session.get.return_value = mock_response
            # Call without required parameters should either raise locally or via server response
            # For generator methods (paginated), we need to iterate to trigger the exception
            import types
            with pytest.raises((TypeError, ValueError, Exception)):
                result = method()
                # Check if it's a generator (paginated method)
                if isinstance(result, types.GeneratorType):
                    # For generators, exception is raised when iterating
                    next(result)


    def test_get_insights28hr_response_structure(self):
        """Test get_insights28hr response structure validation."""
        with patch.object(self.client, "session") as mock_session:
            # Create mock response with expected structure
            mock_response_data = {
                "data": None,
            }
            mock_response = Mock()
            mock_response.status_code = 200
            mock_response.json.return_value = mock_response_data
            mock_response.raise_for_status.return_value = None
            mock_session.get.return_value = mock_response
            # Prepare minimal valid parameters
            kwargs = {}
            kwargs["tweet_ids"] = ["test"]
            kwargs["granularity"] = "test_value"
            kwargs["requested_metrics"] = ["test"]
            # Add request body if required
            # Call method and verify response structure
            method = getattr(self.posts_client, "get_insights28hr")
            result = method(**kwargs)
            # Verify response object has expected attributes
            # Optional field - just check it doesn't cause errors if accessed
            try:
                getattr(result, "data", None)
            except Exception as e:
                pytest.fail(
                    f"Accessing optional field 'data' should not cause errors: {e}"
                )


    def test_get_liking_users_request_structure(self):
        """Test get_liking_users request structure."""
        # Mock the session to capture request details
        with patch.object(self.client, "session") as mock_session:
            mock_response = Mock()
            mock_response.status_code = 200
            mock_response.json.return_value = {
                "data": None,
            }
            mock_response.raise_for_status.return_value = None
            mock_session.get.return_value = mock_response
            # Prepare test parameters
            kwargs = {}
            # Add required parameters
            kwargs["id"] = "test_value"
            # Add request body if required
            # Call the method
            try:
                method = getattr(self.posts_client, "get_liking_users")
                # Check if this might be a streaming operation by inspecting return type
                import types
                import inspect
                sig = inspect.signature(method)
                return_annotation = str(sig.return_annotation)
                might_be_streaming = (
                    "Generator" in return_annotation or "Iterator" in return_annotation
                )
                # Set up streaming mock if it might be streaming (before calling method)
                if might_be_streaming:
                    mock_streaming_response = Mock()
                    mock_streaming_response.status_code = 200
                    mock_streaming_response.raise_for_status.return_value = None
                    # Make it a proper context manager
                    mock_streaming_response.__enter__ = Mock(
                        return_value=mock_streaming_response
                    )
                    mock_streaming_response.__exit__ = Mock(return_value=None)
                    # Set up iter_content to return an iterator that yields test data
                    # iter_content with decode_unicode=True returns strings, not bytes
                    test_data = '{"data": "test"}\n'
                    # iter_content is called as a method, so we need to make it return an iterator
                    mock_streaming_response.iter_content = Mock(
                        side_effect=lambda *args, **kwargs: iter([test_data])
                    )
                    # Make session.get return the context manager
                    mock_session.get.return_value = mock_streaming_response
                result = method(**kwargs)
                # Check if this is actually a streaming operation (returns Generator)
                is_streaming = isinstance(result, types.GeneratorType)
                if is_streaming:
                    # Consume the generator to trigger the HTTP request
                    # The HTTP request happens when entering the 'with' block inside the generator
                    # We need to actually iterate to trigger the request
                    try:
                        # Try to get first item - this will trigger the HTTP request
                        # The 'with' statement inside the generator will call session.get()
                        next(result)
                    except StopIteration:
                        # Generator exhausted immediately - request was still made
                        pass
                    except (
                        requests.exceptions.RequestException,
                        json.JSONDecodeError,
                        AttributeError,
                        ValueError,
                    ) as e:
                        # These exceptions can occur during streaming (request errors, JSON parsing, etc.)
                        # The request should still have been attempted
                        pass
                    # Don't catch other exceptions - if there's an error during setup (before the request),
                    # we want to know about it, and the request verification below will fail appropriately
                # Verify the request was made
                # For streaming operations, the request happens when entering the 'with' block
                # which occurs when we call next() on the generator
                mock_session.get.assert_called_once()
                # Verify request structure
                call_args = mock_session.get.call_args
                # Check URL structure
                called_url = (
                    call_args[0][0] if call_args[0] else call_args[1].get("url", "")
                )
                expected_path = "/2/tweets/{id}/liking_users"
                assert expected_path.replace("{", "").replace(
                    "}", ""
                ) in called_url or any(
                    param in called_url for param in ["test_", "42"]
                ), f"URL should contain path template elements: {called_url}"
                # Verify response structure
                if is_streaming:
                    # For streaming, verify we got a generator
                    assert isinstance(
                        result, types.GeneratorType
                    ), "Streaming method should return a generator"
                else:
                    # For regular operations, verify we got a result
                    assert result is not None, "Method should return a result"
            except Exception as e:
                pytest.fail(f"Contract test failed for get_liking_users: {e}")


    def test_get_liking_users_required_parameters(self):
        """Test that get_liking_users handles parameters correctly."""
        method = getattr(self.posts_client, "get_liking_users")
        # Test with missing required parameters - mock the request to avoid network calls
        with patch.object(self.client, "session") as mock_session:
            # Mock a 400 response (typical for missing required parameters)
            mock_response = Mock()
            mock_response.status_code = 400
            mock_response.json.return_value = {"error": "Missing required parameters"}
            mock_response.raise_for_status.side_effect = Exception("Bad Request")
            mock_session.get.return_value = mock_response
            # Call without required parameters should either raise locally or via server response
            # For generator methods (paginated), we need to iterate to trigger the exception
            import types
            with pytest.raises((TypeError, ValueError, Exception)):
                result = method()
                # Check if it's a generator (paginated method)
                if isinstance(result, types.GeneratorType):
                    # For generators, exception is raised when iterating
                    next(result)


    def test_get_liking_users_response_structure(self):
        """Test get_liking_users response structure validation."""
        with patch.object(self.client, "session") as mock_session:
            # Create mock response with expected structure
            mock_response_data = {
                "data": None,
            }
            mock_response = Mock()
            mock_response.status_code = 200
            mock_response.json.return_value = mock_response_data
            mock_response.raise_for_status.return_value = None
            mock_session.get.return_value = mock_response
            # Prepare minimal valid parameters
            kwargs = {}
            kwargs["id"] = "test"
            # Add request body if required
            # Call method and verify response structure
            method = getattr(self.posts_client, "get_liking_users")
            result = method(**kwargs)
            # Verify response object has expected attributes
            # Optional field - just check it doesn't cause errors if accessed
            try:
                getattr(result, "data", None)
            except Exception as e:
                pytest.fail(
                    f"Accessing optional field 'data' should not cause errors: {e}"
                )


    def test_search_recent_request_structure(self):
        """Test search_recent request structure."""
        # Mock the session to capture request details
        with patch.object(self.client, "session") as mock_session:
            mock_response = Mock()
            mock_response.status_code = 200
            mock_response.json.return_value = {
                "data": None,
            }
            mock_response.raise_for_status.return_value = None
            mock_session.get.return_value = mock_response
            # Prepare test parameters
            kwargs = {}
            # Add required parameters
            kwargs["query"] = "test_query"
            # Add request body if required
            # Call the method
            try:
                method = getattr(self.posts_client, "search_recent")
                # Check if this might be a streaming operation by inspecting return type
                import types
                import inspect
                sig = inspect.signature(method)
                return_annotation = str(sig.return_annotation)
                might_be_streaming = (
                    "Generator" in return_annotation or "Iterator" in return_annotation
                )
                # Set up streaming mock if it might be streaming (before calling method)
                if might_be_streaming:
                    mock_streaming_response = Mock()
                    mock_streaming_response.status_code = 200
                    mock_streaming_response.raise_for_status.return_value = None
                    # Make it a proper context manager
                    mock_streaming_response.__enter__ = Mock(
                        return_value=mock_streaming_response
                    )
                    mock_streaming_response.__exit__ = Mock(return_value=None)
                    # Set up iter_content to return an iterator that yields test data
                    # iter_content with decode_unicode=True returns strings, not bytes
                    test_data = '{"data": "test"}\n'
                    # iter_content is called as a method, so we need to make it return an iterator
                    mock_streaming_response.iter_content = Mock(
                        side_effect=lambda *args, **kwargs: iter([test_data])
                    )
                    # Make session.get return the context manager
                    mock_session.get.return_value = mock_streaming_response
                result = method(**kwargs)
                # Check if this is actually a streaming operation (returns Generator)
                is_streaming = isinstance(result, types.GeneratorType)
                if is_streaming:
                    # Consume the generator to trigger the HTTP request
                    # The HTTP request happens when entering the 'with' block inside the generator
                    # We need to actually iterate to trigger the request
                    try:
                        # Try to get first item - this will trigger the HTTP request
                        # The 'with' statement inside the generator will call session.get()
                        next(result)
                    except StopIteration:
                        # Generator exhausted immediately - request was still made
                        pass
                    except (
                        requests.exceptions.RequestException,
                        json.JSONDecodeError,
                        AttributeError,
                        ValueError,
                    ) as e:
                        # These exceptions can occur during streaming (request errors, JSON parsing, etc.)
                        # The request should still have been attempted
                        pass
                    # Don't catch other exceptions - if there's an error during setup (before the request),
                    # we want to know about it, and the request verification below will fail appropriately
                # Verify the request was made
                # For streaming operations, the request happens when entering the 'with' block
                # which occurs when we call next() on the generator
                mock_session.get.assert_called_once()
                # Verify request structure
                call_args = mock_session.get.call_args
                # Check URL structure
                called_url = (
                    call_args[0][0] if call_args[0] else call_args[1].get("url", "")
                )
                expected_path = "/2/tweets/search/recent"
                assert expected_path.replace("{", "").replace(
                    "}", ""
                ) in called_url or any(
                    param in called_url for param in ["test_", "42"]
                ), f"URL should contain path template elements: {called_url}"
                # Verify response structure
                if is_streaming:
                    # For streaming, verify we got a generator
                    assert isinstance(
                        result, types.GeneratorType
                    ), "Streaming method should return a generator"
                else:
                    # For regular operations, verify we got a result
                    assert result is not None, "Method should return a result"
            except Exception as e:
                pytest.fail(f"Contract test failed for search_recent: {e}")


    def test_search_recent_required_parameters(self):
        """Test that search_recent handles parameters correctly."""
        method = getattr(self.posts_client, "search_recent")
        # Test with missing required parameters - mock the request to avoid network calls
        with patch.object(self.client, "session") as mock_session:
            # Mock a 400 response (typical for missing required parameters)
            mock_response = Mock()
            mock_response.status_code = 400
            mock_response.json.return_value = {"error": "Missing required parameters"}
            mock_response.raise_for_status.side_effect = Exception("Bad Request")
            mock_session.get.return_value = mock_response
            # Call without required parameters should either raise locally or via server response
            # For generator methods (paginated), we need to iterate to trigger the exception
            import types
            with pytest.raises((TypeError, ValueError, Exception)):
                result = method()
                # Check if it's a generator (paginated method)
                if isinstance(result, types.GeneratorType):
                    # For generators, exception is raised when iterating
                    next(result)


    def test_search_recent_response_structure(self):
        """Test search_recent response structure validation."""
        with patch.object(self.client, "session") as mock_session:
            # Create mock response with expected structure
            mock_response_data = {
                "data": None,
            }
            mock_response = Mock()
            mock_response.status_code = 200
            mock_response.json.return_value = mock_response_data
            mock_response.raise_for_status.return_value = None
            mock_session.get.return_value = mock_response
            # Prepare minimal valid parameters
            kwargs = {}
            kwargs["query"] = "test_value"
            # Add request body if required
            # Call method and verify response structure
            method = getattr(self.posts_client, "search_recent")
            result = method(**kwargs)
            # Verify response object has expected attributes
            # Optional field - just check it doesn't cause errors if accessed
            try:
                getattr(result, "data", None)
            except Exception as e:
                pytest.fail(
                    f"Accessing optional field 'data' should not cause errors: {e}"
                )


    def test_get_quoted_request_structure(self):
        """Test get_quoted request structure."""
        # Mock the session to capture request details
        with patch.object(self.client, "session") as mock_session:
            mock_response = Mock()
            mock_response.status_code = 200
            mock_response.json.return_value = {
                "data": None,
            }
            mock_response.raise_for_status.return_value = None
            mock_session.get.return_value = mock_response
            # Prepare test parameters
            kwargs = {}
            # Add required parameters
            kwargs["id"] = "test_value"
            # Add request body if required
            # Call the method
            try:
                method = getattr(self.posts_client, "get_quoted")
                # Check if this might be a streaming operation by inspecting return type
                import types
                import inspect
                sig = inspect.signature(method)
                return_annotation = str(sig.return_annotation)
                might_be_streaming = (
                    "Generator" in return_annotation or "Iterator" in return_annotation
                )
                # Set up streaming mock if it might be streaming (before calling method)
                if might_be_streaming:
                    mock_streaming_response = Mock()
                    mock_streaming_response.status_code = 200
                    mock_streaming_response.raise_for_status.return_value = None
                    # Make it a proper context manager
                    mock_streaming_response.__enter__ = Mock(
                        return_value=mock_streaming_response
                    )
                    mock_streaming_response.__exit__ = Mock(return_value=None)
                    # Set up iter_content to return an iterator that yields test data
                    # iter_content with decode_unicode=True returns strings, not bytes
                    test_data = '{"data": "test"}\n'
                    # iter_content is called as a method, so we need to make it return an iterator
                    mock_streaming_response.iter_content = Mock(
                        side_effect=lambda *args, **kwargs: iter([test_data])
                    )
                    # Make session.get return the context manager
                    mock_session.get.return_value = mock_streaming_response
                result = method(**kwargs)
                # Check if this is actually a streaming operation (returns Generator)
                is_streaming = isinstance(result, types.GeneratorType)
                if is_streaming:
                    # Consume the generator to trigger the HTTP request
                    # The HTTP request happens when entering the 'with' block inside the generator
                    # We need to actually iterate to trigger the request
                    try:
                        # Try to get first item - this will trigger the HTTP request
                        # The 'with' statement inside the generator will call session.get()
                        next(result)
                    except StopIteration:
                        # Generator exhausted immediately - request was still made
                        pass
                    except (
                        requests.exceptions.RequestException,
                        json.JSONDecodeError,
                        AttributeError,
                        ValueError,
                    ) as e:
                        # These exceptions can occur during streaming (request errors, JSON parsing, etc.)
                        # The request should still have been attempted
                        pass
                    # Don't catch other exceptions - if there's an error during setup (before the request),
                    # we want to know about it, and the request verification below will fail appropriately
                # Verify the request was made
                # For streaming operations, the request happens when entering the 'with' block
                # which occurs when we call next() on the generator
                mock_session.get.assert_called_once()
                # Verify request structure
                call_args = mock_session.get.call_args
                # Check URL structure
                called_url = (
                    call_args[0][0] if call_args[0] else call_args[1].get("url", "")
                )
                expected_path = "/2/tweets/{id}/quote_tweets"
                assert expected_path.replace("{", "").replace(
                    "}", ""
                ) in called_url or any(
                    param in called_url for param in ["test_", "42"]
                ), f"URL should contain path template elements: {called_url}"
                # Verify response structure
                if is_streaming:
                    # For streaming, verify we got a generator
                    assert isinstance(
                        result, types.GeneratorType
                    ), "Streaming method should return a generator"
                else:
                    # For regular operations, verify we got a result
                    assert result is not None, "Method should return a result"
            except Exception as e:
                pytest.fail(f"Contract test failed for get_quoted: {e}")


    def test_get_quoted_required_parameters(self):
        """Test that get_quoted handles parameters correctly."""
        method = getattr(self.posts_client, "get_quoted")
        # Test with missing required parameters - mock the request to avoid network calls
        with patch.object(self.client, "session") as mock_session:
            # Mock a 400 response (typical for missing required parameters)
            mock_response = Mock()
            mock_response.status_code = 400
            mock_response.json.return_value = {"error": "Missing required parameters"}
            mock_response.raise_for_status.side_effect = Exception("Bad Request")
            mock_session.get.return_value = mock_response
            # Call without required parameters should either raise locally or via server response
            # For generator methods (paginated), we need to iterate to trigger the exception
            import types
            with pytest.raises((TypeError, ValueError, Exception)):
                result = method()
                # Check if it's a generator (paginated method)
                if isinstance(result, types.GeneratorType):
                    # For generators, exception is raised when iterating
                    next(result)


    def test_get_quoted_response_structure(self):
        """Test get_quoted response structure validation."""
        with patch.object(self.client, "session") as mock_session:
            # Create mock response with expected structure
            mock_response_data = {
                "data": None,
            }
            mock_response = Mock()
            mock_response.status_code = 200
            mock_response.json.return_value = mock_response_data
            mock_response.raise_for_status.return_value = None
            mock_session.get.return_value = mock_response
            # Prepare minimal valid parameters
            kwargs = {}
            kwargs["id"] = "test"
            # Add request body if required
            # Call method and verify response structure
            method = getattr(self.posts_client, "get_quoted")
            result = method(**kwargs)
            # Verify response object has expected attributes
            # Optional field - just check it doesn't cause errors if accessed
            try:
                getattr(result, "data", None)
            except Exception as e:
                pytest.fail(
                    f"Accessing optional field 'data' should not cause errors: {e}"
                )


    def test_hide_reply_request_structure(self):
        """Test hide_reply request structure."""
        # Mock the session to capture request details
        with patch.object(self.client, "session") as mock_session:
            mock_response = Mock()
            mock_response.status_code = 200
            mock_response.json.return_value = {
                "data": None,
            }
            mock_response.raise_for_status.return_value = None
            mock_session.put.return_value = mock_response
            # Prepare test parameters
            kwargs = {}
            # Add required parameters
            kwargs["tweet_id"] = "test_value"
            # Add request body if required
            # Import and create proper request model instance
            from xdk.posts.models import HideReplyRequest
            # Create instance with minimal valid data (empty instance should work for most cases)
            kwargs["body"] = HideReplyRequest()
            # Call the method
            try:
                method = getattr(self.posts_client, "hide_reply")
                # Check if this might be a streaming operation by inspecting return type
                import types
                import inspect
                sig = inspect.signature(method)
                return_annotation = str(sig.return_annotation)
                might_be_streaming = (
                    "Generator" in return_annotation or "Iterator" in return_annotation
                )
                # Set up streaming mock if it might be streaming (before calling method)
                if might_be_streaming:
                    mock_streaming_response = Mock()
                    mock_streaming_response.status_code = 200
                    mock_streaming_response.raise_for_status.return_value = None
                    # Make it a proper context manager
                    mock_streaming_response.__enter__ = Mock(
                        return_value=mock_streaming_response
                    )
                    mock_streaming_response.__exit__ = Mock(return_value=None)
                    # Set up iter_content to return an iterator that yields test data
                    # iter_content with decode_unicode=True returns strings, not bytes
                    test_data = '{"data": "test"}\n'
                    # iter_content is called as a method, so we need to make it return an iterator
                    mock_streaming_response.iter_content = Mock(
                        side_effect=lambda *args, **kwargs: iter([test_data])
                    )
                    # Make session.get return the context manager
                    mock_session.put.return_value = mock_streaming_response
                result = method(**kwargs)
                # Check if this is actually a streaming operation (returns Generator)
                is_streaming = isinstance(result, types.GeneratorType)
                if is_streaming:
                    # Consume the generator to trigger the HTTP request
                    # The HTTP request happens when entering the 'with' block inside the generator
                    # We need to actually iterate to trigger the request
                    try:
                        # Try to get first item - this will trigger the HTTP request
                        # The 'with' statement inside the generator will call session.get()
                        next(result)
                    except StopIteration:
                        # Generator exhausted immediately - request was still made
                        pass
                    except (
                        requests.exceptions.RequestException,
                        json.JSONDecodeError,
                        AttributeError,
                        ValueError,
                    ) as e:
                        # These exceptions can occur during streaming (request errors, JSON parsing, etc.)
                        # The request should still have been attempted
                        pass
                    # Don't catch other exceptions - if there's an error during setup (before the request),
                    # we want to know about it, and the request verification below will fail appropriately
                # Verify the request was made
                # For streaming operations, the request happens when entering the 'with' block
                # which occurs when we call next() on the generator
                mock_session.put.assert_called_once()
                # Verify request structure
                call_args = mock_session.put.call_args
                # Check URL structure
                called_url = (
                    call_args[0][0] if call_args[0] else call_args[1].get("url", "")
                )
                expected_path = "/2/tweets/{tweet_id}/hidden"
                assert expected_path.replace("{", "").replace(
                    "}", ""
                ) in called_url or any(
                    param in called_url for param in ["test_", "42"]
                ), f"URL should contain path template elements: {called_url}"
                # Verify response structure
                if is_streaming:
                    # For streaming, verify we got a generator
                    assert isinstance(
                        result, types.GeneratorType
                    ), "Streaming method should return a generator"
                else:
                    # For regular operations, verify we got a result
                    assert result is not None, "Method should return a result"
            except Exception as e:
                pytest.fail(f"Contract test failed for hide_reply: {e}")


    def test_hide_reply_required_parameters(self):
        """Test that hide_reply handles parameters correctly."""
        method = getattr(self.posts_client, "hide_reply")
        # Test with missing required parameters - mock the request to avoid network calls
        with patch.object(self.client, "session") as mock_session:
            # Mock a 400 response (typical for missing required parameters)
            mock_response = Mock()
            mock_response.status_code = 400
            mock_response.json.return_value = {"error": "Missing required parameters"}
            mock_response.raise_for_status.side_effect = Exception("Bad Request")
            mock_session.put.return_value = mock_response
            # Call without required parameters should either raise locally or via server response
            # For generator methods (paginated), we need to iterate to trigger the exception
            import types
            with pytest.raises((TypeError, ValueError, Exception)):
                result = method()
                # Check if it's a generator (paginated method)
                if isinstance(result, types.GeneratorType):
                    # For generators, exception is raised when iterating
                    next(result)


    def test_hide_reply_response_structure(self):
        """Test hide_reply response structure validation."""
        with patch.object(self.client, "session") as mock_session:
            # Create mock response with expected structure
            mock_response_data = {
                "data": None,
            }
            mock_response = Mock()
            mock_response.status_code = 200
            mock_response.json.return_value = mock_response_data
            mock_response.raise_for_status.return_value = None
            mock_session.put.return_value = mock_response
            # Prepare minimal valid parameters
            kwargs = {}
            kwargs["tweet_id"] = "test"
            # Add request body if required
            # Import and create proper request model instance
            from xdk.posts.models import HideReplyRequest
            # Create instance with minimal valid data (empty instance should work for most cases)
            kwargs["body"] = HideReplyRequest()
            # Call method and verify response structure
            method = getattr(self.posts_client, "hide_reply")
            result = method(**kwargs)
            # Verify response object has expected attributes
            # Optional field - just check it doesn't cause errors if accessed
            try:
                getattr(result, "data", None)
            except Exception as e:
                pytest.fail(
                    f"Accessing optional field 'data' should not cause errors: {e}"
                )


    def test_get_by_ids_request_structure(self):
        """Test get_by_ids request structure."""
        # Mock the session to capture request details
        with patch.object(self.client, "session") as mock_session:
            mock_response = Mock()
            mock_response.status_code = 200
            mock_response.json.return_value = {
                "data": None,
            }
            mock_response.raise_for_status.return_value = None
            mock_session.get.return_value = mock_response
            # Prepare test parameters
            kwargs = {}
            # Add required parameters
            kwargs["ids"] = ["test_item"]
            # Add request body if required
            # Call the method
            try:
                method = getattr(self.posts_client, "get_by_ids")
                # Check if this might be a streaming operation by inspecting return type
                import types
                import inspect
                sig = inspect.signature(method)
                return_annotation = str(sig.return_annotation)
                might_be_streaming = (
                    "Generator" in return_annotation or "Iterator" in return_annotation
                )
                # Set up streaming mock if it might be streaming (before calling method)
                if might_be_streaming:
                    mock_streaming_response = Mock()
                    mock_streaming_response.status_code = 200
                    mock_streaming_response.raise_for_status.return_value = None
                    # Make it a proper context manager
                    mock_streaming_response.__enter__ = Mock(
                        return_value=mock_streaming_response
                    )
                    mock_streaming_response.__exit__ = Mock(return_value=None)
                    # Set up iter_content to return an iterator that yields test data
                    # iter_content with decode_unicode=True returns strings, not bytes
                    test_data = '{"data": "test"}\n'
                    # iter_content is called as a method, so we need to make it return an iterator
                    mock_streaming_response.iter_content = Mock(
                        side_effect=lambda *args, **kwargs: iter([test_data])
                    )
                    # Make session.get return the context manager
                    mock_session.get.return_value = mock_streaming_response
                result = method(**kwargs)
                # Check if this is actually a streaming operation (returns Generator)
                is_streaming = isinstance(result, types.GeneratorType)
                if is_streaming:
                    # Consume the generator to trigger the HTTP request
                    # The HTTP request happens when entering the 'with' block inside the generator
                    # We need to actually iterate to trigger the request
                    try:
                        # Try to get first item - this will trigger the HTTP request
                        # The 'with' statement inside the generator will call session.get()
                        next(result)
                    except StopIteration:
                        # Generator exhausted immediately - request was still made
                        pass
                    except (
                        requests.exceptions.RequestException,
                        json.JSONDecodeError,
                        AttributeError,
                        ValueError,
                    ) as e:
                        # These exceptions can occur during streaming (request errors, JSON parsing, etc.)
                        # The request should still have been attempted
                        pass
                    # Don't catch other exceptions - if there's an error during setup (before the request),
                    # we want to know about it, and the request verification below will fail appropriately
                # Verify the request was made
                # For streaming operations, the request happens when entering the 'with' block
                # which occurs when we call next() on the generator
                mock_session.get.assert_called_once()
                # Verify request structure
                call_args = mock_session.get.call_args
                # Check URL structure
                called_url = (
                    call_args[0][0] if call_args[0] else call_args[1].get("url", "")
                )
                expected_path = "/2/tweets"
                assert expected_path.replace("{", "").replace(
                    "}", ""
                ) in called_url or any(
                    param in called_url for param in ["test_", "42"]
                ), f"URL should contain path template elements: {called_url}"
                # Verify response structure
                if is_streaming:
                    # For streaming, verify we got a generator
                    assert isinstance(
                        result, types.GeneratorType
                    ), "Streaming method should return a generator"
                else:
                    # For regular operations, verify we got a result
                    assert result is not None, "Method should return a result"
            except Exception as e:
                pytest.fail(f"Contract test failed for get_by_ids: {e}")


    def test_get_by_ids_required_parameters(self):
        """Test that get_by_ids handles parameters correctly."""
        method = getattr(self.posts_client, "get_by_ids")
        # Test with missing required parameters - mock the request to avoid network calls
        with patch.object(self.client, "session") as mock_session:
            # Mock a 400 response (typical for missing required parameters)
            mock_response = Mock()
            mock_response.status_code = 400
            mock_response.json.return_value = {"error": "Missing required parameters"}
            mock_response.raise_for_status.side_effect = Exception("Bad Request")
            mock_session.get.return_value = mock_response
            # Call without required parameters should either raise locally or via server response
            # For generator methods (paginated), we need to iterate to trigger the exception
            import types
            with pytest.raises((TypeError, ValueError, Exception)):
                result = method()
                # Check if it's a generator (paginated method)
                if isinstance(result, types.GeneratorType):
                    # For generators, exception is raised when iterating
                    next(result)


    def test_get_by_ids_response_structure(self):
        """Test get_by_ids response structure validation."""
        with patch.object(self.client, "session") as mock_session:
            # Create mock response with expected structure
            mock_response_data = {
                "data": None,
            }
            mock_response = Mock()
            mock_response.status_code = 200
            mock_response.json.return_value = mock_response_data
            mock_response.raise_for_status.return_value = None
            mock_session.get.return_value = mock_response
            # Prepare minimal valid parameters
            kwargs = {}
            kwargs["ids"] = ["test"]
            # Add request body if required
            # Call method and verify response structure
            method = getattr(self.posts_client, "get_by_ids")
            result = method(**kwargs)
            # Verify response object has expected attributes
            # Optional field - just check it doesn't cause errors if accessed
            try:
                getattr(result, "data", None)
            except Exception as e:
                pytest.fail(
                    f"Accessing optional field 'data' should not cause errors: {e}"
                )


    def test_create_request_structure(self):
        """Test create request structure."""
        # Mock the session to capture request details
        with patch.object(self.client, "session") as mock_session:
            mock_response = Mock()
            mock_response.status_code = 201
            mock_response.json.return_value = {
                "data": None,
            }
            mock_response.raise_for_status.return_value = None
            mock_session.post.return_value = mock_response
            # Prepare test parameters
            kwargs = {}
            # Add required parameters
            # Add request body if required
            # Import and create proper request model instance
            from xdk.posts.models import CreateRequest
            # Create instance with minimal valid data (empty instance should work for most cases)
            kwargs["body"] = CreateRequest()
            # Call the method
            try:
                method = getattr(self.posts_client, "create")
                # Check if this might be a streaming operation by inspecting return type
                import types
                import inspect
                sig = inspect.signature(method)
                return_annotation = str(sig.return_annotation)
                might_be_streaming = (
                    "Generator" in return_annotation or "Iterator" in return_annotation
                )
                # Set up streaming mock if it might be streaming (before calling method)
                if might_be_streaming:
                    mock_streaming_response = Mock()
                    mock_streaming_response.status_code = 201
                    mock_streaming_response.raise_for_status.return_value = None
                    # Make it a proper context manager
                    mock_streaming_response.__enter__ = Mock(
                        return_value=mock_streaming_response
                    )
                    mock_streaming_response.__exit__ = Mock(return_value=None)
                    # Set up iter_content to return an iterator that yields test data
                    # iter_content with decode_unicode=True returns strings, not bytes
                    test_data = '{"data": "test"}\n'
                    # iter_content is called as a method, so we need to make it return an iterator
                    mock_streaming_response.iter_content = Mock(
                        side_effect=lambda *args, **kwargs: iter([test_data])
                    )
                    # Make session.get return the context manager
                    mock_session.post.return_value = mock_streaming_response
                result = method(**kwargs)
                # Check if this is actually a streaming operation (returns Generator)
                is_streaming = isinstance(result, types.GeneratorType)
                if is_streaming:
                    # Consume the generator to trigger the HTTP request
                    # The HTTP request happens when entering the 'with' block inside the generator
                    # We need to actually iterate to trigger the request
                    try:
                        # Try to get first item - this will trigger the HTTP request
                        # The 'with' statement inside the generator will call session.get()
                        next(result)
                    except StopIteration:
                        # Generator exhausted immediately - request was still made
                        pass
                    except (
                        requests.exceptions.RequestException,
                        json.JSONDecodeError,
                        AttributeError,
                        ValueError,
                    ) as e:
                        # These exceptions can occur during streaming (request errors, JSON parsing, etc.)
                        # The request should still have been attempted
                        pass
                    # Don't catch other exceptions - if there's an error during setup (before the request),
                    # we want to know about it, and the request verification below will fail appropriately
                # Verify the request was made
                # For streaming operations, the request happens when entering the 'with' block
                # which occurs when we call next() on the generator
                mock_session.post.assert_called_once()
                # Verify request structure
                call_args = mock_session.post.call_args
                # Check URL structure
                called_url = (
                    call_args[0][0] if call_args[0] else call_args[1].get("url", "")
                )
                expected_path = "/2/tweets"
                assert expected_path.replace("{", "").replace(
                    "}", ""
                ) in called_url or any(
                    param in called_url for param in ["test_", "42"]
                ), f"URL should contain path template elements: {called_url}"
                # Verify response structure
                if is_streaming:
                    # For streaming, verify we got a generator
                    assert isinstance(
                        result, types.GeneratorType
                    ), "Streaming method should return a generator"
                else:
                    # For regular operations, verify we got a result
                    assert result is not None, "Method should return a result"
            except Exception as e:
                pytest.fail(f"Contract test failed for create: {e}")


    def test_create_required_parameters(self):
        """Test that create handles parameters correctly."""
        method = getattr(self.posts_client, "create")
        # Test with missing required parameters - mock the request to avoid network calls
        with patch.object(self.client, "session") as mock_session:
            # Mock a 400 response (typical for missing required parameters)
            mock_response = Mock()
            mock_response.status_code = 400
            mock_response.json.return_value = {"error": "Missing required parameters"}
            mock_response.raise_for_status.side_effect = Exception("Bad Request")
            mock_session.post.return_value = mock_response
            # Call without required parameters should either raise locally or via server response
            # For generator methods (paginated), we need to iterate to trigger the exception
            import types
            with pytest.raises((TypeError, ValueError, Exception)):
                result = method()
                # Check if it's a generator (paginated method)
                if isinstance(result, types.GeneratorType):
                    # For generators, exception is raised when iterating
                    next(result)


    def test_create_response_structure(self):
        """Test create response structure validation."""
        with patch.object(self.client, "session") as mock_session:
            # Create mock response with expected structure
            mock_response_data = {
                "data": None,
            }
            mock_response = Mock()
            mock_response.status_code = 201
            mock_response.json.return_value = mock_response_data
            mock_response.raise_for_status.return_value = None
            mock_session.post.return_value = mock_response
            # Prepare minimal valid parameters
            kwargs = {}
            # Add request body if required
            # Import and create proper request model instance
            from xdk.posts.models import CreateRequest
            # Create instance with minimal valid data (empty instance should work for most cases)
            kwargs["body"] = CreateRequest()
            # Call method and verify response structure
            method = getattr(self.posts_client, "create")
            result = method(**kwargs)
            # Verify response object has expected attributes
            # Optional field - just check it doesn't cause errors if accessed
            try:
                getattr(result, "data", None)
            except Exception as e:
                pytest.fail(
                    f"Accessing optional field 'data' should not cause errors: {e}"
                )


    def test_get_insights_historical_request_structure(self):
        """Test get_insights_historical request structure."""
        # Mock the session to capture request details
        with patch.object(self.client, "session") as mock_session:
            mock_response = Mock()
            mock_response.status_code = 200
            mock_response.json.return_value = {
                "data": None,
            }
            mock_response.raise_for_status.return_value = None
            mock_session.get.return_value = mock_response
            # Prepare test parameters
            kwargs = {}
            # Add required parameters
            kwargs["tweet_ids"] = ["test_item"]
            kwargs["end_time"] = "test_end_time"
            kwargs["start_time"] = "test_start_time"
            kwargs["granularity"] = "test_granularity"
            kwargs["requested_metrics"] = ["test_item"]
            # Add request body if required
            # Call the method
            try:
                method = getattr(self.posts_client, "get_insights_historical")
                # Check if this might be a streaming operation by inspecting return type
                import types
                import inspect
                sig = inspect.signature(method)
                return_annotation = str(sig.return_annotation)
                might_be_streaming = (
                    "Generator" in return_annotation or "Iterator" in return_annotation
                )
                # Set up streaming mock if it might be streaming (before calling method)
                if might_be_streaming:
                    mock_streaming_response = Mock()
                    mock_streaming_response.status_code = 200
                    mock_streaming_response.raise_for_status.return_value = None
                    # Make it a proper context manager
                    mock_streaming_response.__enter__ = Mock(
                        return_value=mock_streaming_response
                    )
                    mock_streaming_response.__exit__ = Mock(return_value=None)
                    # Set up iter_content to return an iterator that yields test data
                    # iter_content with decode_unicode=True returns strings, not bytes
                    test_data = '{"data": "test"}\n'
                    # iter_content is called as a method, so we need to make it return an iterator
                    mock_streaming_response.iter_content = Mock(
                        side_effect=lambda *args, **kwargs: iter([test_data])
                    )
                    # Make session.get return the context manager
                    mock_session.get.return_value = mock_streaming_response
                result = method(**kwargs)
                # Check if this is actually a streaming operation (returns Generator)
                is_streaming = isinstance(result, types.GeneratorType)
                if is_streaming:
                    # Consume the generator to trigger the HTTP request
                    # The HTTP request happens when entering the 'with' block inside the generator
                    # We need to actually iterate to trigger the request
                    try:
                        # Try to get first item - this will trigger the HTTP request
                        # The 'with' statement inside the generator will call session.get()
                        next(result)
                    except StopIteration:
                        # Generator exhausted immediately - request was still made
                        pass
                    except (
                        requests.exceptions.RequestException,
                        json.JSONDecodeError,
                        AttributeError,
                        ValueError,
                    ) as e:
                        # These exceptions can occur during streaming (request errors, JSON parsing, etc.)
                        # The request should still have been attempted
                        pass
                    # Don't catch other exceptions - if there's an error during setup (before the request),
                    # we want to know about it, and the request verification below will fail appropriately
                # Verify the request was made
                # For streaming operations, the request happens when entering the 'with' block
                # which occurs when we call next() on the generator
                mock_session.get.assert_called_once()
                # Verify request structure
                call_args = mock_session.get.call_args
                # Check URL structure
                called_url = (
                    call_args[0][0] if call_args[0] else call_args[1].get("url", "")
                )
                expected_path = "/2/insights/historical"
                assert expected_path.replace("{", "").replace(
                    "}", ""
                ) in called_url or any(
                    param in called_url for param in ["test_", "42"]
                ), f"URL should contain path template elements: {called_url}"
                # Verify response structure
                if is_streaming:
                    # For streaming, verify we got a generator
                    assert isinstance(
                        result, types.GeneratorType
                    ), "Streaming method should return a generator"
                else:
                    # For regular operations, verify we got a result
                    assert result is not None, "Method should return a result"
            except Exception as e:
                pytest.fail(f"Contract test failed for get_insights_historical: {e}")


    def test_get_insights_historical_required_parameters(self):
        """Test that get_insights_historical handles parameters correctly."""
        method = getattr(self.posts_client, "get_insights_historical")
        # Test with missing required parameters - mock the request to avoid network calls
        with patch.object(self.client, "session") as mock_session:
            # Mock a 400 response (typical for missing required parameters)
            mock_response = Mock()
            mock_response.status_code = 400
            mock_response.json.return_value = {"error": "Missing required parameters"}
            mock_response.raise_for_status.side_effect = Exception("Bad Request")
            mock_session.get.return_value = mock_response
            # Call without required parameters should either raise locally or via server response
            # For generator methods (paginated), we need to iterate to trigger the exception
            import types
            with pytest.raises((TypeError, ValueError, Exception)):
                result = method()
                # Check if it's a generator (paginated method)
                if isinstance(result, types.GeneratorType):
                    # For generators, exception is raised when iterating
                    next(result)


    def test_get_insights_historical_response_structure(self):
        """Test get_insights_historical response structure validation."""
        with patch.object(self.client, "session") as mock_session:
            # Create mock response with expected structure
            mock_response_data = {
                "data": None,
            }
            mock_response = Mock()
            mock_response.status_code = 200
            mock_response.json.return_value = mock_response_data
            mock_response.raise_for_status.return_value = None
            mock_session.get.return_value = mock_response
            # Prepare minimal valid parameters
            kwargs = {}
            kwargs["tweet_ids"] = ["test"]
            kwargs["end_time"] = "test_value"
            kwargs["start_time"] = "test_value"
            kwargs["granularity"] = "test_value"
            kwargs["requested_metrics"] = ["test"]
            # Add request body if required
            # Call method and verify response structure
            method = getattr(self.posts_client, "get_insights_historical")
            result = method(**kwargs)
            # Verify response object has expected attributes
            # Optional field - just check it doesn't cause errors if accessed
            try:
                getattr(result, "data", None)
            except Exception as e:
                pytest.fail(
                    f"Accessing optional field 'data' should not cause errors: {e}"
                )


    def test_get_counts_recent_request_structure(self):
        """Test get_counts_recent request structure."""
        # Mock the session to capture request details
        with patch.object(self.client, "session") as mock_session:
            mock_response = Mock()
            mock_response.status_code = 200
            mock_response.json.return_value = {
                "data": None,
            }
            mock_response.raise_for_status.return_value = None
            mock_session.get.return_value = mock_response
            # Prepare test parameters
            kwargs = {}
            # Add required parameters
            kwargs["query"] = "test_query"
            # Add request body if required
            # Call the method
            try:
                method = getattr(self.posts_client, "get_counts_recent")
                # Check if this might be a streaming operation by inspecting return type
                import types
                import inspect
                sig = inspect.signature(method)
                return_annotation = str(sig.return_annotation)
                might_be_streaming = (
                    "Generator" in return_annotation or "Iterator" in return_annotation
                )
                # Set up streaming mock if it might be streaming (before calling method)
                if might_be_streaming:
                    mock_streaming_response = Mock()
                    mock_streaming_response.status_code = 200
                    mock_streaming_response.raise_for_status.return_value = None
                    # Make it a proper context manager
                    mock_streaming_response.__enter__ = Mock(
                        return_value=mock_streaming_response
                    )
                    mock_streaming_response.__exit__ = Mock(return_value=None)
                    # Set up iter_content to return an iterator that yields test data
                    # iter_content with decode_unicode=True returns strings, not bytes
                    test_data = '{"data": "test"}\n'
                    # iter_content is called as a method, so we need to make it return an iterator
                    mock_streaming_response.iter_content = Mock(
                        side_effect=lambda *args, **kwargs: iter([test_data])
                    )
                    # Make session.get return the context manager
                    mock_session.get.return_value = mock_streaming_response
                result = method(**kwargs)
                # Check if this is actually a streaming operation (returns Generator)
                is_streaming = isinstance(result, types.GeneratorType)
                if is_streaming:
                    # Consume the generator to trigger the HTTP request
                    # The HTTP request happens when entering the 'with' block inside the generator
                    # We need to actually iterate to trigger the request
                    try:
                        # Try to get first item - this will trigger the HTTP request
                        # The 'with' statement inside the generator will call session.get()
                        next(result)
                    except StopIteration:
                        # Generator exhausted immediately - request was still made
                        pass
                    except (
                        requests.exceptions.RequestException,
                        json.JSONDecodeError,
                        AttributeError,
                        ValueError,
                    ) as e:
                        # These exceptions can occur during streaming (request errors, JSON parsing, etc.)
                        # The request should still have been attempted
                        pass
                    # Don't catch other exceptions - if there's an error during setup (before the request),
                    # we want to know about it, and the request verification below will fail appropriately
                # Verify the request was made
                # For streaming operations, the request happens when entering the 'with' block
                # which occurs when we call next() on the generator
                mock_session.get.assert_called_once()
                # Verify request structure
                call_args = mock_session.get.call_args
                # Check URL structure
                called_url = (
                    call_args[0][0] if call_args[0] else call_args[1].get("url", "")
                )
                expected_path = "/2/tweets/counts/recent"
                assert expected_path.replace("{", "").replace(
                    "}", ""
                ) in called_url or any(
                    param in called_url for param in ["test_", "42"]
                ), f"URL should contain path template elements: {called_url}"
                # Verify response structure
                if is_streaming:
                    # For streaming, verify we got a generator
                    assert isinstance(
                        result, types.GeneratorType
                    ), "Streaming method should return a generator"
                else:
                    # For regular operations, verify we got a result
                    assert result is not None, "Method should return a result"
            except Exception as e:
                pytest.fail(f"Contract test failed for get_counts_recent: {e}")


    def test_get_counts_recent_required_parameters(self):
        """Test that get_counts_recent handles parameters correctly."""
        method = getattr(self.posts_client, "get_counts_recent")
        # Test with missing required parameters - mock the request to avoid network calls
        with patch.object(self.client, "session") as mock_session:
            # Mock a 400 response (typical for missing required parameters)
            mock_response = Mock()
            mock_response.status_code = 400
            mock_response.json.return_value = {"error": "Missing required parameters"}
            mock_response.raise_for_status.side_effect = Exception("Bad Request")
            mock_session.get.return_value = mock_response
            # Call without required parameters should either raise locally or via server response
            # For generator methods (paginated), we need to iterate to trigger the exception
            import types
            with pytest.raises((TypeError, ValueError, Exception)):
                result = method()
                # Check if it's a generator (paginated method)
                if isinstance(result, types.GeneratorType):
                    # For generators, exception is raised when iterating
                    next(result)


    def test_get_counts_recent_response_structure(self):
        """Test get_counts_recent response structure validation."""
        with patch.object(self.client, "session") as mock_session:
            # Create mock response with expected structure
            mock_response_data = {
                "data": None,
            }
            mock_response = Mock()
            mock_response.status_code = 200
            mock_response.json.return_value = mock_response_data
            mock_response.raise_for_status.return_value = None
            mock_session.get.return_value = mock_response
            # Prepare minimal valid parameters
            kwargs = {}
            kwargs["query"] = "test_value"
            # Add request body if required
            # Call method and verify response structure
            method = getattr(self.posts_client, "get_counts_recent")
            result = method(**kwargs)
            # Verify response object has expected attributes
            # Optional field - just check it doesn't cause errors if accessed
            try:
                getattr(result, "data", None)
            except Exception as e:
                pytest.fail(
                    f"Accessing optional field 'data' should not cause errors: {e}"
                )


    def test_get_reposted_by_request_structure(self):
        """Test get_reposted_by request structure."""
        # Mock the session to capture request details
        with patch.object(self.client, "session") as mock_session:
            mock_response = Mock()
            mock_response.status_code = 200
            mock_response.json.return_value = {
                "data": None,
            }
            mock_response.raise_for_status.return_value = None
            mock_session.get.return_value = mock_response
            # Prepare test parameters
            kwargs = {}
            # Add required parameters
            kwargs["id"] = "test_value"
            # Add request body if required
            # Call the method
            try:
                method = getattr(self.posts_client, "get_reposted_by")
                # Check if this might be a streaming operation by inspecting return type
                import types
                import inspect
                sig = inspect.signature(method)
                return_annotation = str(sig.return_annotation)
                might_be_streaming = (
                    "Generator" in return_annotation or "Iterator" in return_annotation
                )
                # Set up streaming mock if it might be streaming (before calling method)
                if might_be_streaming:
                    mock_streaming_response = Mock()
                    mock_streaming_response.status_code = 200
                    mock_streaming_response.raise_for_status.return_value = None
                    # Make it a proper context manager
                    mock_streaming_response.__enter__ = Mock(
                        return_value=mock_streaming_response
                    )
                    mock_streaming_response.__exit__ = Mock(return_value=None)
                    # Set up iter_content to return an iterator that yields test data
                    # iter_content with decode_unicode=True returns strings, not bytes
                    test_data = '{"data": "test"}\n'
                    # iter_content is called as a method, so we need to make it return an iterator
                    mock_streaming_response.iter_content = Mock(
                        side_effect=lambda *args, **kwargs: iter([test_data])
                    )
                    # Make session.get return the context manager
                    mock_session.get.return_value = mock_streaming_response
                result = method(**kwargs)
                # Check if this is actually a streaming operation (returns Generator)
                is_streaming = isinstance(result, types.GeneratorType)
                if is_streaming:
                    # Consume the generator to trigger the HTTP request
                    # The HTTP request happens when entering the 'with' block inside the generator
                    # We need to actually iterate to trigger the request
                    try:
                        # Try to get first item - this will trigger the HTTP request
                        # The 'with' statement inside the generator will call session.get()
                        next(result)
                    except StopIteration:
                        # Generator exhausted immediately - request was still made
                        pass
                    except (
                        requests.exceptions.RequestException,
                        json.JSONDecodeError,
                        AttributeError,
                        ValueError,
                    ) as e:
                        # These exceptions can occur during streaming (request errors, JSON parsing, etc.)
                        # The request should still have been attempted
                        pass
                    # Don't catch other exceptions - if there's an error during setup (before the request),
                    # we want to know about it, and the request verification below will fail appropriately
                # Verify the request was made
                # For streaming operations, the request happens when entering the 'with' block
                # which occurs when we call next() on the generator
                mock_session.get.assert_called_once()
                # Verify request structure
                call_args = mock_session.get.call_args
                # Check URL structure
                called_url = (
                    call_args[0][0] if call_args[0] else call_args[1].get("url", "")
                )
                expected_path = "/2/tweets/{id}/retweeted_by"
                assert expected_path.replace("{", "").replace(
                    "}", ""
                ) in called_url or any(
                    param in called_url for param in ["test_", "42"]
                ), f"URL should contain path template elements: {called_url}"
                # Verify response structure
                if is_streaming:
                    # For streaming, verify we got a generator
                    assert isinstance(
                        result, types.GeneratorType
                    ), "Streaming method should return a generator"
                else:
                    # For regular operations, verify we got a result
                    assert result is not None, "Method should return a result"
            except Exception as e:
                pytest.fail(f"Contract test failed for get_reposted_by: {e}")


    def test_get_reposted_by_required_parameters(self):
        """Test that get_reposted_by handles parameters correctly."""
        method = getattr(self.posts_client, "get_reposted_by")
        # Test with missing required parameters - mock the request to avoid network calls
        with patch.object(self.client, "session") as mock_session:
            # Mock a 400 response (typical for missing required parameters)
            mock_response = Mock()
            mock_response.status_code = 400
            mock_response.json.return_value = {"error": "Missing required parameters"}
            mock_response.raise_for_status.side_effect = Exception("Bad Request")
            mock_session.get.return_value = mock_response
            # Call without required parameters should either raise locally or via server response
            # For generator methods (paginated), we need to iterate to trigger the exception
            import types
            with pytest.raises((TypeError, ValueError, Exception)):
                result = method()
                # Check if it's a generator (paginated method)
                if isinstance(result, types.GeneratorType):
                    # For generators, exception is raised when iterating
                    next(result)


    def test_get_reposted_by_response_structure(self):
        """Test get_reposted_by response structure validation."""
        with patch.object(self.client, "session") as mock_session:
            # Create mock response with expected structure
            mock_response_data = {
                "data": None,
            }
            mock_response = Mock()
            mock_response.status_code = 200
            mock_response.json.return_value = mock_response_data
            mock_response.raise_for_status.return_value = None
            mock_session.get.return_value = mock_response
            # Prepare minimal valid parameters
            kwargs = {}
            kwargs["id"] = "test"
            # Add request body if required
            # Call method and verify response structure
            method = getattr(self.posts_client, "get_reposted_by")
            result = method(**kwargs)
            # Verify response object has expected attributes
            # Optional field - just check it doesn't cause errors if accessed
            try:
                getattr(result, "data", None)
            except Exception as e:
                pytest.fail(
                    f"Accessing optional field 'data' should not cause errors: {e}"
                )


    def test_get_analytics_request_structure(self):
        """Test get_analytics request structure."""
        # Mock the session to capture request details
        with patch.object(self.client, "session") as mock_session:
            mock_response = Mock()
            mock_response.status_code = 200
            mock_response.json.return_value = {
                "data": None,
            }
            mock_response.raise_for_status.return_value = None
            mock_session.get.return_value = mock_response
            # Prepare test parameters
            kwargs = {}
            # Add required parameters
            kwargs["ids"] = ["test_item"]
            kwargs["end_time"] = "test_end_time"
            kwargs["start_time"] = "test_start_time"
            kwargs["granularity"] = "test_granularity"
            # Add request body if required
            # Call the method
            try:
                method = getattr(self.posts_client, "get_analytics")
                # Check if this might be a streaming operation by inspecting return type
                import types
                import inspect
                sig = inspect.signature(method)
                return_annotation = str(sig.return_annotation)
                might_be_streaming = (
                    "Generator" in return_annotation or "Iterator" in return_annotation
                )
                # Set up streaming mock if it might be streaming (before calling method)
                if might_be_streaming:
                    mock_streaming_response = Mock()
                    mock_streaming_response.status_code = 200
                    mock_streaming_response.raise_for_status.return_value = None
                    # Make it a proper context manager
                    mock_streaming_response.__enter__ = Mock(
                        return_value=mock_streaming_response
                    )
                    mock_streaming_response.__exit__ = Mock(return_value=None)
                    # Set up iter_content to return an iterator that yields test data
                    # iter_content with decode_unicode=True returns strings, not bytes
                    test_data = '{"data": "test"}\n'
                    # iter_content is called as a method, so we need to make it return an iterator
                    mock_streaming_response.iter_content = Mock(
                        side_effect=lambda *args, **kwargs: iter([test_data])
                    )
                    # Make session.get return the context manager
                    mock_session.get.return_value = mock_streaming_response
                result = method(**kwargs)
                # Check if this is actually a streaming operation (returns Generator)
                is_streaming = isinstance(result, types.GeneratorType)
                if is_streaming:
                    # Consume the generator to trigger the HTTP request
                    # The HTTP request happens when entering the 'with' block inside the generator
                    # We need to actually iterate to trigger the request
                    try:
                        # Try to get first item - this will trigger the HTTP request
                        # The 'with' statement inside the generator will call session.get()
                        next(result)
                    except StopIteration:
                        # Generator exhausted immediately - request was still made
                        pass
                    except (
                        requests.exceptions.RequestException,
                        json.JSONDecodeError,
                        AttributeError,
                        ValueError,
                    ) as e:
                        # These exceptions can occur during streaming (request errors, JSON parsing, etc.)
                        # The request should still have been attempted
                        pass
                    # Don't catch other exceptions - if there's an error during setup (before the request),
                    # we want to know about it, and the request verification below will fail appropriately
                # Verify the request was made
                # For streaming operations, the request happens when entering the 'with' block
                # which occurs when we call next() on the generator
                mock_session.get.assert_called_once()
                # Verify request structure
                call_args = mock_session.get.call_args
                # Check URL structure
                called_url = (
                    call_args[0][0] if call_args[0] else call_args[1].get("url", "")
                )
                expected_path = "/2/tweets/analytics"
                assert expected_path.replace("{", "").replace(
                    "}", ""
                ) in called_url or any(
                    param in called_url for param in ["test_", "42"]
                ), f"URL should contain path template elements: {called_url}"
                # Verify response structure
                if is_streaming:
                    # For streaming, verify we got a generator
                    assert isinstance(
                        result, types.GeneratorType
                    ), "Streaming method should return a generator"
                else:
                    # For regular operations, verify we got a result
                    assert result is not None, "Method should return a result"
            except Exception as e:
                pytest.fail(f"Contract test failed for get_analytics: {e}")


    def test_get_analytics_required_parameters(self):
        """Test that get_analytics handles parameters correctly."""
        method = getattr(self.posts_client, "get_analytics")
        # Test with missing required parameters - mock the request to avoid network calls
        with patch.object(self.client, "session") as mock_session:
            # Mock a 400 response (typical for missing required parameters)
            mock_response = Mock()
            mock_response.status_code = 400
            mock_response.json.return_value = {"error": "Missing required parameters"}
            mock_response.raise_for_status.side_effect = Exception("Bad Request")
            mock_session.get.return_value = mock_response
            # Call without required parameters should either raise locally or via server response
            # For generator methods (paginated), we need to iterate to trigger the exception
            import types
            with pytest.raises((TypeError, ValueError, Exception)):
                result = method()
                # Check if it's a generator (paginated method)
                if isinstance(result, types.GeneratorType):
                    # For generators, exception is raised when iterating
                    next(result)


    def test_get_analytics_response_structure(self):
        """Test get_analytics response structure validation."""
        with patch.object(self.client, "session") as mock_session:
            # Create mock response with expected structure
            mock_response_data = {
                "data": None,
            }
            mock_response = Mock()
            mock_response.status_code = 200
            mock_response.json.return_value = mock_response_data
            mock_response.raise_for_status.return_value = None
            mock_session.get.return_value = mock_response
            # Prepare minimal valid parameters
            kwargs = {}
            kwargs["ids"] = ["test"]
            kwargs["end_time"] = "test_value"
            kwargs["start_time"] = "test_value"
            kwargs["granularity"] = "test_value"
            # Add request body if required
            # Call method and verify response structure
            method = getattr(self.posts_client, "get_analytics")
            result = method(**kwargs)
            # Verify response object has expected attributes
            # Optional field - just check it doesn't cause errors if accessed
            try:
                getattr(result, "data", None)
            except Exception as e:
                pytest.fail(
                    f"Accessing optional field 'data' should not cause errors: {e}"
                )


    def test_get_counts_all_request_structure(self):
        """Test get_counts_all request structure."""
        # Mock the session to capture request details
        with patch.object(self.client, "session") as mock_session:
            mock_response = Mock()
            mock_response.status_code = 200
            mock_response.json.return_value = {
                "data": None,
            }
            mock_response.raise_for_status.return_value = None
            mock_session.get.return_value = mock_response
            # Prepare test parameters
            kwargs = {}
            # Add required parameters
            kwargs["query"] = "test_query"
            # Add request body if required
            # Call the method
            try:
                method = getattr(self.posts_client, "get_counts_all")
                # Check if this might be a streaming operation by inspecting return type
                import types
                import inspect
                sig = inspect.signature(method)
                return_annotation = str(sig.return_annotation)
                might_be_streaming = (
                    "Generator" in return_annotation or "Iterator" in return_annotation
                )
                # Set up streaming mock if it might be streaming (before calling method)
                if might_be_streaming:
                    mock_streaming_response = Mock()
                    mock_streaming_response.status_code = 200
                    mock_streaming_response.raise_for_status.return_value = None
                    # Make it a proper context manager
                    mock_streaming_response.__enter__ = Mock(
                        return_value=mock_streaming_response
                    )
                    mock_streaming_response.__exit__ = Mock(return_value=None)
                    # Set up iter_content to return an iterator that yields test data
                    # iter_content with decode_unicode=True returns strings, not bytes
                    test_data = '{"data": "test"}\n'
                    # iter_content is called as a method, so we need to make it return an iterator
                    mock_streaming_response.iter_content = Mock(
                        side_effect=lambda *args, **kwargs: iter([test_data])
                    )
                    # Make session.get return the context manager
                    mock_session.get.return_value = mock_streaming_response
                result = method(**kwargs)
                # Check if this is actually a streaming operation (returns Generator)
                is_streaming = isinstance(result, types.GeneratorType)
                if is_streaming:
                    # Consume the generator to trigger the HTTP request
                    # The HTTP request happens when entering the 'with' block inside the generator
                    # We need to actually iterate to trigger the request
                    try:
                        # Try to get first item - this will trigger the HTTP request
                        # The 'with' statement inside the generator will call session.get()
                        next(result)
                    except StopIteration:
                        # Generator exhausted immediately - request was still made
                        pass
                    except (
                        requests.exceptions.RequestException,
                        json.JSONDecodeError,
                        AttributeError,
                        ValueError,
                    ) as e:
                        # These exceptions can occur during streaming (request errors, JSON parsing, etc.)
                        # The request should still have been attempted
                        pass
                    # Don't catch other exceptions - if there's an error during setup (before the request),
                    # we want to know about it, and the request verification below will fail appropriately
                # Verify the request was made
                # For streaming operations, the request happens when entering the 'with' block
                # which occurs when we call next() on the generator
                mock_session.get.assert_called_once()
                # Verify request structure
                call_args = mock_session.get.call_args
                # Check URL structure
                called_url = (
                    call_args[0][0] if call_args[0] else call_args[1].get("url", "")
                )
                expected_path = "/2/tweets/counts/all"
                assert expected_path.replace("{", "").replace(
                    "}", ""
                ) in called_url or any(
                    param in called_url for param in ["test_", "42"]
                ), f"URL should contain path template elements: {called_url}"
                # Verify response structure
                if is_streaming:
                    # For streaming, verify we got a generator
                    assert isinstance(
                        result, types.GeneratorType
                    ), "Streaming method should return a generator"
                else:
                    # For regular operations, verify we got a result
                    assert result is not None, "Method should return a result"
            except Exception as e:
                pytest.fail(f"Contract test failed for get_counts_all: {e}")


    def test_get_counts_all_required_parameters(self):
        """Test that get_counts_all handles parameters correctly."""
        method = getattr(self.posts_client, "get_counts_all")
        # Test with missing required parameters - mock the request to avoid network calls
        with patch.object(self.client, "session") as mock_session:
            # Mock a 400 response (typical for missing required parameters)
            mock_response = Mock()
            mock_response.status_code = 400
            mock_response.json.return_value = {"error": "Missing required parameters"}
            mock_response.raise_for_status.side_effect = Exception("Bad Request")
            mock_session.get.return_value = mock_response
            # Call without required parameters should either raise locally or via server response
            # For generator methods (paginated), we need to iterate to trigger the exception
            import types
            with pytest.raises((TypeError, ValueError, Exception)):
                result = method()
                # Check if it's a generator (paginated method)
                if isinstance(result, types.GeneratorType):
                    # For generators, exception is raised when iterating
                    next(result)


    def test_get_counts_all_response_structure(self):
        """Test get_counts_all response structure validation."""
        with patch.object(self.client, "session") as mock_session:
            # Create mock response with expected structure
            mock_response_data = {
                "data": None,
            }
            mock_response = Mock()
            mock_response.status_code = 200
            mock_response.json.return_value = mock_response_data
            mock_response.raise_for_status.return_value = None
            mock_session.get.return_value = mock_response
            # Prepare minimal valid parameters
            kwargs = {}
            kwargs["query"] = "test_value"
            # Add request body if required
            # Call method and verify response structure
            method = getattr(self.posts_client, "get_counts_all")
            result = method(**kwargs)
            # Verify response object has expected attributes
            # Optional field - just check it doesn't cause errors if accessed
            try:
                getattr(result, "data", None)
            except Exception as e:
                pytest.fail(
                    f"Accessing optional field 'data' should not cause errors: {e}"
                )


    def test_search_all_request_structure(self):
        """Test search_all request structure."""
        # Mock the session to capture request details
        with patch.object(self.client, "session") as mock_session:
            mock_response = Mock()
            mock_response.status_code = 200
            mock_response.json.return_value = {
                "data": None,
            }
            mock_response.raise_for_status.return_value = None
            mock_session.get.return_value = mock_response
            # Prepare test parameters
            kwargs = {}
            # Add required parameters
            kwargs["query"] = "test_query"
            # Add request body if required
            # Call the method
            try:
                method = getattr(self.posts_client, "search_all")
                # Check if this might be a streaming operation by inspecting return type
                import types
                import inspect
                sig = inspect.signature(method)
                return_annotation = str(sig.return_annotation)
                might_be_streaming = (
                    "Generator" in return_annotation or "Iterator" in return_annotation
                )
                # Set up streaming mock if it might be streaming (before calling method)
                if might_be_streaming:
                    mock_streaming_response = Mock()
                    mock_streaming_response.status_code = 200
                    mock_streaming_response.raise_for_status.return_value = None
                    # Make it a proper context manager
                    mock_streaming_response.__enter__ = Mock(
                        return_value=mock_streaming_response
                    )
                    mock_streaming_response.__exit__ = Mock(return_value=None)
                    # Set up iter_content to return an iterator that yields test data
                    # iter_content with decode_unicode=True returns strings, not bytes
                    test_data = '{"data": "test"}\n'
                    # iter_content is called as a method, so we need to make it return an iterator
                    mock_streaming_response.iter_content = Mock(
                        side_effect=lambda *args, **kwargs: iter([test_data])
                    )
                    # Make session.get return the context manager
                    mock_session.get.return_value = mock_streaming_response
                result = method(**kwargs)
                # Check if this is actually a streaming operation (returns Generator)
                is_streaming = isinstance(result, types.GeneratorType)
                if is_streaming:
                    # Consume the generator to trigger the HTTP request
                    # The HTTP request happens when entering the 'with' block inside the generator
                    # We need to actually iterate to trigger the request
                    try:
                        # Try to get first item - this will trigger the HTTP request
                        # The 'with' statement inside the generator will call session.get()
                        next(result)
                    except StopIteration:
                        # Generator exhausted immediately - request was still made
                        pass
                    except (
                        requests.exceptions.RequestException,
                        json.JSONDecodeError,
                        AttributeError,
                        ValueError,
                    ) as e:
                        # These exceptions can occur during streaming (request errors, JSON parsing, etc.)
                        # The request should still have been attempted
                        pass
                    # Don't catch other exceptions - if there's an error during setup (before the request),
                    # we want to know about it, and the request verification below will fail appropriately
                # Verify the request was made
                # For streaming operations, the request happens when entering the 'with' block
                # which occurs when we call next() on the generator
                mock_session.get.assert_called_once()
                # Verify request structure
                call_args = mock_session.get.call_args
                # Check URL structure
                called_url = (
                    call_args[0][0] if call_args[0] else call_args[1].get("url", "")
                )
                expected_path = "/2/tweets/search/all"
                assert expected_path.replace("{", "").replace(
                    "}", ""
                ) in called_url or any(
                    param in called_url for param in ["test_", "42"]
                ), f"URL should contain path template elements: {called_url}"
                # Verify response structure
                if is_streaming:
                    # For streaming, verify we got a generator
                    assert isinstance(
                        result, types.GeneratorType
                    ), "Streaming method should return a generator"
                else:
                    # For regular operations, verify we got a result
                    assert result is not None, "Method should return a result"
            except Exception as e:
                pytest.fail(f"Contract test failed for search_all: {e}")


    def test_search_all_required_parameters(self):
        """Test that search_all handles parameters correctly."""
        method = getattr(self.posts_client, "search_all")
        # Test with missing required parameters - mock the request to avoid network calls
        with patch.object(self.client, "session") as mock_session:
            # Mock a 400 response (typical for missing required parameters)
            mock_response = Mock()
            mock_response.status_code = 400
            mock_response.json.return_value = {"error": "Missing required parameters"}
            mock_response.raise_for_status.side_effect = Exception("Bad Request")
            mock_session.get.return_value = mock_response
            # Call without required parameters should either raise locally or via server response
            # For generator methods (paginated), we need to iterate to trigger the exception
            import types
            with pytest.raises((TypeError, ValueError, Exception)):
                result = method()
                # Check if it's a generator (paginated method)
                if isinstance(result, types.GeneratorType):
                    # For generators, exception is raised when iterating
                    next(result)


    def test_search_all_response_structure(self):
        """Test search_all response structure validation."""
        with patch.object(self.client, "session") as mock_session:
            # Create mock response with expected structure
            mock_response_data = {
                "data": None,
            }
            mock_response = Mock()
            mock_response.status_code = 200
            mock_response.json.return_value = mock_response_data
            mock_response.raise_for_status.return_value = None
            mock_session.get.return_value = mock_response
            # Prepare minimal valid parameters
            kwargs = {}
            kwargs["query"] = "test_value"
            # Add request body if required
            # Call method and verify response structure
            method = getattr(self.posts_client, "search_all")
            result = method(**kwargs)
            # Verify response object has expected attributes
            # Optional field - just check it doesn't cause errors if accessed
            try:
                getattr(result, "data", None)
            except Exception as e:
                pytest.fail(
                    f"Accessing optional field 'data' should not cause errors: {e}"
                )


    def test_get_by_id_request_structure(self):
        """Test get_by_id request structure."""
        # Mock the session to capture request details
        with patch.object(self.client, "session") as mock_session:
            mock_response = Mock()
            mock_response.status_code = 200
            mock_response.json.return_value = {
                "data": None,
            }
            mock_response.raise_for_status.return_value = None
            mock_session.get.return_value = mock_response
            # Prepare test parameters
            kwargs = {}
            # Add required parameters
            kwargs["id"] = "test_value"
            # Add request body if required
            # Call the method
            try:
                method = getattr(self.posts_client, "get_by_id")
                # Check if this might be a streaming operation by inspecting return type
                import types
                import inspect
                sig = inspect.signature(method)
                return_annotation = str(sig.return_annotation)
                might_be_streaming = (
                    "Generator" in return_annotation or "Iterator" in return_annotation
                )
                # Set up streaming mock if it might be streaming (before calling method)
                if might_be_streaming:
                    mock_streaming_response = Mock()
                    mock_streaming_response.status_code = 200
                    mock_streaming_response.raise_for_status.return_value = None
                    # Make it a proper context manager
                    mock_streaming_response.__enter__ = Mock(
                        return_value=mock_streaming_response
                    )
                    mock_streaming_response.__exit__ = Mock(return_value=None)
                    # Set up iter_content to return an iterator that yields test data
                    # iter_content with decode_unicode=True returns strings, not bytes
                    test_data = '{"data": "test"}\n'
                    # iter_content is called as a method, so we need to make it return an iterator
                    mock_streaming_response.iter_content = Mock(
                        side_effect=lambda *args, **kwargs: iter([test_data])
                    )
                    # Make session.get return the context manager
                    mock_session.get.return_value = mock_streaming_response
                result = method(**kwargs)
                # Check if this is actually a streaming operation (returns Generator)
                is_streaming = isinstance(result, types.GeneratorType)
                if is_streaming:
                    # Consume the generator to trigger the HTTP request
                    # The HTTP request happens when entering the 'with' block inside the generator
                    # We need to actually iterate to trigger the request
                    try:
                        # Try to get first item - this will trigger the HTTP request
                        # The 'with' statement inside the generator will call session.get()
                        next(result)
                    except StopIteration:
                        # Generator exhausted immediately - request was still made
                        pass
                    except (
                        requests.exceptions.RequestException,
                        json.JSONDecodeError,
                        AttributeError,
                        ValueError,
                    ) as e:
                        # These exceptions can occur during streaming (request errors, JSON parsing, etc.)
                        # The request should still have been attempted
                        pass
                    # Don't catch other exceptions - if there's an error during setup (before the request),
                    # we want to know about it, and the request verification below will fail appropriately
                # Verify the request was made
                # For streaming operations, the request happens when entering the 'with' block
                # which occurs when we call next() on the generator
                mock_session.get.assert_called_once()
                # Verify request structure
                call_args = mock_session.get.call_args
                # Check URL structure
                called_url = (
                    call_args[0][0] if call_args[0] else call_args[1].get("url", "")
                )
                expected_path = "/2/tweets/{id}"
                assert expected_path.replace("{", "").replace(
                    "}", ""
                ) in called_url or any(
                    param in called_url for param in ["test_", "42"]
                ), f"URL should contain path template elements: {called_url}"
                # Verify response structure
                if is_streaming:
                    # For streaming, verify we got a generator
                    assert isinstance(
                        result, types.GeneratorType
                    ), "Streaming method should return a generator"
                else:
                    # For regular operations, verify we got a result
                    assert result is not None, "Method should return a result"
            except Exception as e:
                pytest.fail(f"Contract test failed for get_by_id: {e}")


    def test_get_by_id_required_parameters(self):
        """Test that get_by_id handles parameters correctly."""
        method = getattr(self.posts_client, "get_by_id")
        # Test with missing required parameters - mock the request to avoid network calls
        with patch.object(self.client, "session") as mock_session:
            # Mock a 400 response (typical for missing required parameters)
            mock_response = Mock()
            mock_response.status_code = 400
            mock_response.json.return_value = {"error": "Missing required parameters"}
            mock_response.raise_for_status.side_effect = Exception("Bad Request")
            mock_session.get.return_value = mock_response
            # Call without required parameters should either raise locally or via server response
            # For generator methods (paginated), we need to iterate to trigger the exception
            import types
            with pytest.raises((TypeError, ValueError, Exception)):
                result = method()
                # Check if it's a generator (paginated method)
                if isinstance(result, types.GeneratorType):
                    # For generators, exception is raised when iterating
                    next(result)


    def test_get_by_id_response_structure(self):
        """Test get_by_id response structure validation."""
        with patch.object(self.client, "session") as mock_session:
            # Create mock response with expected structure
            mock_response_data = {
                "data": None,
            }
            mock_response = Mock()
            mock_response.status_code = 200
            mock_response.json.return_value = mock_response_data
            mock_response.raise_for_status.return_value = None
            mock_session.get.return_value = mock_response
            # Prepare minimal valid parameters
            kwargs = {}
            kwargs["id"] = "test"
            # Add request body if required
            # Call method and verify response structure
            method = getattr(self.posts_client, "get_by_id")
            result = method(**kwargs)
            # Verify response object has expected attributes
            # Optional field - just check it doesn't cause errors if accessed
            try:
                getattr(result, "data", None)
            except Exception as e:
                pytest.fail(
                    f"Accessing optional field 'data' should not cause errors: {e}"
                )


    def test_delete_request_structure(self):
        """Test delete request structure."""
        # Mock the session to capture request details
        with patch.object(self.client, "session") as mock_session:
            mock_response = Mock()
            mock_response.status_code = 200
            mock_response.json.return_value = {
                "data": None,
            }
            mock_response.raise_for_status.return_value = None
            mock_session.delete.return_value = mock_response
            # Prepare test parameters
            kwargs = {}
            # Add required parameters
            kwargs["id"] = "test_value"
            # Add request body if required
            # Call the method
            try:
                method = getattr(self.posts_client, "delete")
                # Check if this might be a streaming operation by inspecting return type
                import types
                import inspect
                sig = inspect.signature(method)
                return_annotation = str(sig.return_annotation)
                might_be_streaming = (
                    "Generator" in return_annotation or "Iterator" in return_annotation
                )
                # Set up streaming mock if it might be streaming (before calling method)
                if might_be_streaming:
                    mock_streaming_response = Mock()
                    mock_streaming_response.status_code = 200
                    mock_streaming_response.raise_for_status.return_value = None
                    # Make it a proper context manager
                    mock_streaming_response.__enter__ = Mock(
                        return_value=mock_streaming_response
                    )
                    mock_streaming_response.__exit__ = Mock(return_value=None)
                    # Set up iter_content to return an iterator that yields test data
                    # iter_content with decode_unicode=True returns strings, not bytes
                    test_data = '{"data": "test"}\n'
                    # iter_content is called as a method, so we need to make it return an iterator
                    mock_streaming_response.iter_content = Mock(
                        side_effect=lambda *args, **kwargs: iter([test_data])
                    )
                    # Make session.get return the context manager
                    mock_session.delete.return_value = mock_streaming_response
                result = method(**kwargs)
                # Check if this is actually a streaming operation (returns Generator)
                is_streaming = isinstance(result, types.GeneratorType)
                if is_streaming:
                    # Consume the generator to trigger the HTTP request
                    # The HTTP request happens when entering the 'with' block inside the generator
                    # We need to actually iterate to trigger the request
                    try:
                        # Try to get first item - this will trigger the HTTP request
                        # The 'with' statement inside the generator will call session.get()
                        next(result)
                    except StopIteration:
                        # Generator exhausted immediately - request was still made
                        pass
                    except (
                        requests.exceptions.RequestException,
                        json.JSONDecodeError,
                        AttributeError,
                        ValueError,
                    ) as e:
                        # These exceptions can occur during streaming (request errors, JSON parsing, etc.)
                        # The request should still have been attempted
                        pass
                    # Don't catch other exceptions - if there's an error during setup (before the request),
                    # we want to know about it, and the request verification below will fail appropriately
                # Verify the request was made
                # For streaming operations, the request happens when entering the 'with' block
                # which occurs when we call next() on the generator
                mock_session.delete.assert_called_once()
                # Verify request structure
                call_args = mock_session.delete.call_args
                # Check URL structure
                called_url = (
                    call_args[0][0] if call_args[0] else call_args[1].get("url", "")
                )
                expected_path = "/2/tweets/{id}"
                assert expected_path.replace("{", "").replace(
                    "}", ""
                ) in called_url or any(
                    param in called_url for param in ["test_", "42"]
                ), f"URL should contain path template elements: {called_url}"
                # Verify response structure
                if is_streaming:
                    # For streaming, verify we got a generator
                    assert isinstance(
                        result, types.GeneratorType
                    ), "Streaming method should return a generator"
                else:
                    # For regular operations, verify we got a result
                    assert result is not None, "Method should return a result"
            except Exception as e:
                pytest.fail(f"Contract test failed for delete: {e}")


    def test_delete_required_parameters(self):
        """Test that delete handles parameters correctly."""
        method = getattr(self.posts_client, "delete")
        # Test with missing required parameters - mock the request to avoid network calls
        with patch.object(self.client, "session") as mock_session:
            # Mock a 400 response (typical for missing required parameters)
            mock_response = Mock()
            mock_response.status_code = 400
            mock_response.json.return_value = {"error": "Missing required parameters"}
            mock_response.raise_for_status.side_effect = Exception("Bad Request")
            mock_session.delete.return_value = mock_response
            # Call without required parameters should either raise locally or via server response
            # For generator methods (paginated), we need to iterate to trigger the exception
            import types
            with pytest.raises((TypeError, ValueError, Exception)):
                result = method()
                # Check if it's a generator (paginated method)
                if isinstance(result, types.GeneratorType):
                    # For generators, exception is raised when iterating
                    next(result)


    def test_delete_response_structure(self):
        """Test delete response structure validation."""
        with patch.object(self.client, "session") as mock_session:
            # Create mock response with expected structure
            mock_response_data = {
                "data": None,
            }
            mock_response = Mock()
            mock_response.status_code = 200
            mock_response.json.return_value = mock_response_data
            mock_response.raise_for_status.return_value = None
            mock_session.delete.return_value = mock_response
            # Prepare minimal valid parameters
            kwargs = {}
            kwargs["id"] = "test"
            # Add request body if required
            # Call method and verify response structure
            method = getattr(self.posts_client, "delete")
            result = method(**kwargs)
            # Verify response object has expected attributes
            # Optional field - just check it doesn't cause errors if accessed
            try:
                getattr(result, "data", None)
            except Exception as e:
                pytest.fail(
                    f"Accessing optional field 'data' should not cause errors: {e}"
                )


    def test_get_reposts_request_structure(self):
        """Test get_reposts request structure."""
        # Mock the session to capture request details
        with patch.object(self.client, "session") as mock_session:
            mock_response = Mock()
            mock_response.status_code = 200
            mock_response.json.return_value = {
                "data": None,
            }
            mock_response.raise_for_status.return_value = None
            mock_session.get.return_value = mock_response
            # Prepare test parameters
            kwargs = {}
            # Add required parameters
            kwargs["id"] = "test_value"
            # Add request body if required
            # Call the method
            try:
                method = getattr(self.posts_client, "get_reposts")
                # Check if this might be a streaming operation by inspecting return type
                import types
                import inspect
                sig = inspect.signature(method)
                return_annotation = str(sig.return_annotation)
                might_be_streaming = (
                    "Generator" in return_annotation or "Iterator" in return_annotation
                )
                # Set up streaming mock if it might be streaming (before calling method)
                if might_be_streaming:
                    mock_streaming_response = Mock()
                    mock_streaming_response.status_code = 200
                    mock_streaming_response.raise_for_status.return_value = None
                    # Make it a proper context manager
                    mock_streaming_response.__enter__ = Mock(
                        return_value=mock_streaming_response
                    )
                    mock_streaming_response.__exit__ = Mock(return_value=None)
                    # Set up iter_content to return an iterator that yields test data
                    # iter_content with decode_unicode=True returns strings, not bytes
                    test_data = '{"data": "test"}\n'
                    # iter_content is called as a method, so we need to make it return an iterator
                    mock_streaming_response.iter_content = Mock(
                        side_effect=lambda *args, **kwargs: iter([test_data])
                    )
                    # Make session.get return the context manager
                    mock_session.get.return_value = mock_streaming_response
                result = method(**kwargs)
                # Check if this is actually a streaming operation (returns Generator)
                is_streaming = isinstance(result, types.GeneratorType)
                if is_streaming:
                    # Consume the generator to trigger the HTTP request
                    # The HTTP request happens when entering the 'with' block inside the generator
                    # We need to actually iterate to trigger the request
                    try:
                        # Try to get first item - this will trigger the HTTP request
                        # The 'with' statement inside the generator will call session.get()
                        next(result)
                    except StopIteration:
                        # Generator exhausted immediately - request was still made
                        pass
                    except (
                        requests.exceptions.RequestException,
                        json.JSONDecodeError,
                        AttributeError,
                        ValueError,
                    ) as e:
                        # These exceptions can occur during streaming (request errors, JSON parsing, etc.)
                        # The request should still have been attempted
                        pass
                    # Don't catch other exceptions - if there's an error during setup (before the request),
                    # we want to know about it, and the request verification below will fail appropriately
                # Verify the request was made
                # For streaming operations, the request happens when entering the 'with' block
                # which occurs when we call next() on the generator
                mock_session.get.assert_called_once()
                # Verify request structure
                call_args = mock_session.get.call_args
                # Check URL structure
                called_url = (
                    call_args[0][0] if call_args[0] else call_args[1].get("url", "")
                )
                expected_path = "/2/tweets/{id}/retweets"
                assert expected_path.replace("{", "").replace(
                    "}", ""
                ) in called_url or any(
                    param in called_url for param in ["test_", "42"]
                ), f"URL should contain path template elements: {called_url}"
                # Verify response structure
                if is_streaming:
                    # For streaming, verify we got a generator
                    assert isinstance(
                        result, types.GeneratorType
                    ), "Streaming method should return a generator"
                else:
                    # For regular operations, verify we got a result
                    assert result is not None, "Method should return a result"
            except Exception as e:
                pytest.fail(f"Contract test failed for get_reposts: {e}")


    def test_get_reposts_required_parameters(self):
        """Test that get_reposts handles parameters correctly."""
        method = getattr(self.posts_client, "get_reposts")
        # Test with missing required parameters - mock the request to avoid network calls
        with patch.object(self.client, "session") as mock_session:
            # Mock a 400 response (typical for missing required parameters)
            mock_response = Mock()
            mock_response.status_code = 400
            mock_response.json.return_value = {"error": "Missing required parameters"}
            mock_response.raise_for_status.side_effect = Exception("Bad Request")
            mock_session.get.return_value = mock_response
            # Call without required parameters should either raise locally or via server response
            # For generator methods (paginated), we need to iterate to trigger the exception
            import types
            with pytest.raises((TypeError, ValueError, Exception)):
                result = method()
                # Check if it's a generator (paginated method)
                if isinstance(result, types.GeneratorType):
                    # For generators, exception is raised when iterating
                    next(result)


    def test_get_reposts_response_structure(self):
        """Test get_reposts response structure validation."""
        with patch.object(self.client, "session") as mock_session:
            # Create mock response with expected structure
            mock_response_data = {
                "data": None,
            }
            mock_response = Mock()
            mock_response.status_code = 200
            mock_response.json.return_value = mock_response_data
            mock_response.raise_for_status.return_value = None
            mock_session.get.return_value = mock_response
            # Prepare minimal valid parameters
            kwargs = {}
            kwargs["id"] = "test"
            # Add request body if required
            # Call method and verify response structure
            method = getattr(self.posts_client, "get_reposts")
            result = method(**kwargs)
            # Verify response object has expected attributes
            # Optional field - just check it doesn't cause errors if accessed
            try:
                getattr(result, "data", None)
            except Exception as e:
                pytest.fail(
                    f"Accessing optional field 'data' should not cause errors: {e}"
                )
