fix failing tests that didn't work with error code

This commit is contained in:
James Turk 2011-09-28 15:43:53 -04:00
parent 7b8eda5143
commit da1a3385e1

View File

@ -29,6 +29,7 @@ class ClientTests(TestCase):
assert c.scraper.requests_per_minute == 30 assert c.scraper.requests_per_minute == 30
assert c.scraper.timeout == 60 assert c.scraper.timeout == 60
def test_log(self): def test_log(self):
self.client.log('action1', 'http://example.com') self.client.log('action1', 'http://example.com')
self.client.log('action2', 'http://test.com', error=True, pi=3) self.client.log('action2', 'http://test.com', error=True, pi=3)
@ -138,37 +139,31 @@ class ClientTests(TestCase):
def test_get_update_queue(self): def test_get_update_queue(self):
self.client.track_url('never-updates', update_mins=0.01) self.client.track_url('never-updates', update_mins=0.01)
self.client.track_url('fake-1', update_mins=0.01) self.client.track_url('bad-uri', update_mins=0.01)
self.client.track_url('fake-2', update_mins=0.01) self.client.track_url('http://example.com', update_mins=0.01)
self.client.track_url('fake-3', update_mins=0.01)
never = self.client.db.tracked.find_one(dict(url='never-updates')) never = self.client.db.tracked.find_one(dict(url='never-updates'))
fake1 = self.client.db.tracked.find_one(dict(url='fake-1')) bad = self.client.db.tracked.find_one(dict(url='bad-uri'))
fake2 = self.client.db.tracked.find_one(dict(url='fake-2')) good = self.client.db.tracked.find_one(dict(url='http://example.com'))
fake3 = self.client.db.tracked.find_one(dict(url='fake-3'))
# 4 in queue, ordered by random # 3 in queue, ordered by random
queue = self.client.get_update_queue() queue = self.client.get_update_queue()
assert len(queue) == 4 assert len(queue) == 3
assert queue[0]['_random'] < queue[1]['_random'] < queue[2]['_random'] assert queue[0]['_random'] < queue[1]['_random'] < queue[2]['_random']
# update a few # try and update bad & good
self.client.update(fake1) self.client.update(bad)
self.client.update(fake2) self.client.update(good)
self.client.update(fake3)
# queue should only have never in it # queue should only have never in it
queue = self.client.get_update_queue() queue = self.client.get_update_queue()
assert len(queue) == 1
# wait for time to pass
time.sleep(1)
# queue should be full, but start with the un-updated one
queue = self.client.get_update_queue()
assert len(queue) == 4
assert queue[0]['_id'] == never['_id'] assert queue[0]['_id'] == never['_id']
# wait for time to pass so queue should be full
time.sleep(1)
queue = self.client.get_update_queue()
assert len(queue) == 3
def test_get_update_queue_size(self): def test_get_update_queue_size(self):
self.client.track_url('a', update_mins=0.01) self.client.track_url('a', update_mins=0.01)
@ -179,18 +174,13 @@ class ClientTests(TestCase):
b = self.client.db.tracked.find_one(dict(url='b')) b = self.client.db.tracked.find_one(dict(url='b'))
c = self.client.db.tracked.find_one(dict(url='c')) c = self.client.db.tracked.find_one(dict(url='c'))
# size should start at 3
assert self.client.get_update_queue_size() == 3 assert self.client.get_update_queue_size() == 3
# goes down one
self.client.update(a) self.client.update(a)
assert self.client.get_update_queue_size() == 2 assert self.client.get_update_queue_size() == 2
self.client.update(b) # wait for it to go back to 3
self.client.update(c)
assert self.client.get_update_queue_size() == 0
# wait
time.sleep(1) time.sleep(1)
assert self.client.get_update_queue_size() == 3 assert self.client.get_update_queue_size() == 3