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

Commit

Permalink
Ignore failures clearing db during tests; #907
Browse files Browse the repository at this point in the history
This is a hacky workaround.
  • Loading branch information
chadwhitacre committed May 1, 2013
1 parent de7222c commit de0a627
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
12 changes: 10 additions & 2 deletions gittip/models/__init__.py
Expand Up @@ -7,6 +7,14 @@
from gittip.models.transfer import Transfer
from gittip.models.user import User
from gittip.models.goal import Goal
from gittip.models.community import Community

all = [Elsewhere, Exchange, Participant, Payday, Tip, Transfer, User, Community]

# We actually don't want this one in here, because the only reason afaict for
# things to be in here is so that the test infrastructure automatically cleans
# up tables for us, but this is a view, not a table. XXX Even without this we
# still get OperationalErrors in the test suite.

#from gittip.models.community import Community


all = [Elsewhere, Exchange, Participant, Payday, Tip, Transfer, User]
11 changes: 8 additions & 3 deletions gittip/orm/__init__.py
Expand Up @@ -4,6 +4,7 @@
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker, scoped_session
from sqlalchemy.exc import OperationalError


class Model(object):
Expand Down Expand Up @@ -50,9 +51,13 @@ def make_declarative_base(self):
return base

def empty_tables(self):
for table in reversed(self.metadata.sorted_tables):
self.session.execute(table.delete())
self.session.commit()
tables = reversed(self.metadata.sorted_tables)
for table in tables:
try:
self.session.execute(table.delete())
self.session.commit()
except OperationalError:
self.session.rollback()
self.session.remove()

def drop_all(self):
Expand Down

0 comments on commit de0a627

Please sign in to comment.