Remove redundant add facet test. Add Facet.reset(). Add tests for filtering on 2nd facet, and reset'ing both.
This commit is contained in:
parent
a2fa25d4e4
commit
686723445b
|
@ -54,6 +54,8 @@ class Facet(object):
|
||||||
def exclude(self, selection):
|
def exclude(self, selection):
|
||||||
self.selections = [s for s in self.selections if s['v']['v'] != selection]
|
self.selections = [s for s in self.selections if s['v']['v'] != selection]
|
||||||
|
|
||||||
|
def reset(self):
|
||||||
|
self.selections = []
|
||||||
|
|
||||||
|
|
||||||
class FacetResponse(object):
|
class FacetResponse(object):
|
||||||
|
|
|
@ -20,10 +20,7 @@ class FacetTest(unittest.TestCase):
|
||||||
facet = Facet('column name')
|
facet = Facet('column name')
|
||||||
engine = Engine(facet)
|
engine = Engine(facet)
|
||||||
self.assertTrue(str(engine))
|
self.assertTrue(str(engine))
|
||||||
facet2 = Facet('Ethnicity')
|
|
||||||
engine.add_facet(facet2)
|
|
||||||
self.assertEqual(len(engine.facets), 2)
|
|
||||||
self.assertEqual(len(engine), 2)
|
|
||||||
|
|
||||||
def test_serialize(self):
|
def test_serialize(self):
|
||||||
engine = Engine()
|
engine = Engine()
|
||||||
|
@ -35,6 +32,7 @@ class FacetTest(unittest.TestCase):
|
||||||
engine = Engine(facet)
|
engine = Engine(facet)
|
||||||
engine.add_facet(Facet(column='Ethnicity'))
|
engine.add_facet(Facet(column='Ethnicity'))
|
||||||
self.assertEqual(len(engine.facets), 2)
|
self.assertEqual(len(engine.facets), 2)
|
||||||
|
self.assertEqual(len(engine), 2)
|
||||||
|
|
||||||
def test_selections(self):
|
def test_selections(self):
|
||||||
facet = Facet('column name')
|
facet = Facet('column name')
|
||||||
|
@ -44,6 +42,9 @@ class FacetTest(unittest.TestCase):
|
||||||
self.assertEqual(len(facet.selections), 2)
|
self.assertEqual(len(facet.selections), 2)
|
||||||
facet.exclude('element')
|
facet.exclude('element')
|
||||||
self.assertEqual(len(facet.selections), 1)
|
self.assertEqual(len(facet.selections), 1)
|
||||||
|
facet.reset()
|
||||||
|
self.assertEqual(len(facet.selections), 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"}"""
|
||||||
|
|
|
@ -79,15 +79,15 @@ class TutorialTestFacets(RefineTestCase):
|
||||||
|
|
||||||
def test_basic_facet(self):
|
def test_basic_facet(self):
|
||||||
# {4}
|
# {4}
|
||||||
facet = Facet(column='Party Code')
|
party_code_facet = Facet(column='Party Code')
|
||||||
response = self.project.text_facet(facet)
|
response = self.project.text_facet(party_code_facet)
|
||||||
pc = response.facets[0]
|
pc = response.facets[0]
|
||||||
self.assertEqual(pc.name, 'Party Code')
|
self.assertEqual(pc.name, 'Party Code')
|
||||||
self.assertEqual(pc.choices['D'].count, 3700)
|
self.assertEqual(pc.choices['D'].count, 3700)
|
||||||
self.assertEqual(pc.choices['N'].count, 15)
|
self.assertEqual(pc.choices['N'].count, 15)
|
||||||
self.assertEqual(pc.blank_choice.count, 1446)
|
self.assertEqual(pc.blank_choice.count, 1446)
|
||||||
# {5}, {6}
|
# {5}, {6}
|
||||||
engine = Engine(facet)
|
engine = Engine(party_code_facet)
|
||||||
ethnicity_facet = Facet(column='Ethnicity')
|
ethnicity_facet = Facet(column='Ethnicity')
|
||||||
engine.add_facet(ethnicity_facet)
|
engine.add_facet(ethnicity_facet)
|
||||||
self.project.engine = engine
|
self.project.engine = engine
|
||||||
|
@ -108,7 +108,16 @@ class TutorialTestFacets(RefineTestCase):
|
||||||
self.assertEqual(pc.choices['D'].count, 1179)
|
self.assertEqual(pc.choices['D'].count, 1179)
|
||||||
self.assertEqual(pc.choices['R'].count, 11)
|
self.assertEqual(pc.choices['R'].count, 11)
|
||||||
self.assertEqual(pc.blank_choice.count, 46)
|
self.assertEqual(pc.blank_choice.count, 46)
|
||||||
|
# {9}
|
||||||
|
party_code_facet.include('R')
|
||||||
|
response = self.project.text_facet()
|
||||||
|
e = response.facets[1]
|
||||||
|
self.assertEqual(e.choices['B'].count, 11)
|
||||||
|
# {10}
|
||||||
|
party_code_facet.reset()
|
||||||
|
ethnicity_facet.reset()
|
||||||
|
response = self.project.get_rows()
|
||||||
|
self.assertEqual(response.filtered, 6958)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
Loading…
Reference in New Issue