def test_filter_value(self): filter = ReportFilter.wrap({ "type": "location_drilldown", "field": "block_id", "slug": "block_id_drill", "display": "Drilldown by Location", }) filter_value = LocationDrilldownFilterValue(filter, ['Middlesex']) self.assertDictEqual(filter_value.to_sql_values(), {'block_id_drill_0': 'Middlesex'})
def test_filter_value(self): filter = { "type": "location_drilldown", "field": "block_id", "slug": "block_id_drill", "display": "Drilldown by Location", } filter_value = LocationDrilldownFilterValue(filter, ['Middlesex']) self.assertDictEqual(filter_value.to_sql_values(), {'block_id_drill_0': 'Middlesex'}) self.assertEqual(str(filter_value.to_sql_filter().build_expression()), 'block_id IN (:block_id_drill_0)') self.assertEqual(filter_value.to_sql_values(), {'block_id_drill_0': 'Middlesex'})
def test_filter_value(self): filter = { "type": "location_drilldown", "field": "block_id", "slug": "block_id_drill", "display": "Drilldown by Location", } filter_value = LocationDrilldownFilterValue(filter, ['Middlesex']) self.assertDictEqual(filter_value.to_sql_values(), {'block_id_drill_0': 'Middlesex'}) self.assertEqual( str(filter_value.to_sql_filter().build_expression()), 'block_id IN (:block_id_drill_0)' ) self.assertEqual( filter_value.to_sql_values(), {'block_id_drill_0': 'Middlesex'} )
def test_filter_value(self): from sqlalchemy import Column, String mock_table = Mock() mock_table.c = [ Column(f, type_=String) for f in ['block_id', 'state_id'] ] filter = { "type": "location_drilldown", "field": "block_id", "slug": "block_id_drill", "display": "Drilldown by Location", } filter_value = LocationDrilldownFilterValue(filter, ['Middlesex']) self.assertDictEqual(filter_value.to_sql_values(), {'block_id_drill_0': 'Middlesex'}) self.assertEqual( str(filter_value.to_sql_filter().build_expression(mock_table)), 'block_id IN (:block_id_drill_0)') self.assertEqual(filter_value.to_sql_values(), {'block_id_drill_0': 'Middlesex'})
def test_prefix_ancestor_location(self): filter = { "type": "location_drilldown", "field": "block_id", "slug": "block_id_drill", "display": "Drilldown by Location", "ancestor_expression": { 'field': 'state_id', 'location_type': 'state', } } middlesex_id = self.locations['Middlesex'].location_id mass_id = self.locations['Massachusetts'].location_id # make sure ancestor gets passed if right block is passed filter_value = LocationDrilldownFilterValue(filter, [middlesex_id]) self.assertEqual( str(filter_value.to_sql_filter().build_expression()), 'state_id = :state_id AND block_id IN (:block_id_drill_0)' ) self.assertEqual( filter_value.to_sql_values(), {'state_id': mass_id, 'block_id_drill_0': middlesex_id} ) # make sure ancestor doesn't get passed if multiple locations are passed filter_value = LocationDrilldownFilterValue(filter, [middlesex_id, 'Suffolk']) self.assertEqual( str(filter_value.to_sql_filter().build_expression()), 'block_id IN (:block_id_drill_0, :block_id_drill_1)' ) self.assertEqual( filter_value.to_sql_values(), {'block_id_drill_0': middlesex_id, 'block_id_drill_1': 'Suffolk'} ) # no ancestor is passed if passed in location is invalid filter_value = LocationDrilldownFilterValue(filter, ['random']) self.assertEqual( str(filter_value.to_sql_filter().build_expression()), 'block_id IN (:block_id_drill_0)' ) self.assertEqual( filter_value.to_sql_values(), {'block_id_drill_0': 'random'} )
def test_prefix_ancestor_location(self): filter = { "type": "location_drilldown", "field": "block_id", "slug": "block_id_drill", "display": "Drilldown by Location", "ancestor_expression": { 'field': 'state_id', 'location_type': 'state', } } middlesex_id = self.locations['Middlesex'].location_id mass_id = self.locations['Massachusetts'].location_id # make sure ancestor gets passed if right block is passed filter_value = LocationDrilldownFilterValue(filter, [middlesex_id]) self.assertEqual( str(filter_value.to_sql_filter().build_expression()), 'state_id = :state_id AND block_id IN (:block_id_drill_0)') self.assertEqual(filter_value.to_sql_values(), { 'state_id': mass_id, 'block_id_drill_0': middlesex_id }) # make sure ancestor doesn't get passed if multiple locations are passed filter_value = LocationDrilldownFilterValue(filter, [middlesex_id, 'Suffolk']) self.assertEqual(str(filter_value.to_sql_filter().build_expression()), 'block_id IN (:block_id_drill_0, :block_id_drill_1)') self.assertEqual(filter_value.to_sql_values(), { 'block_id_drill_0': middlesex_id, 'block_id_drill_1': 'Suffolk' }) # no ancestor is passed if passed in location is invalid filter_value = LocationDrilldownFilterValue(filter, ['random']) self.assertEqual(str(filter_value.to_sql_filter().build_expression()), 'block_id IN (:block_id_drill_0)') self.assertEqual(filter_value.to_sql_values(), {'block_id_drill_0': 'random'})