コード例 #1
0
ファイル: tests.py プロジェクト: kaaquist/pystocks
 def test_content_no_params(self):
     """
     Test that the stock API returns something 
     when start and end are not specified
     """
     data = stocks.quotes('GOOG')
     self.assertTrue(len(data) > 0)
コード例 #2
0
ファイル: service.py プロジェクト: kaaquist/pystocks
def quotes(request, stock_symbol):
    """
    Return stock quotes between two epoch timestamps.
    If no timestamps are given, distant past and today will be used.
    """
    start = request.GET.get('start')
    try:
        if start:
            start = int(start)
        end = request.GET.get('end')
        if end:
            end = int(end)
    except Exception:
        error = _error_message('Start and end parameters must be \
            in valid UNIX timestamp format')
        return HttpResponse(error, status=400, mimetype='application/json')

    data = stocks.quotes(stock_symbol, start=start, end=end)
    if data == None:
        error = _error_message('Could not find stocksymbol %s' % (stock_symbol))
        return HttpResponse(error, status=404, mimetype='application/json')

    return HttpResponse(json.dumps(data))
コード例 #3
0
ファイル: tests.py プロジェクト: kaaquist/pystocks
 def test_content(self):
     """Test that the stock API returns something"""
     data = stocks.quotes('GOOG', start=time.time()-864000, end=time.time())
     self.assertTrue(len(data) > 0)
コード例 #4
0
ファイル: tests.py プロジェクト: kaaquist/pystocks
 def test_non_content(self):
     """Test that the stock API returns nothing when the time range is wrong"""
     data = stocks.quotes('GOOG', start=time.time(), end=time.time()-864000)
     self.assertTrue(data is None)