From 51480fafccbc9ccb62de92a1f17549d05ec89560 Mon Sep 17 00:00:00 2001 From: James Turk Date: Wed, 28 Sep 2011 15:50:32 -0400 Subject: [PATCH] track_url with same parameters returns original id --- oyster/client.py | 16 +++++++++++++--- oyster/tests/test_client.py | 10 +++++++--- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/oyster/client.py b/oyster/client.py index 60f6dde..6e8ada9 100644 --- a/oyster/client.py +++ b/oyster/client.py @@ -84,9 +84,19 @@ class Client(object): url URL to start tracking """ - if self.db.tracked.find_one({'url': url}): - self.log('track', url=url, error='already tracked') - raise ValueError('%s is already tracked' % url) + tracked = self.db.tracked.find_one({'url': url}) + + # if data is already tracked and this is just a duplicate call + # return the original object + if tracked: + if (tracked['metadata'] == kwargs and + tracked['versioning'] == versioning and + tracked['update_mins'] == update_mins): + return tracked['_id'] + else: + self.log('track', url=url, error='tracking conflict') + raise ValueError('%s is already tracked with different ' + 'metadata' % url) self.log('track', url=url) return self.db.tracked.insert(dict(url=url, versioning=versioning, diff --git a/oyster/tests/test_client.py b/oyster/tests/test_client.py index b836cba..d425f80 100644 --- a/oyster/tests/test_client.py +++ b/oyster/tests/test_client.py @@ -42,7 +42,7 @@ class ClientTests(TestCase): def test_track_url(self): # basic insert - self.client.track_url('http://example.com', update_mins=30, pi=3) + id1 = self.client.track_url('http://example.com', update_mins=30, pi=3) obj = self.client.db.tracked.find_one() assert '_random' in obj assert obj['update_mins'] == 30 @@ -53,11 +53,15 @@ class ClientTests(TestCase): assert log['action'] == 'track' assert log['url'] == 'http://example.com' - # can't track same URL twice + # track same url again with same metadata returns id + id2 = self.client.track_url('http://example.com', update_mins=30, pi=3) + assert id1 == id2 + + # can't track same URL twice with different metadata assert_raises(ValueError, self.client.track_url, 'http://example.com') # logged error - assert self.client.db.logs.find_one({'error': 'already tracked'}) + assert self.client.db.logs.find_one({'error': 'tracking conflict'}) def test_md5_versioning(self):