From 34bf9acd56d36f096b3fe37bf95aaf408ab3cde7 Mon Sep 17 00:00:00 2001 From: James Turk Date: Thu, 4 Aug 2011 15:02:02 -0400 Subject: [PATCH] flesh out update tests --- oyster/client.py | 2 +- oyster/tests/test_client.py | 46 ++++++++++++++++++++++++++++++++++++- oyster/web.py | 2 +- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/oyster/client.py b/oyster/client.py index 0e2564a..7448d66 100644 --- a/oyster/client.py +++ b/oyster/client.py @@ -105,7 +105,7 @@ class Client(object): doc['versioning']) if do_put: - self.fs.put(data, filename=doc['url'], mimetype=content_type, + self.fs.put(data, filename=doc['url'], content_type=content_type, **doc['metadata']) # last_update/next_update are separate from question of versioning diff --git a/oyster/tests/test_client.py b/oyster/tests/test_client.py index 2a8f2ca..0cb6f44 100644 --- a/oyster/tests/test_client.py +++ b/oyster/tests/test_client.py @@ -64,7 +64,8 @@ class ClientTests(TestCase): def test_update(self): - self.client.track_url('http://google.com', update_mins=60) + # get a single document tracked + self.client.track_url('http://example.com', update_mins=60, pi=3) obj = self.client.db.tracked.find_one() self.client.update(obj) @@ -73,4 +74,47 @@ class ClientTests(TestCase): assert (newobj['last_update'] + datetime.timedelta(minutes=newobj['update_mins']) == newobj['next_update']) + first_update = newobj['last_update'] assert newobj['consecutive_errors'] == 0 + + # check that document exists in database + doc = self.client.fs.get_last_version() + assert doc.filename == 'http://example.com' + assert doc.content_type.startswith('text/html') + assert doc.pi == 3 + + # check logs + assert self.client.db.logs.find({'action': 'update'}).count() == 1 + + # and do an update.. + self.client.update(obj) + + # hopefully example.com hasn't changed, this tests that md5 worked + assert self.client.db.fs.files.count() == 1 + + # check that appropriate metadata updated + newobj = self.client.db.tracked.find_one() + assert first_update < newobj['last_update'] + + # check that logs updated + assert self.client.db.logs.find({'action': 'update'}).count() == 2 + + + def test_update_failure(self): + # track a non-existent URL + self.client.track_url('http://not_a_url') + obj = self.client.db.tracked.find_one() + self.client.update(obj) + + obj = self.client.db.tracked.find_one() + assert obj['consecutive_errors'] == 1 + + # we should have logged an error too + assert self.client.db.logs.find({'action': 'update', + 'error': {'$ne': False}}).count() == 1 + + # update again + self.client.update(obj) + + obj = self.client.db.tracked.find_one() + assert obj['consecutive_errors'] == 2 diff --git a/oyster/web.py b/oyster/web.py index 8fba4d5..2576b6b 100644 --- a/oyster/web.py +++ b/oyster/web.py @@ -78,7 +78,7 @@ def show_doc(url, version): version = -1 doc = client.get_version(url, version) resp = flask.make_response(doc.read()) - resp.headers['content-type'] = doc.mimetype + resp.headers['content-type'] = doc.content_type return resp