From b76600e3a815f91a15ef04142cd05b6983acbbc3 Mon Sep 17 00:00:00 2001 From: mdalvi Date: Thu, 24 Oct 2024 13:07:11 +0530 Subject: [PATCH] redoing test cases --- README.md | 64 ++++++++++++++++++- tests/{test_sample.py => test_connect.py} | 0 tests/test_zerodha_api.py | 76 ----------------------- 3 files changed, 62 insertions(+), 78 deletions(-) rename tests/{test_sample.py => test_connect.py} (100%) delete mode 100644 tests/test_zerodha_api.py diff --git a/README.md b/README.md index f72626a..c029f0e 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,62 @@ -# zerodha_api -Zerodha Kite API Wrapper +# Zerodha API +[![codecov](https://codecov.io/github/mdalvi/zerodha_api/graph/badge.svg?token=ZYRWQBZG7J)](https://codecov.io/github/mdalvi/zerodha_api) + +This is a data aggregation wrapper for Zerodha's Kite Connect API that simplifies market data handling for machine learning and data analysis. + +## Features + +```python +# TODO +``` +## Installation + +```python +# TODO +``` + +## Prerequisites + +```python +# TODO +``` + +## Configuration + +```python +# TODO +``` + +## Usage + +```python +# TODO +``` + +## Key Components + +- `Connect`: Main class for interacting with Kite API +- `Ticker`: WebSocket implementation for real-time market data +- `Redis`: Caching layer for market data and state management +- `Celery`: Asynchronous task processing for data handling + +## Development + +```bash +# Install development dependencies +poetry install ../zerodha_api/ + +# Run tests +pytest + +# Generate coverage report +pytest --cov=./ --cov-report=xml +``` + +## License + +This project is licensed under the MIT License - see the LICENSE file for details. + +## Acknowledgments + +- [Zerodha Kite Connect API](https://kite.trade/docs/connect/v3/) +- [KiteConnect Python Client](https://kite.trade/docs/pykiteconnect/v4/) \ No newline at end of file diff --git a/tests/test_sample.py b/tests/test_connect.py similarity index 100% rename from tests/test_sample.py rename to tests/test_connect.py diff --git a/tests/test_zerodha_api.py b/tests/test_zerodha_api.py deleted file mode 100644 index 91bd1d9..0000000 --- a/tests/test_zerodha_api.py +++ /dev/null @@ -1,76 +0,0 @@ -""" -Test case generated using Claude Sonnet 3.5 -""" - -import json -from unittest.mock import patch - -import pytest - -from zerodha_api import ZAMQp -from zerodha_api.settings import KITE_SNAPSHOT_DATA, KITE_TICK_DATA - - -@pytest.fixture -def redis_config(): - return { - "redis_host": "127.0.0.1", - "redis_password": "", - "redis_port": 6379, - "redis_db": 0, - } - - -@pytest.fixture -def mock_redis(): - with patch("zerodha_api.amqp.main.Redis") as mock: - yield mock.return_value - - -@pytest.fixture -def mock_get_configuration(): - with patch("zerodha_api.amqp.main.get_configuration") as mock: - mock.return_value = {"timezone": "UTC"} - yield mock - - -def test_create_celery_app(redis_config, mock_redis, mock_get_configuration): - app = ZAMQp(**redis_config) - - assert app.main == "tasks" - assert app.conf.timezone == "UTC" - assert app.conf.enable_utc is True - assert app.conf.broker_connection_retry_on_startup is True - - expected_broker_url = f"redis://:{redis_config['redis_password']}@{redis_config['redis_host']}:{redis_config['redis_port']}/{redis_config['redis_db']}" - assert app.conf.broker_url == expected_broker_url - - -def test_cache_on_redis_task(redis_config, mock_redis, mock_get_configuration): - app = ZAMQp(**redis_config) - # Get the task by name from the app - task = app.tasks["zerodha_api.amqp.main.cache_on_redis"] - - test_ticks = [ - {"instrument_token": "123", "last_price": 100.5}, - {"instrument_token": "456", "last_price": 200.75}, - ] - - task.apply(args=(test_ticks,)) - - # Check if Redis set and rpush were called with correct arguments - for tick in test_ticks: - mock_redis.set.assert_any_call( - f"kt:ltp:{tick['instrument_token']}", tick["last_price"] - ) - mock_redis.rpush.assert_any_call( - f"kt:{tick['instrument_token']}", json.dumps(tick) - ) - - # Check if KITE_SNAPSHOT_DATA and KITE_TICK_DATA were set - mock_redis.set.assert_any_call(KITE_SNAPSHOT_DATA, json.dumps(test_ticks)) - mock_redis.rpush.assert_any_call(KITE_TICK_DATA, json.dumps(test_ticks)) - - -if __name__ == "__main__": - pytest.main()