def filtered_opportunities(self): filtered_opportunities = [opp for opp in self.opportunities] if self.sector.sectors: filtered_opportunities = helpers.filter_opportunities( filtered_opportunities, self.sector) if self.region.regions: filtered_opportunities = helpers.filter_opportunities( filtered_opportunities, self.region) if self.scale.selected_scales: filtered_opportunities = helpers.filter_opportunities( filtered_opportunities, self.scale) if self.sub_sector.sub_sectors: filtered_opportunities = helpers.filter_opportunities( filtered_opportunities, self.sub_sector) if self.sort_filter.sort_by_filter_chosen: filtered_opportunities = helpers.sort_opportunities( filtered_opportunities, self.sort_filter) return filtered_opportunities
def test_filter_opportunities_multiple_filters(): opportunities = [ { 'title': 'this one', 'related_sectors': [ { 'related_sector': '' }, { 'related_sector': { 'heading': 'Birmingham Curzon' } }, { 'related_sector': { 'heading': '' } }, ], 'scale_value': 0, 'related_region': { 'title': 'Midlands' }, }, { 'title': 'not this one', 'related_sectors': [ { 'related_sector': { 'heading': 'Aston Green' } }, ], 'scale_value': 3000, 'related_region': { 'title': '' }, }, ] filtered_opps = filter_opportunities(opportunities, SectorFilter('Birmingham Curzon')) filtered_opps = filter_opportunities(filtered_opps, RegionFilter('Midlands')) filtered_opps = filter_opportunities(filtered_opps, ScaleFilter('Value unknown')) assert len(filtered_opps) == 1 assert filtered_opps[0]['title'] == 'this one'
def test_filter_opportunities_sector(): opportunities = [ { 'related_sectors': [ { 'related_sector': { 'heading': 'Aston Green' } }, { 'related_sector': { 'heading': 'Birmingham Curzon' } }, ], }, { 'related_sectors': [ { 'related_sector': { 'heading': 'Aston Green' } }, ], }, ] filter_chosen = SectorFilter('Birmingham Curzon') filtered_opps = filter_opportunities(opportunities, filter_chosen) assert len(filtered_opps) == 1
def test_filter_opportunities_region(): opportunities = [ { 'related_region': { 'title': 'Midlands' } }, { 'related_region': '' }, { 'related_region': { 'title': 'Midlands' } }, { 'related_region': { 'title': '' } }, ] filter_chosen = RegionFilter('Midlands') filtered_opps = filter_opportunities(opportunities, filter_chosen) assert len(filtered_opps) == 2
def test_filter_opportunities_scale_greater_than_1000(): opportunities = [{ 'scale_value': 100 }, { 'scale_value': 1 }, { 'scale_value': 0 }, { 'scale_value': 3000 }] filter_chosen = ScaleFilter('> £1bn') filtered_opps = filter_opportunities(opportunities, filter_chosen) assert len(filtered_opps) == 1
def test_filter_opportunities_scale(): opportunities = [{ 'scale_value': 100 }, { 'scale_value': 3 }, { 'scale_value': 30 }, { 'scale_value': 3000 }] filter_chosen = ScaleFilter('< £100m') filtered_opps = filter_opportunities(opportunities, filter_chosen) assert len(filtered_opps) == 2
def test_filter_opportunities_sub_sector(): opportunities = [ { 'sub_sectors': ['Energy', 'Housing'], }, { 'sub_sectors': ['Mixed-use', 'Housing'], }, { 'sub_sectors': ['Energy', 'Mixed-use'], }, ] filter_chosen = SubSectorFilter('Housing') filtered_opps = filter_opportunities(opportunities, filter_chosen) assert len(filtered_opps) == 2
def test_filter_opportunities_scale_value_unknown(): opportunities = [{ 'scale_value': 100 }, { 'scale_value': 1 }, { 'scale_value': '0.00' }, { 'scale_value': 0.0 }, { 'scale_value': '0' }, { 'scale_value': '' }] filter_chosen = ScaleFilter('Value unknown') filtered_opps = filter_opportunities(opportunities, filter_chosen) assert len(filtered_opps) == 4