refactore code and tests

This commit is contained in:
Henrique Lopes 2015-08-23 15:57:28 -03:00
parent 28e0fab588
commit bbda3eaa54
2 changed files with 7 additions and 5 deletions

View File

@ -23,9 +23,9 @@ googleFinanceKeyToFullName = {
def buildUrl(symbols):
aux_symbols = filter(lambda value: value.strip() != "", symbols)
if len(aux_symbols) != len(symbols):
raise Exception("Does not input value empty.")
aux_symbols = [s for s in symbols if s.strip() != ""]
if len(aux_symbols) == 0 or len(aux_symbols) != len(symbols):
raise Exception("Can not be blank.")
# a deprecated but still active & correct api
return 'http://finance.google.com/finance/info?client=ig&q={0}'.format(
','.join(aux_symbols))

View File

@ -17,6 +17,8 @@ class TestQuotes(unittest.TestCase):
self.assertEqual(quotes[1]["StockSymbol"], "BKS")
def test_empty(self):
with self.assertRaises(Exception) as e:
try:
googlefinance.getQuotes("")
self.assertTrue("Can not be blank." in str(e.exception))
self.assertTrue(False)
except Exception as e:
self.assertTrue("Can not be blank." in str(e))