Skip to content

Commit

Permalink
Merge pull request #15 from jmhobbs/patch-1
Browse files Browse the repository at this point in the history
Add tag deletion method.
  • Loading branch information
mgan59 committed Dec 23, 2014
2 parents 62e50df + 313a0d8 commit f36826b
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 14 deletions.
15 changes: 15 additions & 0 deletions pinboard.py
Expand Up @@ -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__
Expand Down
69 changes: 55 additions & 14 deletions tests/test.py
Expand Up @@ -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']
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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.