Merge pull request #75 from pudo/enhancements-74

Add return value for Table.delete, add __repr__ to Table

Thanks to @cli248
This commit is contained in:
Stefan Wehrmeyer 2014-02-04 02:44:27 -08:00
commit a99ed6958c
3 changed files with 16 additions and 6 deletions

View File

@ -7,13 +7,13 @@ python:
env:
- DATABASE_URL=sqlite:///:memory:
- DATABASE_URL=postgresql+psycopg2://postgres@127.0.0.1/dataset
- DATABASE_URL=mysql+pymysql://travis@127.0.0.1/dataset?charset=utf8
- DATABASE_URL=mysql+mysqlconnector://travis@127.0.0.1/dataset?charset=utf8
install:
- pip install flake8 psycopg2 pymysql
- pip install flake8 psycopg2 mysql-connector-python
before_script:
- sh -c "if [ '$DATABASE_URL' = 'postgresql+psycopg2://postgres@127.0.0.1/dataset' ]; then psql -c 'DROP DATABASE IF EXISTS dataset;' -U postgres; fi"
- sh -c "if [ '$DATABASE_URL' = 'postgresql+psycopg2://postgres@127.0.0.1/dataset' ]; then psql -c 'create database dataset;' -U postgres; fi"
- sh -c "if [ '$DATABASE_URL' = 'mysql+pymysql://travis@127.0.0.1/dataset?charset=utf8' ]; then mysql -e 'create database IF NOT EXISTS dataset DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;'; fi"
- sh -c "if [ '$DATABASE_URL' = 'mysql+mysqlconnector://travis@127.0.0.1/dataset?charset=utf8' ]; then mysql -e 'create database IF NOT EXISTS dataset DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;'; fi"
script:
- flake8 --ignore=E501,E123,E124,E126,E127,E128 dataset test
- python setup.py test

View File

@ -181,7 +181,8 @@ class Table(object):
stmt = self.table.delete(q)
else:
stmt = self.table.delete()
self.database.executable.execute(stmt)
rows = self.database.executable.execute(stmt)
return rows.rowcount > 0
def _ensure_columns(self, row, types={}):
# Keep order of inserted columns
@ -406,3 +407,6 @@ class Table(object):
print(row)
"""
return self.all()
def __repr__(self):
return '<Table(%s)>' % self.table.name

View File

@ -179,11 +179,17 @@ class TableTestCase(unittest.TestCase):
'place': 'Berlin'}
)
assert len(self.tbl) == len(TEST_DATA) + 1, len(self.tbl)
self.tbl.delete(place='Berlin')
assert self.tbl.delete(place='Berlin') is True, 'should return 1'
assert len(self.tbl) == len(TEST_DATA), len(self.tbl)
self.tbl.delete()
assert self.tbl.delete() is True, 'should return non zero'
assert len(self.tbl) == 0, len(self.tbl)
def test_repr(self):
assert repr(self.tbl) == '<Table(weather)>', 'the representation should be <Table(weather)>'
def test_delete_nonexist_entry(self):
assert self.tbl.delete(place='Berlin') is False, 'entry not exist, should fail to delete'
def test_find_one(self):
self.tbl.insert({
'date': datetime(2011, 1, 2),