Skip to content

Commit

Permalink
Add user segment margin tests and other connect tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vividvilla committed Apr 4, 2018
1 parent 182aa4c commit 94d16c8
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
18 changes: 17 additions & 1 deletion connect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,33 @@ func TestClientSetters(t *testing.T) {
Timeout: customHTTPClientTimeout,
}

// Check if default debug is false
if client.debug != false || client.httpClient.GetClient().debug != false {
t.Errorf("Default debug is not false.")
}

// Set custom debug
client.SetDebug(customDebug)
if client.debug != customDebug || client.httpClient.GetClient().debug != customDebug {
t.Errorf("Debug is not set properly.")
}

// Test default base uri
if client.baseURI != baseURI {
t.Errorf("Default base URI is not set properly.")
}

// Set custom base URI
client.SetBaseURI(customBaseURI)
if client.baseURI != customBaseURI {
t.Errorf("Base URI is not set properly.")
}

// Test default timeout
if client.httpClient.GetClient().client.Timeout != requestTimeout {
t.Errorf("Default request timeout is not set properly.")
}

// Set custom timeout for default http client
client.SetTimeout(customTimeout)
if client.httpClient.GetClient().client.Timeout != customTimeout {
Expand Down Expand Up @@ -85,6 +100,7 @@ const mockBaseDir = "./mock_responses"
var MockResponses = map[string]string{
URIUserProfile: "profile.json",
URIUserMargins: "margins.json",
URIUserMarginsSegment: "margins_equity.json",
URIGetOrders: "orders.json",
URIGetTrades: "trades.json",
URIGetOrderHistory: "order_info.json", // "/orders/{order_id}"
Expand Down Expand Up @@ -117,7 +133,7 @@ type TestSuite struct {
// Setup the API suit
func (ts *TestSuite) SetupAPITestSuit() {
ts.KiteConnect = New("test_api_key")
httpmock.ActivateNonDefault(ts.KiteConnect.httpClient.GetClient())
httpmock.ActivateNonDefault(ts.KiteConnect.httpClient.GetClient().client)

for route, f := range MockResponses {
resp, err := ioutil.ReadFile(path.Join(mockBaseDir, f))
Expand Down
24 changes: 24 additions & 0 deletions mock_responses/margins_equity.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"status": "success",
"data": {
"enabled": true,
"net": 15481.524,
"available": {
"adhoc_margin": 0,
"cash": 9929.024,
"collateral": 5554.5,
"intraday_payin": 0
},
"utilised": {
"debits": 2,
"exposure": 0,
"m2m_realised": -2,
"m2m_unrealised": 0,
"option_premium": 0,
"payout": 0,
"span": 0,
"holding_sales": 0,
"turnover": 0
}
}
}
15 changes: 14 additions & 1 deletion user_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package kiteconnect

import "testing"
import (
"testing"
)

func (ts *TestSuite) TestGetUserProfile(t *testing.T) {
profile, err := ts.KiteConnect.GetUserProfile()
Expand All @@ -19,3 +21,14 @@ func (ts *TestSuite) TestGetUserMargins(t *testing.T) {
t.Errorf("Incorrect margin values.")
}
}

func (ts *TestSuite) TestGetUserSegmentMargins(t *testing.T) {
margins, err := ts.KiteConnect.GetUserSegmentMargins("test")
if err != nil {
t.Errorf("Error while reading user margins. Error: %v", err)
}

if !margins.Enabled {
t.Errorf("Incorrect segment margin values.")
}
}

0 comments on commit 94d16c8

Please sign in to comment.