Add engine.{remove,reset}_all().

This commit is contained in:
Paul Makepeace 2011-04-24 18:51:21 -04:00
parent da85e698dd
commit 2da0288975
3 changed files with 25 additions and 0 deletions

View File

@ -138,6 +138,13 @@ class Engine(object):
def add_facet(self, facet): def add_facet(self, facet):
self.facets.append(facet) self.facets.append(facet)
def remove_all(self):
self.facets = []
def reset_all(self):
for facet in self.facets:
facet.reset()
class RefineServer(object): class RefineServer(object):
"""Communicate with a Refine server.""" """Communicate with a Refine server."""

View File

@ -52,6 +52,20 @@ class FacetTest(unittest.TestCase):
facet.reset() facet.reset()
self.assertEqual(len(facet.selection), 0) self.assertEqual(len(facet.selection), 0)
def test_reset_remove(self):
text_facet1 = TextFacet('column name')
text_facet1.include('element')
text_facet2 = TextFacet('column name 2')
text_facet2.include('element 2')
engine = Engine([text_facet1, text_facet2])
self.assertEqual(len(engine), 2)
self.assertEqual(len(text_facet1.selection), 1)
engine.reset_all()
self.assertEqual(len(text_facet1.selection), 0)
self.assertEqual(len(text_facet2.selection), 0)
engine.remove_all()
self.assertEqual(len(engine), 0)
def test_facets_response(self): def test_facets_response(self):
response = """{"facets":[{"name":"Party Code","expression":"value","columnName":"Party Code","invert":false,"choices":[{"v":{"v":"D","l":"D"},"c":3700,"s":false},{"v":{"v":"R","l":"R"},"c":1613,"s":false},{"v":{"v":"N","l":"N"},"c":15,"s":false},{"v":{"v":"O","l":"O"},"c":184,"s":false}],"blankChoice":{"s":false,"c":1446}}],"mode":"row-based"}""" response = """{"facets":[{"name":"Party Code","expression":"value","columnName":"Party Code","invert":false,"choices":[{"v":{"v":"D","l":"D"},"c":3700,"s":false},{"v":{"v":"R","l":"R"},"c":1613,"s":false},{"v":{"v":"N","l":"N"},"c":15,"s":false},{"v":{"v":"O","l":"O"},"c":184,"s":false}],"blankChoice":{"s":false,"c":1446}}],"mode":"row-based"}"""

View File

@ -160,6 +160,10 @@ class TutorialTestFacets(RefineTestCase):
self.assertEqual(len(ot.choices), 21) self.assertEqual(len(ot.choices), 21)
self.assertEqual(ot.choices['Chief of Police'].count, 2) self.assertEqual(ot.choices['Chief of Police'].count, 2)
self.assertEqual(ot.choices['Chief of Police '].count, 211) self.assertEqual(ot.choices['Chief of Police '].count, 211)
# {14}
self.project.engine.remove_all()
response = self.project.get_rows()
self.assertEqual(response.filtered, 6958)
if __name__ == '__main__': if __name__ == '__main__':