Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
Rename delete to deactivate in models; #54
Browse files Browse the repository at this point in the history
  • Loading branch information
chadwhitacre committed Mar 8, 2013
1 parent ae95ec4 commit da001c8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion gittip/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# .metadata, and thus aren't cleaned up properly during teardown.)

from gittip.models.absorption import Absorption
from gittip.models.deletion import Deletion
from gittip.models.deactivation import Deactivation


# The rest we actually use.
Expand Down
6 changes: 3 additions & 3 deletions gittip/models/deletion.py → gittip/models/deactivation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

from gittip.orm import db

class Deletion(db.Model):
__tablename__ = 'deletions'
class Deactivation(db.Model):
__tablename__ = 'deactivations'

id = Column(Integer, nullable=False, primary_key=True)
timestamp = Column(TIMESTAMP(timezone=True), nullable=False,
default="now()")
deleted_was = Column(Text, nullable=False)
deactivated_was = Column(Text, nullable=False)
archived_as = Column(Text, ForeignKey("participants.id",
onupdate="RESTRICT",
ondelete="RESTRICT"), nullable=False)
13 changes: 8 additions & 5 deletions gittip/participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,14 +842,17 @@ def deactivate(self):
"""Deactivate this account.
"""
with gittip.db.get_transaction() as txn:
deleted_was = self.id
archived_as = self.archive(txn, deleted_was)
deactivated_was = self.id
archived_as = self.archive(txn, deactivated_was)
txn.execute("""
INSERT INTO deletions (deleted_was, archived_as)
VALUES (%s, %s)
INSERT
INTO deactivations
(deactivated_was, archived_as)
VALUES
(%s, %s)
""", (deleted_was, archived_as))
""", (deactivated_was, archived_as))
return archived_as


Expand Down
10 changes: 5 additions & 5 deletions tests/test_participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from aspen.utils import utcnow
from nose.tools import assert_raises, assert_equals

from gittip.models import Absorption, Deletion, User, Tip
from gittip.models import Absorption, Deactivation, User, Tip
from gittip.orm import db
from gittip.participant import Participant, NeedConfirmation
from gittip.testing import Harness, looks_random
Expand Down Expand Up @@ -135,22 +135,22 @@ def test_deleting_a_non_existent_user_assertion_errors(self):

def test_no_deactivations_to_start_with(self):
self.make_participant('alice')
actual = Deletion.query.filter_by().count()
actual = Deactivation.query.filter_by().count()
assert actual == 0, actual

def test_deactivate_records_one_deactivation(self):
self.make_participant('alice').deactivate()
actual = Deletion.query.filter_by().count()
actual = Deactivation.query.filter_by().count()
assert actual == 1, actual

def test_deactivation_records_deactivated_was(self):
self.make_participant('alice').deactivate()
actual = Deletion.query.filter_by()[0].deactivated_was
actual = Deactivation.query.filter_by()[0].deactivated_was
assert actual == 'alice', actual

def test_deactivation_records_archived_as(self):
self.make_participant('alice').deactivate()
actual = Deletion.query.filter_by()[0].archived_as
actual = Deactivation.query.filter_by()[0].archived_as
assert looks_random(actual)


Expand Down

0 comments on commit da001c8

Please sign in to comment.