# coding: utf-8

import pytest
import kiteconnect.exceptions as ex


def test_set_access_token(kiteconnect):
    """Check for token exception when invalid token is set."""
    kiteconnect.set_access_token("invalid_token")
    with pytest.raises(ex.TokenException):
        kiteconnect.positions()


def test_positions(kiteconnect):
    """Test positions."""
    positions = kiteconnect.positions()
    assert type(positions) == dict
    assert "day" in positions
    assert "net" in positions


def test_holdings(kiteconnect):
    """Test holdiogs."""
    holdings = kiteconnect.holdings()
    assert type(holdings) == list


def test_margins(kiteconnect):
    """Test holdiogs."""
    margins = kiteconnect.margins()
    assert type(margins) == dict
    assert kiteconnect.MARGIN_EQUITY in margins
    assert kiteconnect.MARGIN_COMMODITY in margins


def test_margins_segmentwise(kiteconnect):
    """Test margins for individual segments."""
    commodity = kiteconnect.margins(segment=kiteconnect.MARGIN_COMMODITY)
    assert type(commodity) == dict


def test_orders(kiteconnect):
    """Test orders get."""
    orders = kiteconnect.orders()
    assert type(orders) == list


def test_order_get(kiteconnect):
    """Test individual order get."""
    orders = kiteconnect.orders()
    assert type(orders) == list


def test_trades(kiteconnect):
    """Test trades."""
    trades = kiteconnect.trades()
    assert type(trades) == list


def test_mf_orders(kiteconnect):
    """Test mf orders get."""
    trades = kiteconnect.mf_orders()
    assert type(trades) == list


def test_mf_sips(kiteconnect):
    """Test mf sips get."""
    trades = kiteconnect.mf_sips()
    assert type(trades) == list


def test_mf_holdings(kiteconnect):
    """Test mf holdings."""
    trades = kiteconnect.mf_holdings()
    assert type(trades) == list


def test_mf_instruments(kiteconnect):
    """Test mf instruments fetch."""
    trades = kiteconnect.mf_instruments()
    assert type(trades) == list

@@ -17,22 +17,51 @@
 %0Aimport 
-pytest
+warnings%0Aimport pytest%0Aimport utils
 %0Aimport 
@@ -485,16 +485,16 @@
 sitions%0A
-
     asse
@@ -512,24 +512,570 @@
  positions%0A%0A
+    if len(positions%5B%22day%22%5D) %3E 0:%0A        keys = %5B'day_sell_value', 'day_buy_quantity', 'last_price'%5D%0A        utils.assert_dict_keys(positions%5B%22day%22%5D%5B0%5D, keys)%0A    else:%0A        warnings.warn(UserWarning(%22No day positions. So skipping day positions response keys test.%22))%0A%0A    if len(positions%5B%22net%22%5D) %3E 0:%0A        keys = %5B'day_sell_value', 'day_buy_quantity', 'last_price'%5D%0A        utils.assert_dict_keys(positions%5B%22net%22%5D%5B0%5D, keys)%0A    else:%0A        warnings.warn(UserWarning(%22No net positions. So skipping net positions response keys test.%22))%0A%0A
 %0Adef test_ho

Add response dict keys check for positions integration test