Skip to content

Commit

Permalink
Adding comment lines to delete user
Browse files Browse the repository at this point in the history
This line will avoid lose integrity of database

Signed-off-by: Lucas Kanashiro <kanashiro.duarte@gmail.com>
Signed-off-by: Macartur Sousa <macartur.sc@gmail.com>
  • Loading branch information
macartur committed May 17, 2016
1 parent 3887a18 commit f1c7d16
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
11 changes: 8 additions & 3 deletions colab/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,14 @@ def delete(self, using=None):
emails = " ".join(self.emails.values_list('address', flat=True))
super(User, self).delete(using)

user = User.objects.filter(id=self.id)
if not user:
delete_user.send(User, user=self, emails=emails)

#TODO:
# To maintain to integrity of the database we should deactive the user
# instead of delete. Or we will lose some data.

# user = User.objects.filter(id=self.id)
# if not user:
# delete_user.send(User, user=self, emails=emails)

# We need to have `email` field set as unique but Django does not
# support field overriding (at least not until 1.6).
Expand Down
37 changes: 19 additions & 18 deletions colab/super_archives/tests/test_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,22 @@ def create_user(self):

return user

@patch.object(User, 'update_subscription')
def test_delete_user_without_email(self, update_subscription_mock):
update_subscription_mock.return_value = True
self.user.delete()
self.assertEqual(0, update_subscription_mock.call_count)

@patch.object(User, 'update_subscription')
def test_delete_user_with_email(self, update_subscription_mock):
update_subscription_mock.return_value = True

EmailAddress.objects.get_or_create(user=self.user,
address="usertest@colab.com.br")
EmailAddress.objects.get_or_create(user=self.user,
address="teste@gmail.com")

self.user.delete()
self.assertEqual(2, update_subscription_mock.call_count)
self.assertEqual(0, EmailAddress.objects.count())
#TODO: see colab/accounts/models.py before uncomment this lines
#@patch.object(User, 'update_subscription')
#def test_delete_user_without_email(self, update_subscription_mock):
# update_subscription_mock.return_value = True
# self.user.delete()
# self.assertEqual(0, update_subscription_mock.call_count)

#@patch.object(User, 'update_subscription')
#def test_delete_user_with_email(self, update_subscription_mock):
# update_subscription_mock.return_value = True

# EmailAddress.objects.get_or_create(user=self.user,
# address="usertest@colab.com.br")
# EmailAddress.objects.get_or_create(user=self.user,
# address="teste@gmail.com")

# self.user.delete()
# self.assertEqual(2, update_subscription_mock.call_count)
# self.assertEqual(0, EmailAddress.objects.count())

0 comments on commit f1c7d16

Please sign in to comment.