Skip to content

Commit

Permalink
Deleting a user is now possible.
Browse files Browse the repository at this point in the history
  • Loading branch information
toastdriven committed Jan 24, 2012
1 parent de1a4d9 commit c8b1860
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
4 changes: 4 additions & 0 deletions friendlydb/db.py
Expand Up @@ -92,3 +92,7 @@ def __getitem__(self, username):
kwargs['separator'] = self.separator

return self.user_klass(username, self.data_directory, **kwargs)

def delete_user(self, username):
user = self[username]
return user.delete()
13 changes: 13 additions & 0 deletions friendlydb/user.py
Expand Up @@ -214,3 +214,16 @@ def is_following(self, username):
def is_followed_by(self, username):
followers = self.followers()
return username in followers

def delete(self):
following = self.following()
followers = self.followers()

for follow in following:
self.unfollow(follow)

for follower in followers:
other = self.__class__(follower, self.data_directory, hash_width=self.hash_width, separator=self.separator)
other.unfollow(self.username)

return True
42 changes: 42 additions & 0 deletions tests.py
Expand Up @@ -180,6 +180,30 @@ def test_followers_history(self):
self.assertEqual(len(history[0]), 3)
self.assertEqual([(bits[0], bits[1]) for bits in history], [('Added', 'daniel'), ('Added', 'alice'), ('Deleted', 'daniel'), ('Added', 'daniel')])

def test_unfollow(self):
self.assertTrue(self.daniel.follow('alice'))
self.assertTrue(self.daniel.follow('bob'))
self.assertTrue(self.daniel.follow('joe'))
self.assertTrue(self.alice.follow('daniel'))
self.assertTrue(self.alice.follow('bob'))
self.assertTrue(self.bob.follow('daniel'))

# Make sure it worked.
daniel_following = self.daniel.following()
self.assertEqual(daniel_following, ['alice', 'bob', 'joe'])
alice_followers = self.alice.followers()
self.assertEqual(alice_followers, ['daniel'])
alice_following = self.alice.following()
self.assertEqual(alice_following, ['daniel', 'bob'])

# Kaboom!
self.daniel.delete()

alice_followers = self.alice.followers()
self.assertEqual(alice_followers, [])
alice_following = self.alice.following()
self.assertEqual(alice_following, ['bob'])


class FriendlyDBTestCase(FriendlyTestCase):
def test_init(self):
Expand Down Expand Up @@ -233,3 +257,21 @@ def test_clear(self):

self.assertTrue(fdb.clear())
self.assertFalse(os.path.exists(daniel.full_path))

def test_delete_user(self):
fdb = FriendlyDB(data_directory=self.data_dir)
daniel = fdb['daniel']
alice = fdb['alice']
bob = fdb['bob']

daniel.follow('alice')
alice.follow('daniel')
alice.follow('bob')

self.assertEqual(daniel.following(), ['alice'])
self.assertEqual(alice.following(), ['daniel', 'bob'])
self.assertEqual(alice.followers(), ['daniel'])

fdb.delete_user('alice')

self.assertEqual(daniel.following(), [])

0 comments on commit c8b1860

Please sign in to comment.