def test_filter_by_tags_and(self): """Show only commrec with correct tags in 'and' configuration.""" ds = CommRecordsDataSource() recs = ds.run_unaggregated( self.company, CommRecordsFilter(tags=AndGroupFilter([ OrGroupFilter([MatchFilter('EaSt')]), OrGroupFilter([MatchFilter('wEsT')]) ])), []) subjects = {r['subject'] for r in recs} expected = set() self.assertEqual(expected, subjects) # Now try adding another tag. self.record_1.tags.add(self.west_tag) self.record_1.save() recs = ds.run_unaggregated( self.company, CommRecordsFilter(tags=AndGroupFilter([ OrGroupFilter([MatchFilter('EaSt')]), OrGroupFilter([MatchFilter('wEsT')]) ])), []) subjects = {r['subject'] for r in recs} expected = {self.record_1.subject} self.assertEqual(expected, subjects)
def test_clone_without_empty(self): """ Cloning empty filters shouldn't crash. """ filter = CommRecordsFilter() self.assertEqual(CommRecordsFilter(), filter.clone_without_city()) self.assertEqual(CommRecordsFilter(), filter.clone_without_state())
def test_clone_without_partners(self): filter = CommRecordsFilter( partner=[1, 2, 3], locations={'city': 'A', 'state': 'B'}) expected_filter = CommRecordsFilter( locations={'city': 'A', 'state': 'B'}) self.assertEqual( expected_filter, filter.clone_without_partner())
def test_clone_without_partners(self): filter = CommRecordsFilter(partner=[1, 2, 3], locations={ 'city': 'A', 'state': 'B' }) expected_filter = CommRecordsFilter(locations={ 'city': 'A', 'state': 'B' }) self.assertEqual(expected_filter, filter.clone_without_partner())
def test_clone_without_full(self): """Cloning should remove certain fields.""" filter = CommRecordsFilter( tags=['C'], locations={'city': 'A', 'state': 'B'}) expected_with_city = CommRecordsFilter( tags=['C'], locations={'city': 'A'}) expected_with_state = CommRecordsFilter( tags=['C'], locations={'state': 'B'}) self.assertEqual(expected_with_state, filter.clone_without_city()) self.assertEqual(expected_with_city, filter.clone_without_state())
def test_help_tags_colors(self): """ Tags should have colors """ ds = CommRecordsDataSource() recs = ds.help_tags(self.company, CommRecordsFilter(), "east") self.assertEqual("aaaaaa", recs[0]['hexColor'])
def test_help_partner_tags(self): """ Check partner tags help works at all. """ ds = CommRecordsDataSource() recs = ds.help_partner_tags(self.company, CommRecordsFilter(), "t") actual = {r['value'] for r in recs} self.assertEqual({'left', 'right'}, actual)
def test_filter_by_date_after(self): """Should show only commrec with last_action_time after date.""" ds = CommRecordsDataSource() date_range = DateRangeFilter([datetime(2015, 10, 1), None]) recs = ds.run_unaggregated(self.company, CommRecordsFilter(date_time=date_range), []) subjects = {r['subject'] for r in recs} expected = {self.record_3.subject} self.assertEqual(expected, subjects)
def test_help_tags(self): """ Check tags help works at all. """ ds = CommRecordsDataSource() recs = ds.help_tags(self.company, CommRecordsFilter(), "E") actual = {r['value'] for r in recs} self.assertEqual({'east', 'west'}, actual)
def test_help_contact_tags(self): """ Check contact tags help works at all. """ ds = CommRecordsDataSource() recs = ds.help_contact_tags(self.company, CommRecordsFilter(), "O") actual = {r['value'] for r in recs} self.assertEqual({'north', 'south'}, actual)
def test_filter_by_communication_type(self): """Check communication_type filter works at all.""" ds = CommRecordsDataSource() recs = ds.run_unaggregated( self.company, CommRecordsFilter( communication_type=OrGroupFilter([MatchFilter('email')])), []) subjects = {r['subject'] for r in recs} expected = {self.record_1.subject} self.assertEqual(expected, subjects)
def test_filter_by_city(self): """Should show only commrecs with correct city.""" ds = CommRecordsDataSource() recs = ds.run_unaggregated( self.company, CommRecordsFilter(locations=CompositeAndFilter( {'city': MatchFilter('Los Angeles')})), []) subjects = {r['subject'] for r in recs} expected = {self.record_3.subject} self.assertEqual(expected, subjects)
def test_help_contact(self): """ Check contact help works at all. """ ds = CommRecordsDataSource() recs = ds.help_contact(self.company, CommRecordsFilter(), "U") self.assertEqual([{ 'value': self.sue.pk, 'display': self.sue.name }], recs)
def test_run_unfiltered(self): """Make sure we only get data for this user.""" ds = CommRecordsDataSource() recs = ds.run_unaggregated(self.company, CommRecordsFilter(), []) subjects = {r['subject'] for r in recs} expected = { self.record_1.subject, self.record_2.subject, self.record_3.subject, } self.assertEqual(expected, subjects)
def test_help_communication_types(self): """ Check communication_types help works at all. """ ds = CommRecordsDataSource() recs = ds.help_communication_type(self.company, CommRecordsFilter(), "ph") actual = {r['value'] for r in recs} expected = {'phone', 'job', 'meetingorevent', 'email', 'pssemail'} self.assertEqual(expected, actual)
def test_help_partner(self): """ Check partner help works at all. """ ds = CommRecordsDataSource() recs = ds.help_partner(self.company, CommRecordsFilter(), "A") self.assertEqual([{ 'value': self.partner_a.pk, 'display': self.partner_a.name }], recs)
def test_clone_without_full(self): """ Cloning should remove certain fields. """ filter = CommRecordsFilter( tags=['C'], locations=CompositeAndFilter({ 'city': MatchFilter('A'), 'state': MatchFilter('B')})) expected_with_city = CommRecordsFilter( tags=['C'], locations=CompositeAndFilter({ 'city': MatchFilter('A')})) expected_with_state = CommRecordsFilter( tags=['C'], locations=CompositeAndFilter({ 'state': MatchFilter('B')})) self.assertEqual(expected_with_state, filter.clone_without_city()) self.assertEqual(expected_with_city, filter.clone_without_state())
def test_filter_by_partner_tags_untagged(self): """ Check that we can find a record attached to an untagged partner. """ self.partner_b.tags.clear() ds = CommRecordsDataSource() recs = ds.run_unaggregated( self.company, CommRecordsFilter(partner_tags=UnlinkedFilter()), []) subjects = {r['subject'] for r in recs} expected = {self.record_3.subject} self.assertEqual(expected, subjects)
def test_help_state(self): """ Check state help works and ignores current state filter. """ ds = CommRecordsDataSource() recs = ds.help_state( self.company, CommRecordsFilter( locations=CompositeAndFilter({'state': MatchFilter("zz")})), "i") actual = {r['value'] for r in recs} self.assertEqual({'IL', 'IN'}, actual)
def test_filter_by_tags_unlinked(self): """ Only return untagged commrecs. """ self.record_1.tags.clear() ds = CommRecordsDataSource() recs = ds.run_unaggregated(self.company, CommRecordsFilter(tags=UnlinkedFilter()), []) subjects = {r['subject'] for r in recs} expected = {self.record_1.subject} self.assertEqual(expected, subjects)
def test_filter_by_contact(self): """ Check partner filter works at all. """ ds = CommRecordsDataSource() recs = ds.run_unaggregated( self.company, CommRecordsFilter( contact=OrGroupFilter([MatchFilter(self.sue.pk)])), []) subjects = {r['subject'] for r in recs} expected = {self.record_3.subject} self.assertEqual(expected, subjects)
def test_filter_by_partner_tags(self): """ Test that we can filter by partner tags. """ ds = CommRecordsDataSource() recs = ds.run_unaggregated( self.company, CommRecordsFilter(partner_tags=AndGroupFilter( [OrGroupFilter([MatchFilter('rigHt')])])), []) subjects = {r['subject'] for r in recs} expected = {self.record_3.subject} self.assertEqual(expected, subjects)
def test_help_city(self): """ Check city help works and ignores current city filter. """ ds = CommRecordsDataSource() recs = ds.help_city( self.company, CommRecordsFilter( locations=CompositeAndFilter({'city': MatchFilter("zz")})), "angel") actual = {r['value'] for r in recs} self.assertEqual({'Los Angeles'}, actual)
def test_default_filter(self): """ should produce a populated filter object. """ ds = CommRecordsDataSource() default_filter = ds.get_default_filter(None, self.company) self.assertEquals(datetime.now().year, default_filter.date_time.dates[1].year) # Take out value dated today. Too hard to run through assertEquals. default_filter.date_time.dates[1] = None expected = CommRecordsFilter( date_time=DateRangeFilter([datetime(2014, 1, 1), None])) self.assertEquals(expected, default_filter)
def test_filter_by_tags(self): """ Show only commrec with correct tags. """ ds = CommRecordsDataSource() recs = ds.run_unaggregated( self.company, CommRecordsFilter( tags=AndGroupFilter([OrGroupFilter([MatchFilter('EaSt')])])), []) subjects = {r['subject'] for r in recs} expected = {self.record_1.subject, self.record_2.subject} self.assertEqual(expected, subjects)
def test_values(self): """ Check limiting values works at all """ self.maxDiff = 10000 ds = CommRecordsDataSource() recs = ds.run_unaggregated(self.company, CommRecordsFilter(), ["partner", "subject"]) expected = [ { 'partner': u'aaa', 'subject': u'record 1' }, { 'partner': u'aaa', 'subject': u'record 2' }, { 'partner': u'bbb', 'subject': u'record 3' }, ] self.assertEqual(expected, recs)
def test_clone_without_full(self): """ Cloning should remove certain fields. """ filter = CommRecordsFilter(tags=['C'], locations=CompositeAndFilter({ 'city': MatchFilter('A'), 'state': MatchFilter('B') })) expected_with_city = CommRecordsFilter(tags=['C'], locations=CompositeAndFilter( {'city': MatchFilter('A')})) expected_with_state = CommRecordsFilter( tags=['C'], locations=CompositeAndFilter({'state': MatchFilter('B')})) self.assertEqual(expected_with_state, filter.clone_without_city()) self.assertEqual(expected_with_city, filter.clone_without_state())