示例#1
0
def yahoo_fetcher(stock, start, end):
    with rest.create(YAHOO_HOST) as c:
        c.move(YAHOO_APP)
        c.query("s",stock).query("ignore",".csv")
        c.params.update(map_date(["a","b","c"],start))
        c.params.update(map_date(["d","e","f"],end))
        c.query("g","d")
        resp = c.get()
        if not resp.status == 200:
            raise IOError("Failed to fetch index data. Error code : %i" % resp.status)
        return resp.read()
示例#2
0
def yahoo_fetcher(stock, start, end):
    with rest.create(YAHOO_HOST) as c:
        c.move(YAHOO_APP)
        c.query("s", stock).query("ignore", ".csv")
        c.params.update(map_date(["a", "b", "c"], start))
        c.params.update(map_date(["d", "e", "f"], end))
        c.query("g", "d")
        resp = c.get()
        if not resp.status == 200:
            raise IOError("Failed to fetch index data. Error code : %i" %
                          resp.status)
        return resp.read()
示例#3
0
 def setUp(self):
     self.subject = rest.create(HOST)
示例#4
0
 def test_get_fetches_a_body(self):
     with rest.create(VALID_HOST) as c:
         response = c.get()
         self.assertTrue(response.status < 400)
         self.assertTrue(len(response.read()) > 0)
示例#5
0
 def test_head_fetches_no_body(self):
     with rest.create(VALID_HOST) as c:
         response = c.head()
         self.assertTrue(response.status < 400)
         self.assertEqual(0, len(response.read()))
示例#6
0
 def test_context_autoconnects(self):
     with rest.create(VALID_HOST) as client:
         self.assertTrue(client.isConnected())
示例#7
0
 def test_invalid_host_fails_on_connecting(self):
     self.subject = rest.create(INVALID_HOST)
     with self.assertRaises(InvalidURL):
         self.subject.connect()
示例#8
0
 def test_can_connect_to_valid(self):
     self.subject = rest.create(VALID_HOST)
     self.subject.connect()
     self.assertTrue(self.subject.isConnected())
示例#9
0
 def test_is_disconnected_before_connecting(self):
     self.subject = rest.create(INVALID_HOST)
     self.assertFalse(self.subject.isConnected())
示例#10
0
 def test_get_fetches_a_body(self):
     with rest.create(VALID_HOST) as c:
         response = c.get()
         self.assertTrue(response.status < 400)
         self.assertTrue(len(response.read()) > 0)
示例#11
0
 def test_head_fetches_no_body(self):
     with rest.create(VALID_HOST) as c:
         response = c.head()
         self.assertTrue(response.status < 400)
         self.assertEqual(0, len(response.read()))
示例#12
0
 def test_context_autoconnects(self):
     with rest.create(VALID_HOST) as client:
         self.assertTrue(client.isConnected())
示例#13
0
 def test_invalid_host_fails_on_connecting(self):
     self.subject = rest.create(INVALID_HOST)
     with self.assertRaises(InvalidURL):
         self.subject.connect()
示例#14
0
 def test_can_connect_to_valid(self):
     self.subject = rest.create(VALID_HOST)
     self.subject.connect()
     self.assertTrue(self.subject.isConnected())
示例#15
0
 def test_is_disconnected_before_connecting(self):
     self.subject = rest.create(INVALID_HOST)
     self.assertFalse(self.subject.isConnected())