Skip to content

test: add request assertions and parameterized quote/ohlc/ltp tests - #259

Open
Almaryj1 wants to merge 1 commit into
zerodha:masterfrom
Almaryj1:test/request-assertions-and-quote-params
Open

Almaryj1 wants to merge 1 commit into
zerodha:masterfrom
Almaryj1:test/request-assertions-and-quote-params

Conversation

@Almaryj1

@Almaryj1 Almaryj1 commented Nov 12, 2026 •

Copy link
Copy Markdown

Summary

Fixes #257.

Several REST API unit tests in tests/unit/test_connect.py only verified response types (e.g. assert type(result) == list). They did not verify that the correct HTTP method, URL, or request body/query parameters were actually being sent. A breaking change to how a method constructs its request could go undetected.

Changes

1. Request assertion tests

Added tests that verify the outgoing request for:

Method HTTP Assertions
historical_data GET URL contains instrument_token and interval; query params include from, to, continuous, oi
historical_data (flags) GET continuous=True serializes as 1, oi=True serializes as 1
trigger_range GET transaction_type lowercased in URL, instruments in query params
convert_position PUT All 7 body params present
place_mf_order POST tradingsymbol, transaction_type, amount, tag in body
cancel_mf_order DELETE order_id in URL
place_mf_sip POST tradingsymbol, amount, instalments, frequency, instalment_day in body
modify_mf_sip PUT sip_id in URL, amount, status, instalments in body
cancel_mf_sip DELETE sip_id in URL

2. Parameterized tests for quote, ohlc, ltp

Added @pytest.mark.parametrize tests covering both supported calling styles:

kiteconnect.quote("NSE:INFY")                        # single positional
kiteconnect.quote("NSE:INFY", "NSE:RELIANCE")        # multiple positional
kiteconnect.quote(["NSE:INFY"])                      # legacy single list
kiteconnect.quote(["NSE:INFY", "NSE:RELIANCE"])      # legacy multi list

Same parametrize coverage applied to ohlc() and ltp().

Test results

52 passed (31 existing + 21 new). No changes to library code.

  Existing tests only verified response types. This adds:
  - Request method, URL, and body/query-param assertions for
    historical_data, trigger_range, convert_position, place_mf_order,
    cancel_mf_order, place_mf_sip, modify_mf_sip, and cancel_mf_sip
  - Parameterized tests for quote(), ohlc(), and ltp() covering both
    positional-arg and legacy list-style calling conventions

  Closes zerodha#257
@Almaryj1

Copy link
Copy Markdown
Author

Hi @rainandsalt — I've added request-side assertions and parametrized tests for the methods in #257. Would love your feedback when you get a chance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve REST API unit-test coverage with request assertions and parameterized quote tests

1 participant