From 117f4d60b228a58021686a02c7fdbb510371769d Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Thu, 25 Aug 2016 17:08:37 -0400 Subject: [PATCH] Make sure records are actually saveable MongoDB doesn't like the pure `date` type. --- metrik/__init__.py | 2 +- metrik/tasks/tradeking.py | 2 +- test/tasks/test_tradeking.py | 22 +++++++++++++++++++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/metrik/__init__.py b/metrik/__init__.py index 743c92f..561af6b 100644 --- a/metrik/__init__.py +++ b/metrik/__init__.py @@ -1,2 +1,2 @@ -__version__ = '0.3.3' +__version__ = '0.3.4' __release__ = __version__ \ No newline at end of file diff --git a/metrik/tasks/tradeking.py b/metrik/tasks/tradeking.py index b0c4456..403b354 100644 --- a/metrik/tasks/tradeking.py +++ b/metrik/tasks/tradeking.py @@ -65,7 +65,7 @@ class Tradeking1mTimesales(MongoCreateTask): 'incr_vl': int(quote['incr_vl']), 'hi': float(quote['hi']), 'timestamp': parse(quote['timestamp']), - 'date': parse(quote['date']).date(), + 'date': parse(quote['date']), 'opn': float(quote['opn']) } quotes_typed = [format_quote(q) for q in quotes] diff --git a/test/tasks/test_tradeking.py b/test/tasks/test_tradeking.py index e126309..78a40fc 100644 --- a/test/tasks/test_tradeking.py +++ b/test/tasks/test_tradeking.py @@ -4,13 +4,16 @@ from pandas_datareader.data import get_data_yahoo from numpy.testing import assert_allclose import pytest from six.moves import map +from pytz import utc from metrik.tasks.tradeking import Tradeking1mTimesales from metrik.trading_days import TradingDay +from metrik.targets.mongo import MongoTarget +from test.mongo_test import MongoTest @pytest.mark.parametrize('ticker', [ - 'AAPL', 'GOOG', 'SPY', 'REGN', 'SWHC', 'BAC', 'NVCR' + 'AAPL', 'GOOG', 'SPY', 'REGN', 'SWHC', 'BAC', 'NVCR', 'ARGT' ]) def test_returns_verifiable(ticker): # Test that the quotes line up with data off of Yahoo @@ -36,3 +39,20 @@ def test_returns_verifiable(ticker): tradeking_ohlc = (open, high, low, close) assert_allclose(tradeking_ohlc, yahoo_ohlc, rtol=1e-3) + +class TradekingTest(MongoTest): + + def test_record_is_saveable(self): + # Had an issue previously where the `date` type would cause saving + # to fail. Make sure that doesn't continue + now = datetime.now() + prior_day = now - TradingDay(1) + quotes = Tradeking1mTimesales.retrieve_data(prior_day, 'AAPL') + t = MongoTarget('tradeking', hash('just_testing')) + t.persist(quotes) + quotes_retrieved = t.retrieve() + for quote in quotes_retrieved['quotes']: + quote['datetime'] = utc.localize(quote['datetime']) + quote['timestamp'] = utc.localize(quote['timestamp']) + + assert quotes == quotes_retrieved