Skip to content

Commit

Permalink
Mock up techindicator call
Browse files Browse the repository at this point in the history
  • Loading branch information
RomelTorres committed Dec 20, 2017
1 parent 7dd28a0 commit 4e5fe44
Show file tree
Hide file tree
Showing 2 changed files with 789 additions and 0 deletions.
65 changes: 65 additions & 0 deletions test_alpha_vantage/test_alphavantage.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
from ..alpha_vantage.alphavantage import AlphaVantage
from ..alpha_vantage.timeseries import TimeSeries
from ..alpha_vantage.techindicators import TechIndicators
from ..alpha_vantage.sectorperformance import SectorPerformances
from ..alpha_vantage.cryptocurrencies import CryptoCurrencies
from ..alpha_vantage.foreignexchange import ForeignExchange
from pandas import DataFrame as df
import unittest
import mock
Expand Down Expand Up @@ -67,3 +72,63 @@ def test_handle_api_call_python2(self, mock_urlopen):
data = av._handle_api_call(url)
self.assertIsInstance(
data, dict, 'Result Data must be a dictionary')

@unittest.skipIf(sys.version_info.major == 2, "Test valid for python 3")
@mock.patch('urllib.request.urlopen')
def test_time_series_intraday_python3(self, mock_urlopen):
""" Test that api call returns a json file as requested
"""
ts = TimeSeries(key=TestAlphaVantage._API_KEY_TEST)
url = "https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=MSFT&interval=1min&apikey=test"
path_file = self.get_file_from_url(url)
with open(path_file) as f:
mock_urlopen.return_value = f
data, _ = ts.get_intraday(
"MSFT", interval='1min', outputsize='full')
self.assertIsInstance(
data, dict, 'Result Data must be a dictionary')

@unittest.skipIf(sys.version_info.major == 3, "Test valid for python 3")
@mock.patch('urllib2.urlopen')
def test_time_series_intraday_python2(self, mock_urlopen):
""" Test that api call returns a json file as requested
"""
ts = TimeSeries(key=TestAlphaVantage._API_KEY_TEST)
url = "https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=MSFT&interval=1min&apikey=test"
path_file = self.get_file_from_url(url)
with open(path_file) as f:
mock_urlopen.return_value = f
data, _ = ts.get_intraday(
"MSFT", interval='1min', outputsize='full')
self.assertIsInstance(
data, dict, 'Result Data must be a dictionary')

@unittest.skipIf(sys.version_info.major == 2, "Test valid for python 3")
@mock.patch('urllib.request.urlopen')
def test_technical_indicator_sma_python3(self, mock_urlopen):
""" Test that api call returns a json file as requested
"""
ti = TechIndicators(key=TestAlphaVantage._API_KEY_TEST)
url = "https://www.alphavantage.co/query?function=SMA&symbol=MSFT&interval=15min&time_period=10&series_type=close&apikey=test"
path_file = self.get_file_from_url(url)
with open(path_file) as f:
mock_urlopen.return_value = f
data, _ = ti.get_sma("MSFT", interval='15min',
time_period=10, series_type='close')
self.assertIsInstance(
data, dict, 'Result Data must be a dictionary')

@unittest.skipIf(sys.version_info.major == 3, "Test valid for python 3")
@mock.patch('urllib2.urlopen')
def test_technical_indicator_sma_python2(self, mock_urlopen):
""" Test that api call returns a json file as requested
"""
ti = TechIndicators(key=TestAlphaVantage._API_KEY_TEST)
url = "https://www.alphavantage.co/query?function=SMA&symbol=MSFT&interval=15min&time_period=10&series_type=close&apikey=test"
path_file = self.get_file_from_url(url)
with open(path_file) as f:
mock_urlopen.return_value = f
data, _ = ti.get_sma("MSFT", interval='15min',
time_period=10, series_type='close')
self.assertIsInstance(
data, dict, 'Result Data must be a dictionary')
Loading

0 comments on commit 4e5fe44

Please sign in to comment.