Add row indexing to get_rows()'s response.rows.

This commit is contained in:
Paul Makepeace 2011-04-26 14:54:44 -04:00
parent d5038c6618
commit bde4eb7466
3 changed files with 53 additions and 1 deletions

View File

@ -178,6 +178,8 @@ def RowsResponseFactory(column_index):
def __iter__(self):
for row_response in self.rows_response:
yield self.RefineRow(row_response)
def __getitem__(self, index):
return self.RefineRow(self.rows_response[index])
def __len__(self):
return len(self.rows_response)

View File

@ -326,7 +326,7 @@ class TutorialTestTransposeColumnsIntoRows(RefineTestCase):
response['historyEntry']['description'])
# spot check of last row for transforms and fill down
response = self.project.get_rows()
row10 = [r for r in response.rows][9]
row10 = response.rows[9]
self.assertEqual(row10['country_name'], 'Afghanistan')
self.assertEqual(row10['program_name'],
'Department of Defense Security Assistance')

View File

@ -0,0 +1,50 @@
#!/usr/bin/env python
"""
test_refine_small.py
"""
# Copyright (c) 2011 Paul Makepeace, Real Programmers. All rights reserved.
import unittest
from google.refine import refine
class RefineRowsTest(unittest.TestCase):
def test_rows_response(self):
rr = refine.RowsResponseFactory({
u'gender': 3, u'state': 2, u'purchase': 4, u'email': 0,
u'name': 1})
response = rr({
u'rows': [{
u'i': 0,
u'cells': [
{u'v': u'danny.baron@example1.com'},
{u'v': u'Danny Baron'},
{u'v': u'CA'},
{u'v': u'M'},
{u'v': u'TV'}
],
u'starred': False,
u'flagged': False
}],
u'start': 0,
u'limit': 1,
u'mode': u'row-based',
u'filtered': 10,
u'total': 10,
u'pool': {
u'recons': {},
u'reconCandidates': {}
}
})
self.assertEqual(len(response.rows), 1)
# test iteration
rows = [row for row in response.rows]
self.assertEqual(rows[0]['name'], 'Danny Baron')
# test indexing
self.assertEqual(response.rows[0]['name'], 'Danny Baron')
if __name__ == '__main__':
unittest.main()