Permalink
Browse files

Merge pull request #15 from jmhobbs/patch-1

Add tag deletion method.
  • Loading branch information...
2 parents 62e50df + 313a0d8 commit f36826b1ca9b5882081b06e2b00d2ef2bab3c9d0 @mgan59 committed Dec 23, 2014
Showing with 70 additions and 14 deletions.
  1. +15 −0 pinboard.py
  2. +55 −14 tests/test.py
View
@@ -577,6 +577,21 @@ def rename_tag(self, old, new):
sys.stderr.write("Unable to rename %s tag to %s in pinboard.in\n" \
% (old, new))
+ def delete_tag(self, name):
+ """Delete a tag from pinboard.in by its name"""
+ try:
+ response = self.__request("%s/tags/delete?%s" % (PINBOARD_API, \
+ urllib.urlencode({"tag":name})))
+ if response.firstChild.getAttribute("code") != u"done":
+ raise DeleteBundleError
+ if _debug:
+ sys.stderr.write("Tag, %s, deleted from pinboard.in\n" \
+ % name)
+ except:
+ if _debug:
+ sys.stderr.write("Unable to delete tag, %s, from pinboard.in\n" \
+ % name)
+
if __name__ == "__main__":
if sys.argv[1:][0] == '-v' or sys.argv[1:][0] == '--version':
print __version__
View
@@ -18,6 +18,13 @@
import pinboard
+def api_wait():
+# Looks like there is no immediate consistency between API inputs
+# and outputs, that's why additional delays added here and below.
+ print 'API Threshold Delay (3 seconds)'
+ time.sleep(3)
+ print 'API Resuming'
+
def get_tag_names(tags):
for tag in tags:
yield tag['name']
@@ -54,25 +61,16 @@ def common_case(self, p):
self.assertIs(type(posts), list)
self.assertFalse(posts)
- # Looks like there is no immediate consistency between API inputs
- # and outputs, that's why additional delays added here and below.
- print 'API Threshold Delay (3 seconds)'
- time.sleep(3)
-
- print 'API Resuming'
+ api_wait()
posts = p.posts(tag=test_tag)
# Bookmark was added
self.assertIs(type(posts), list)
self.assertTrue(posts)
- # Looks like there is no immediate consistency between API inputs
- # and outputs, that's why additional delays added here and below.
- print 'API Threshold Delay (3 seconds)'
- time.sleep(3)
+ api_wait()
- print 'API Resuming'
# Tags contains new tag
tags = p.tags()
self.assertTrue(type(tags), dict)
@@ -82,10 +80,8 @@ def common_case(self, p):
for post in posts:
p.delete(post['href'])
- print 'API Threshold Delay (3 seconds)'
- time.sleep(3)
+ api_wait()
- print 'API Resuming'
# There are no posts with test tag
posts = p.posts(tag=test_tag)
self.assertFalse(posts)
@@ -95,5 +91,50 @@ def common_case(self, p):
self.assertNotIn(test_tag, tags)
+ def test_delete_tag(self):
+ """Test tag deletion"""
+ p = pinboard.open(token=conf.token)
+
+ test_url = 'http://github.com'
+ test_tag = '__testing__'
+
+ # Clean pre-conditions
+ p.delete(test_url)
+
+ # Test pre-conditions (no test tag)
+ tags = p.tags()
+ self.assertNotIn(test_tag, get_tag_names(tags))
+
+ # Adding a test bookmark
+ p.add(url=test_url,
+ description='GitHub',
+ extended='It\'s a GitHub!',
+ tags=(test_tag),
+ toread=False,
+ replace="yes")
+
+ api_wait()
+
+ # Tags contains new tag
+ tags = p.tags()
+ self.assertTrue(type(tags), dict)
+ self.assertIn(test_tag, get_tag_names(tags))
+
+ # Deleting test tag
+ p.delete_tag(test_tag)
+
+ api_wait()
+
+ # There are no posts with test tag
+ posts = p.posts(tag=test_tag)
+ self.assertFalse(posts)
+
+ # And no test tag any more
+ tags = p.tags()
+ self.assertNotIn(test_tag, get_tag_names(tags))
+
+ # Clean Up
+ p.delete(test_url)
+
if __name__ == '__main__':
unittest.main()

0 comments on commit f36826b

Please sign in to comment.