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
|
@ -44,16 +44,18 @@ class Facet(object):
|
|||
'selectError': self.select_error,
|
||||
'invert': self.invert,
|
||||
}
|
||||
|
||||
|
||||
def include(self, selection):
|
||||
for s in self.selections:
|
||||
if s['v']['v'] == selection:
|
||||
return
|
||||
self.selections.append({'v': {'v': selection, 'l': selection}})
|
||||
|
||||
|
||||
def exclude(self, selection):
|
||||
self.selections = [s for s in self.selections if s['v']['v'] != selection]
|
||||
|
||||
|
||||
def reset(self):
|
||||
self.selections = []
|
||||
|
||||
|
||||
class FacetResponse(object):
|
||||
|
|
|
@ -20,21 +20,19 @@ class FacetTest(unittest.TestCase):
|
|||
facet = Facet('column name')
|
||||
engine = Engine(facet)
|
||||
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):
|
||||
engine = Engine()
|
||||
engine_json = engine.as_json()
|
||||
self.assertEqual(engine_json, '{"facets": [], "mode": "row-based"}')
|
||||
|
||||
|
||||
def test_add_facet(self):
|
||||
facet = Facet(column='Party Code')
|
||||
engine = Engine(facet)
|
||||
engine.add_facet(Facet(column='Ethnicity'))
|
||||
self.assertEqual(len(engine.facets), 2)
|
||||
self.assertEqual(len(engine), 2)
|
||||
|
||||
def test_selections(self):
|
||||
facet = Facet('column name')
|
||||
|
@ -43,13 +41,16 @@ class FacetTest(unittest.TestCase):
|
|||
facet.include('element 2')
|
||||
self.assertEqual(len(facet.selections), 2)
|
||||
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):
|
||||
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 = json.loads(response)
|
||||
facets = FacetsResponse(response)
|
||||
self.assertEqual(facets.facets[0].choices['D'].count, 3700)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
|
@ -79,15 +79,15 @@ class TutorialTestFacets(RefineTestCase):
|
|||
|
||||
def test_basic_facet(self):
|
||||
# {4}
|
||||
facet = Facet(column='Party Code')
|
||||
response = self.project.text_facet(facet)
|
||||
party_code_facet = Facet(column='Party Code')
|
||||
response = self.project.text_facet(party_code_facet)
|
||||
pc = response.facets[0]
|
||||
self.assertEqual(pc.name, 'Party Code')
|
||||
self.assertEqual(pc.choices['D'].count, 3700)
|
||||
self.assertEqual(pc.choices['N'].count, 15)
|
||||
self.assertEqual(pc.blank_choice.count, 1446)
|
||||
# {5}, {6}
|
||||
engine = Engine(facet)
|
||||
engine = Engine(party_code_facet)
|
||||
ethnicity_facet = Facet(column='Ethnicity')
|
||||
engine.add_facet(ethnicity_facet)
|
||||
self.project.engine = engine
|
||||
|
@ -108,7 +108,16 @@ class TutorialTestFacets(RefineTestCase):
|
|||
self.assertEqual(pc.choices['D'].count, 1179)
|
||||
self.assertEqual(pc.choices['R'].count, 11)
|
||||
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__':
|
||||
unittest.main()
|
Loading…
Reference in New Issue