This document explains the test structure and execution methods for the Sendbird Platform SDK Python.
Tests are organized into two types:
Unit tests independently test individual components of the SDK. They run quickly without actual API calls by using mocks.
Location: /test/test_*.py
Test Coverage:
- Model classes (creation, attribute validation, serialization/deserialization)
- API classes (method calls using mocks)
Example:
# Model test
def testCreateAUserRequest(self):
model = CreateAUserRequest(
user_id="user123",
nickname="John Doe",
profile_url="https://example.com/profile.jpg"
)
self.assertEqual(model.user_id, "user123")
# API test (using mock)
@patch.object(ApiClient, 'call_api')
def test_create_a_user(self, mock_call_api):
mock_response = MagicMock()
mock_response.data = {...}
mock_call_api.return_value = mock_response
response = self.api.create_a_user(...)
mock_call_api.assert_called_once()Integration tests verify the complete flow against actual Sendbird API. Real API credentials are required.
Location: /test/integration/test_*_integration.py
Test Coverage:
- User API (create, view, update, delete users)
- Group Channel API (create, manage channels, invite members)
- Message API (send, view, update, delete messages)
# Run all unit tests
python -m pytest test/ --ignore=test/integration/
# Run specific test file
python -m pytest test/test_user_api.py
# Run specific test case
python -m pytest test/test_user_api.py::TestUserApi::test_create_a_user
# With coverage
python -m pytest test/ --ignore=test/integration/ --cov=sendbird_platform_sdk --cov-report=htmlIntegration tests can be configured using a .env file or environment variables.
Create a .env file in the project root:
# .env
SENDBIRD_APP_ID=your_app_id
SENDBIRD_API_TOKEN=your_api_tokenThen run integration tests:
# Run integration tests (automatically loads .env)
python -m pytest test/integration/
# Run specific integration test
python -m pytest test/integration/test_user_integration.py
# Verbose output
python -m pytest test/integration/ -vAlternatively, set environment variables directly:
# Set environment variables
export SENDBIRD_APP_ID=your_app_id
export SENDBIRD_API_TOKEN=your_api_token
# Run integration tests
python -m pytest test/integration/ -vCreate a .env file in the project root with the following content:
# Sendbird Platform SDK - Integration Test Configuration
# Your Sendbird Application ID
SENDBIRD_APP_ID=your_app_id_here
# Your Sendbird API Token (Master API Token)
SENDBIRD_API_TOKEN=your_api_token_hereImportant:
- Integration tests make actual API calls
- Valid Sendbird credentials are required
- Real data will be created/deleted during test execution
- API usage will be counted towards your quota
- Never commit
.envfile to version control (it's gitignored by default)
# Install test dependencies
pip install -r test-requirements.txtRequired packages:
pytest>=6.2.5- Test frameworkpytest-cov>=2.8.1- Code coveragepytest-mock>=3.6.1- Mock helpersresponses>=0.13.3- HTTP request mocking
Some tests intentionally fail to document SDK bugs and limitations. These failing tests serve as:
- Documentation of expected vs actual behavior
- Regression detection when bugs are fixed
- Clear specifications for future improvements
Current failing tests: ~7 tests related to optional fields rejecting None values
See KNOWN_ISSUES.md for detailed information about these issues and workarounds.
- Create a
test_*.pyfile with the same name as the module to test - Create a class inheriting from
unittest.TestCase - Write test cases as
test_*methods - Use mocks to isolate external dependencies
Example:
import unittest
from unittest.mock import Mock, patch
from sendbird_platform_sdk.api.user_api import UserApi
class TestUserApi(unittest.TestCase):
def setUp(self):
self.api = UserApi()
@patch.object(ApiClient, 'call_api')
def test_new_feature(self, mock_call_api):
# Test implementation
pass- Create a
test_*_integration.pyfile in/test/integration/ - Use fixtures from
conftest.py - Write tests with actual API calls
- Clean up created resources in
teardown_method
Example:
import pytest
from sendbird_platform_sdk.api.user_api import UserApi
class TestUserApiIntegration:
@pytest.fixture(autouse=True)
def setup(self, api_client, api_config):
self.api = UserApi(api_client=api_client)
self.api_token = api_config['api_token']
def test_new_feature(self, test_user_id):
# Test with actual API calls
pass- Check mock configuration
- Verify import paths
- Ensure test isolation (each test should be independent)
- Verify environment variables are set correctly
- Check API credentials are valid
- Verify network connection
- Check API rate limits
- Ensure resources from previous tests were cleaned up properly
- Unit Tests First: Cover as much as possible with unit tests; use integration tests only for end-to-end flow verification
- Test Isolation: Each test should be runnable independently
- Resource Cleanup: Integration tests must clean up all created resources
- Clear Names: Test method names should clearly describe what is being tested
- Proper Assertions: Clearly validate test results
- Documentation: Add comments for complex tests