def test_valid_exchange(self): """When the 'exchange' parameter is correct, the request should return a normal response. """ response = self.client.get(reverse("exchanges:exchange_detail"), {"exchange": EXCHANGE}, HTTP_AUTHORIZATION=new_auth_token()) self.assertEqual(response.status_code, 200) self.assertTrue(json.loads(response.content)["success"])
def test_success(self): """When exchange_list is called, it should return a list of the valid exchanges to use. """ response = self.client.get(reverse("exchanges:exchange_list"), HTTP_AUTHORIZATION=new_auth_token()) ideal_response = {"success": True, "result": ["bitstamp", "btc-e"]} self.assertEqual(response.status_code, 200) self.assertEqual(json.loads(response.content), ideal_response)
def test_missing_exchange(self): """When there is no 'exchange' parameter, an error should be returned. """ response = self.client.get(reverse("exchanges:exchange_detail"), HTTP_AUTHORIZATION=new_auth_token()) self.assertEqual(response.status_code, 400) self.assertEqual(response.content, '{"success":false,"error":"Invalid exchange: None"}')
def test_missing_auth(self, exchange): """When an authenticated method is called without authentication, an error should be returned. """ response = self.client.get(reverse("exchanges:user_detail"), {"exchange": exchange}, HTTP_AUTHORIZATION=new_auth_token()) result = json.loads(response.content) self.assertEqual(response.status_code, 400) self.assertEqual(result["success"], False)
def test_valid_exchange(self): """When the 'exchange' parameter is correct, the request should return a normal response. """ response = self.client.get( reverse("exchanges:exchange_detail"), {"exchange":EXCHANGE}, HTTP_AUTHORIZATION=new_auth_token() ) self.assertEqual(response.status_code, 200) self.assertTrue(json.loads(response.content)["success"])
def test_limit_days(self): """When all params are correct and 'days' is specified,a limited number of prices should be returned. """ response = self.client.get( reverse("prices:get_prices"), {"exchange":"btc-e", "pair":"btc_usd", "days":1}, HTTP_AUTHORIZATION=new_auth_token() ) self.assertEqual(response.status_code, 200) result = json.loads(response.content) self.assertTrue(len(result["result"]) <= 1440)
def auth_request(url, params, auth, method, args=None, auth_token=None): params["api_key"] = auth[0] params["api_secret"] = auth[1] try: params["api_id"] = auth[2] except IndexError: pass if auth_token == None: auth_token = new_auth_token() response = method(reverse(url, args=args), params, HTTP_AUTHORIZATION=auth_token) return response
def test_missing_auth(self, exchange): """When an authenticated method is called without authentication, an error should be returned. """ response = self.client.get( reverse("exchanges:user_detail"), {"exchange":exchange}, HTTP_AUTHORIZATION=new_auth_token() ) result = json.loads(response.content) self.assertEqual(response.status_code, 400) self.assertEqual(result["success"], False)
def test_missing_exchange(self): """When there is no 'exchange' parameter, an error should be returned. """ response = self.client.get( reverse("exchanges:exchange_detail"), HTTP_AUTHORIZATION=new_auth_token() ) self.assertEqual(response.status_code, 400) self.assertEqual( response.content, '{"success":false,"error":"Invalid exchange: None"}' )
def test_success(self): """When all params are correct, a list of prices should be returned. """ response = self.client.get( reverse("prices:get_prices"), {"exchange":"btc-e", "pair":"btc_usd"}, HTTP_AUTHORIZATION=new_auth_token() ) self.assertEqual(response.status_code, 200) result = json.loads(response.content) for price in result["result"]: self.assertTrue(type(price) is int or type(price) is float)
def test_invalid_pair(self, exchange): """When the 'pair' parameter is invalid, an error should be returned. """ invalid_pair = "rg3oirg3o" response = self.client.get(reverse("exchanges:pair_detail", args=[invalid_pair]), {"exchange": exchange}, HTTP_AUTHORIZATION=new_auth_token()) self.assertEqual(response.status_code, 400) self.assertEqual( response.content, '{"success":false,"error":"Invalid pair name: %s"}' % invalid_pair)
def test_success(self): """When exchange_list is called, it should return a list of the valid exchanges to use. """ response = self.client.get( reverse("exchanges:exchange_list"), HTTP_AUTHORIZATION=new_auth_token() ) ideal_response = { "success": True, "result": ["bitstamp", "btc-e"] } self.assertEqual(response.status_code, 200) self.assertEqual(json.loads(response.content), ideal_response)
def test_missing_exchange(self): """When there is no 'pair' parameter, an error should be returned. """ response = self.client.get( reverse("prices:get_prices"), {"exchange":"btc-e"}, HTTP_AUTHORIZATION=new_auth_token() ) self.assertEqual(response.status_code, 400) self.assertEqual( json.loads(response.content)["error"], "Must specify 'exchange' and 'pair' parameters." )
def test_missing_exchange(self): """When there is no 'exchange' parameter, an error should be returned. """ response = self.client.get( reverse("prices:get_prices"), {"pair":"btc_usd"}, HTTP_AUTHORIZATION=new_auth_token() ) self.assertEqual(response.status_code, 400) self.assertEqual( json.loads(response.content)["error"], "Exchange/trading pair combination not found." )
def auth_request(url, params, auth, method, args=None, auth_token=None): params["api_key"] = auth[0] params["api_secret"] = auth[1] try: params["api_id"] = auth[2] except IndexError: pass if auth_token == None: auth_token = new_auth_token() response = method(reverse(url, args=args), params, HTTP_AUTHORIZATION=auth_token) return response
def test_invalid_exchange(self): """When the 'exchange' parameter is invalid, an error should be returned. """ invalid_exchange = "24g2g4gwe" response = self.client.get(reverse("exchanges:exchange_detail"), {"exchange": invalid_exchange}, HTTP_AUTHORIZATION=new_auth_token()) self.assertEqual(response.status_code, 400) self.assertEqual( response.content, '{"success":false,"error":"Invalid exchange: %s"}' \ % invalid_exchange )
def test_bad_params(self): """When an invalid combination of exchange / pair params is supplied, an error should be returned. """ response = self.client.get( reverse("prices:get_prices"), {"exchange":"btc-e", "pair":"349g4ubfref"}, HTTP_AUTHORIZATION=new_auth_token() ) self.assertEqual(response.status_code, 400) self.assertEqual( json.loads(response.content)["error"], "Exchange/trading pair combination not found." )
def test_invalid_pair(self, exchange): """When the 'pair' parameter is invalid, an error should be returned. """ invalid_pair = "rg3oirg3o" response = self.client.get( reverse("exchanges:pair_detail", args=[invalid_pair]), {"exchange":exchange}, HTTP_AUTHORIZATION=new_auth_token() ) self.assertEqual(response.status_code, 400) self.assertEqual( response.content, '{"success":false,"error":"Invalid pair name: %s"}' % invalid_pair )
def test_invalid_exchange(self): """When the 'exchange' parameter is invalid, an error should be returned. """ invalid_exchange = "24g2g4gwe" response = self.client.get( reverse("exchanges:exchange_detail"), {"exchange":invalid_exchange}, HTTP_AUTHORIZATION=new_auth_token() ) self.assertEqual(response.status_code, 400) self.assertEqual( response.content, '{"success":false,"error":"Invalid exchange: %s"}' \ % invalid_exchange )
def test_success(self, exchange): """When exchange_detail is called, it should return informaiton about the given exchange. """ response = self.client.get(reverse("exchanges:exchange_detail"), {"exchange": exchange}, HTTP_AUTHORIZATION=new_auth_token()) result = json.loads(response.content) self.assertEqual(response.status_code, 200) self.assertTrue( type(result["result"]["pairs"]) is list or type(result["result"]["pairs"]) is unicode) self.assertTrue(type(result["result"]["min_order"]) is float) self.assertTrue(type(result["result"]["min_order_cur"]) is unicode) self.assertTrue(type(result["result"]["fees"]) is list) self.assertTrue(type(result["result"]["fees"][0]) is dict) self.assertTrue(type(result["result"]["fees_cur"]) is unicode)
def test_success(self, exchange): """When pair_detail is called, it should return information about the specific trading pair. """ valid_pair = "btc_usd" response = self.client.get(reverse("exchanges:pair_detail", args=[valid_pair]), {"exchange": exchange}, HTTP_AUTHORIZATION=new_auth_token()) result = json.loads(response.content) self.assertTrue(result["success"]) result = result["result"] self.assertEqual(response.status_code, 200) self.assertTrue(type(result["ticker"]) is dict) self.assertTrue(type(result["ticker"]["low"]) is float) self.assertTrue(type(result["volume"]) is float) self.assertTrue(type(result["depth"]) is dict) self.assertTrue(type(result["fees"]) is list)
def test_success(self, exchange): """When exchange_detail is called, it should return informaiton about the given exchange. """ response = self.client.get( reverse("exchanges:exchange_detail"), {"exchange":exchange}, HTTP_AUTHORIZATION=new_auth_token() ) result = json.loads(response.content) self.assertEqual(response.status_code, 200) self.assertTrue(type(result["result"]["pairs"]) is list or type(result["result"]["pairs"]) is unicode) self.assertTrue(type(result["result"]["min_order"]) is float) self.assertTrue(type(result["result"]["min_order_cur"]) is unicode) self.assertTrue(type(result["result"]["fees"]) is list) self.assertTrue(type(result["result"]["fees"][0]) is dict) self.assertTrue(type(result["result"]["fees_cur"]) is unicode)
def test_success(self, exchange): """When pair_detail is called, it should return information about the specific trading pair. """ valid_pair = "btc_usd" response = self.client.get( reverse("exchanges:pair_detail", args=[valid_pair]), {"exchange":exchange}, HTTP_AUTHORIZATION=new_auth_token() ) result = json.loads(response.content) self.assertTrue(result["success"]) result = result["result"] self.assertEqual(response.status_code, 200) self.assertTrue(type(result["ticker"]) is dict) self.assertTrue(type(result["ticker"]["low"]) is float) self.assertTrue(type(result["volume"]) is float) self.assertTrue(type(result["depth"]) is dict) self.assertTrue(type(result["fees"]) is list)