def test_filter_by_tags_and(self):
        """
        Show only contact with correct tags in 'and' configuration.

        """
        ds = ContactsDataSource()
        recs = ds.run_unaggregated(
            self.company,
            ContactsFilter(tags=AndGroupFilter([
                OrGroupFilter([MatchFilter('EaSt')]),
                OrGroupFilter([MatchFilter('wEsT')])
            ])), [])
        names = {r['name'] for r in recs}
        expected = set()
        self.assertEqual(expected, names)

        # Now try adding another tag.
        self.john.tags.add(self.west_tag)
        recs = ds.run_unaggregated(
            self.company,
            ContactsFilter(tags=AndGroupFilter([
                OrGroupFilter([MatchFilter('EaSt')]),
                OrGroupFilter([MatchFilter('wEsT')])
            ])), [])
        names = {r['name'] for r in recs}
        expected = {self.john.name}
        self.assertEqual(expected, names)
    def test_filter_by_tags_and(self):
        """
        Show only contact with correct tags in 'and' configuration.

        """
        ds = ContactsDataSource()
        recs = ds.run_unaggregated(
            self.company,
            ContactsFilter(tags=AndGroupFilter([
                OrGroupFilter([MatchFilter('EaSt')]),
                OrGroupFilter([MatchFilter('wEsT')])])),
            [])
        names = {r['name'] for r in recs}
        expected = set()
        self.assertEqual(expected, names)

        # Now try adding another tag.
        self.john.tags.add(self.west_tag)
        recs = ds.run_unaggregated(
            self.company,
            ContactsFilter(tags=AndGroupFilter([
                OrGroupFilter([MatchFilter('EaSt')]),
                OrGroupFilter([MatchFilter('wEsT')])])),
            [])
        names = {r['name'] for r in recs}
        expected = {self.john.name}
        self.assertEqual(expected, names)
 def test_help_partner(self):
     """Check partner help works at all."""
     ds = ContactsDataSource()
     recs = ds.help_partner(self.company, ContactsFilter(), "A")
     self.assertEqual(
         [{'value': self.partner_a.pk, 'display': 'aaa'}],
         recs)
 def test_help_partner(self):
     """Check partner help works at all."""
     ds = ContactsDataSource()
     recs = ds.help_partner(self.company, ContactsFilter(), "A")
     self.assertEqual([{
         'value': self.partner_a.pk,
         'display': 'aaa'
     }], recs)
    def test_help_partner_tags(self):
        """
        Check partner tags help works at all.

        """
        ds = ContactsDataSource()
        recs = ds.help_partner_tags(self.company, ContactsFilter(), "t")
        actual = {r['value'] for r in recs}
        self.assertEqual({'left', 'right'}, actual)
 def test_help_city(self):
     """Check city help works and ignores current city filter."""
     ds = ContactsDataSource()
     recs = ds.help_city(
         self.company,
         ContactsFilter(locations=CompositeAndFilter(
             {'city': MatchFilter('Los Angeles')})), "angel")
     actual = {r['value'] for r in recs}
     self.assertEqual({'Los Angeles'}, actual)
    def test_help_partner_tags(self):
        """
        Check partner tags help works at all.

        """
        ds = ContactsDataSource()
        recs = ds.help_partner_tags(self.company, ContactsFilter(), "t")
        actual = {r['value'] for r in recs}
        self.assertEqual({'left', 'right'}, actual)
    def test_run_unfiltered(self):
        """
        Make sure we only get data for this user.

        """
        ds = ContactsDataSource()
        recs = ds.run_unaggregated(self.company, ContactsFilter(), [])
        names = {r['name'] for r in recs}
        expected = {self.sue.name, self.john.name}
        self.assertEqual(expected, names)
 def test_filter_by_city(self):
     """Should show only contacts with correct city."""
     ds = ContactsDataSource()
     recs = ds.run_unaggregated(
         self.company,
         ContactsFilter(locations=CompositeAndFilter(
             {'city': MatchFilter('Los Angeles')})), [])
     names = [r['name'] for r in recs]
     expected = [self.sue.name]
     self.assertEqual(expected, names)
    def test_run_unfiltered(self):
        """
        Make sure we only get data for this user.

        """
        ds = ContactsDataSource()
        recs = ds.run_unaggregated(self.company, ContactsFilter(), [])
        names = {r['name'] for r in recs}
        expected = {self.sue.name, self.john.name}
        self.assertEqual(expected, names)
 def test_help_state(self):
     """Check state help works and ignores current state filter."""
     ds = ContactsDataSource()
     recs = ds.help_state(
         self.company,
         ContactsFilter(
             locations=CompositeAndFilter({'state': MatchFilter('zz')})),
         "i")
     actual = {r['value'] for r in recs}
     self.assertEqual({'IL', 'IN'}, actual)
 def test_filter_by_partners(self):
     """Should filter by partners."""
     ds = ContactsDataSource()
     recs = ds.run_unaggregated(
         self.company,
         ContactsFilter(
             partner=OrGroupFilter([MatchFilter(self.partner_a.pk)])), [])
     subjects = {r['name'] for r in recs}
     expected = {self.john.name}
     self.assertEqual(expected, subjects)
 def test_help_state(self):
     """Check state help works and ignores current state filter."""
     ds = ContactsDataSource()
     recs = ds.help_state(
         self.company,
         ContactsFilter(
             locations=CompositeAndFilter({
                 'state': MatchFilter('zz')})),
         "i")
     actual = {r['value'] for r in recs}
     self.assertEqual({'IL', 'IN'}, actual)
 def test_help_city(self):
     """Check city help works and ignores current city filter."""
     ds = ContactsDataSource()
     recs = ds.help_city(
         self.company,
         ContactsFilter(
             locations=CompositeAndFilter({
                 'city': MatchFilter('Los Angeles')})),
         "angel")
     actual = {r['value'] for r in recs}
     self.assertEqual({'Los Angeles'}, actual)
 def test_filter_by_partners(self):
     """Should filter by partners."""
     ds = ContactsDataSource()
     recs = ds.run_unaggregated(
         self.company,
         ContactsFilter(
             partner=OrGroupFilter([MatchFilter(self.partner_a.pk)])),
         [])
     subjects = {r['name'] for r in recs}
     expected = {self.john.name}
     self.assertEqual(expected, subjects)
 def test_filter_by_state(self):
     """Should show only contacts with correct state."""
     ds = ContactsDataSource()
     recs = ds.run_unaggregated(
         self.company,
         ContactsFilter(
             locations=CompositeAndFilter({'state': MatchFilter('CA')})),
         [])
     names = [r['name'] for r in recs]
     expected = [self.sue.name]
     self.assertEqual(expected, names)
 def test_default_filter(self):
     """should produce a populated filter object."""
     ds = ContactsDataSource()
     default_filter = ds.get_default_filter(None, self.company)
     self.assertEquals(datetime.now().year,
                       default_filter.date.dates[1].year)
     # Take out value dated today. Too hard to run through assertEquals.
     default_filter.date.dates[1] = None
     expected = ContactsFilter(
         date=DateRangeFilter([datetime(2014, 1, 1), None]))
     self.assertEquals(expected, default_filter)
 def test_values(self):
     """Check limiting values works at all."""
     ds = ContactsDataSource()
     recs = ds.run_unaggregated(
         self.company,
         ContactsFilter(),
         ["name", "email"])
     expected = [
         {'name': self.john.name, 'email': u'*****@*****.**'},
         {'name': self.sue.name, 'email': u'*****@*****.**'},
     ]
     self.assertEqual(expected, recs)
 def test_default_filter(self):
     """should produce a populated filter object."""
     ds = ContactsDataSource()
     default_filter = ds.get_default_filter(None, self.company)
     self.assertEquals(
         datetime.now().year,
         default_filter.date.dates[1].year)
     # Take out value dated today. Too hard to run through assertEquals.
     default_filter.date.dates[1] = None
     expected = ContactsFilter(
         date=DateRangeFilter([datetime(2014, 1, 1), None]))
     self.assertEquals(expected, default_filter)
    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 = ContactsDataSource()
        recs = ds.run_unaggregated(
            self.company, ContactsFilter(partner_tags=UnlinkedFilter()), [])
        subjects = {r['name'] for r in recs}
        expected = {self.sue.name}
        self.assertEqual(expected, subjects)
    def test_filter_untagged(self):
        """
        This indicates that the member selected to filter by untagged.

        """
        self.sue.tags.clear()
        ds = ContactsDataSource()
        recs = ds.run_unaggregated(self.company,
                                   ContactsFilter(tags=UnlinkedFilter()), [])
        names = {r['name'] for r in recs}
        expected = {self.sue.name}
        self.assertEqual(expected, names)
    def test_filter_by_partner_tags(self):
        """
        Test that we can filter by partner tags.

        """
        ds = ContactsDataSource()
        recs = ds.run_unaggregated(
            self.company,
            ContactsFilter(partner_tags=AndGroupFilter(
                [OrGroupFilter([MatchFilter('rigHt')])])), [])
        subjects = {r['name'] for r in recs}
        expected = {self.sue.name}
        self.assertEqual(expected, subjects)
    def test_filter_by_date_after(self):
        """
        Should show only contact with last_action_time after date.

        """
        ds = ContactsDataSource()
        recs = ds.run_unaggregated(
            self.company,
            ContactsFilter(
                date=DateRangeFilter([datetime(2015, 10, 1), None])), [])
        names = {r['name'] for r in recs}
        expected = {self.john.name}
        self.assertEqual(expected, names)
    def test_filter_by_date_before(self):
        """
        Should show only contact with last_action_time before date.

        """
        ds = ContactsDataSource()
        recs = ds.run_unaggregated(
            self.company,
            ContactsFilter(
                date=DateRangeFilter([None, datetime(2015, 9, 30)])), [])
        names = {r['name'] for r in recs}
        expected = {self.sue.name}
        self.assertEqual(expected, names)
    def test_filter_by_date_before(self):
        """
        Should show only contact with last_action_time before date.

        """
        ds = ContactsDataSource()
        recs = ds.run_unaggregated(
            self.company,
            ContactsFilter(
                date=DateRangeFilter([None, datetime(2015, 9, 30)])),
            [])
        names = {r['name'] for r in recs}
        expected = {self.sue.name}
        self.assertEqual(expected, names)
    def test_filter_by_tags_or(self):
        """
        Show only contact with correct tags in 'or' configuration.

        """
        ds = ContactsDataSource()
        recs = ds.run_unaggregated(
            self.company,
            ContactsFilter(tags=AndGroupFilter([
                OrGroupFilter([MatchFilter('EaSt'), MatchFilter('wEsT')])])),
            [])
        names = {r['name'] for r in recs}
        expected = {self.john.name, self.sue.name}
        self.assertEqual(expected, names)
    def test_filter_untagged(self):
        """
        This indicates that the member selected to filter by untagged.

        """
        self.sue.tags.clear()
        ds = ContactsDataSource()
        recs = ds.run_unaggregated(
            self.company,
            ContactsFilter(tags=UnlinkedFilter()),
            [])
        names = {r['name'] for r in recs}
        expected = {self.sue.name}
        self.assertEqual(expected, names)
    def test_filter_by_partner_tags(self):
        """
        Test that we can filter by partner tags.

        """
        ds = ContactsDataSource()
        recs = ds.run_unaggregated(
            self.company,
            ContactsFilter(partner_tags=AndGroupFilter([
                OrGroupFilter([MatchFilter('rigHt')])])),
            [])
        subjects = {r['name'] for r in recs}
        expected = {self.sue.name}
        self.assertEqual(expected, subjects)
    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 = ContactsDataSource()
        recs = ds.run_unaggregated(
            self.company,
            ContactsFilter(partner_tags=UnlinkedFilter()),
            [])
        subjects = {r['name'] for r in recs}
        expected = {self.sue.name}
        self.assertEqual(expected, subjects)
    def test_filter_by_tags_or(self):
        """
        Show only contact with correct tags in 'or' configuration.

        """
        ds = ContactsDataSource()
        recs = ds.run_unaggregated(
            self.company,
            ContactsFilter(tags=AndGroupFilter(
                [OrGroupFilter([MatchFilter('EaSt'),
                                MatchFilter('wEsT')])])), [])
        names = {r['name'] for r in recs}
        expected = {self.john.name, self.sue.name}
        self.assertEqual(expected, names)
    def test_filter_by_date_after(self):
        """
        Should show only contact with last_action_time after date.

        """
        ds = ContactsDataSource()
        recs = ds.run_unaggregated(
            self.company,
            ContactsFilter(
                date=DateRangeFilter([datetime(2015, 10, 1), None])),
            [])
        names = {r['name'] for r in recs}
        expected = {self.john.name}
        self.assertEqual(expected, names)
 def test_values(self):
     """Check limiting values works at all."""
     ds = ContactsDataSource()
     recs = ds.run_unaggregated(self.company, ContactsFilter(),
                                ["name", "email"])
     expected = [
         {
             'name': self.john.name,
             'email': u'*****@*****.**'
         },
         {
             'name': self.sue.name,
             'email': u'*****@*****.**'
         },
     ]
     self.assertEqual(expected, recs)
    def test_adorn_filter(self):
        self.maxDiff = 10000
        found_filter_items = {
            'tags': ['east', 'west'],
            'partner': [str(self.partner_a.pk)],
            'partner_tags': ['lEft', 'Right'],
        }
        expected = {
            u'partner': {
                self.partner_a.pk: {
                    'value': self.partner_a.pk,
                    'display': u'aaa'
                },
            },
            u'tags': {
                'east': {
                    'value': u'east',
                    'display': u'east',
                    'hexColor': u'aaaaaa',
                },
                'west': {
                    'value': u'west',
                    'display': u'west',
                    'hexColor': u'bbbbbb',
                },
            },
            u'partner_tags': {
                'left': {
                    'value': u'left',
                    'display': u'left',
                    'hexColor': u'cccccc',
                },
                'right': {
                    'value': u'right',
                    'display': u'right',
                    'hexColor': u'dddddd',
                },
            },
        }

        ds = ContactsDataSource()
        adorned_filter = ds.adorn_filter_items(self.company,
                                               found_filter_items)
        self.assertEqual(expected, adorned_filter)
    def test_adorn_filter(self):
        self.maxDiff = 10000
        found_filter_items = {
            'tags': ['east', 'west'],
            'partner': [str(self.partner_a.pk)],
            'partner_tags': ['lEft', 'Right'],
        }
        expected = {
            u'partner': {
                self.partner_a.pk:
                    {'value': self.partner_a.pk, 'display': u'aaa'},
            },
            u'tags': {
                'east': {
                    'value': u'east',
                    'display': u'east',
                    'hexColor': u'aaaaaa',
                },
                'west': {
                    'value': u'west',
                    'display': u'west',
                    'hexColor': u'bbbbbb',
                },
            },
            u'partner_tags': {
                'left': {
                    'value': u'left',
                    'display': u'left',
                    'hexColor': u'cccccc',
                },
                'right': {
                    'value': u'right',
                    'display': u'right',
                    'hexColor': u'dddddd',
                },
            },
        }

        ds = ContactsDataSource()
        adorned_filter = ds.adorn_filter_items(
            self.company, found_filter_items)
        self.assertEqual(expected, adorned_filter)
Exemplo n.º 35
0
from myreports.datasources.contacts import ContactsDataSource
from myreports.datasources.partners import PartnersDataSource
from myreports.datasources.comm_records import CommRecordsDataSource
from myreports.datasources.jsondriver import DataSourceJsonDriver


ds_json_drivers = {
    'contacts': DataSourceJsonDriver(ContactsDataSource()),
    'partners': DataSourceJsonDriver(PartnersDataSource()),
    'comm_records':  DataSourceJsonDriver(CommRecordsDataSource()),
}
 def test_help_tags(self):
     """Check tags help works at all."""
     ds = ContactsDataSource()
     recs = ds.help_tags(self.company, ContactsFilter(), "E")
     actual = {r['value'] for r in recs}
     self.assertEqual({'east', 'west'}, actual)
 def test_help_tags(self):
     """Check tags help works at all."""
     ds = ContactsDataSource()
     recs = ds.help_tags(self.company, ContactsFilter(), "E")
     actual = {r['value'] for r in recs}
     self.assertEqual({'east', 'west'}, actual)
 def test_help_tags_colors(self):
     """Tags should have colors"""
     ds = ContactsDataSource()
     recs = ds.help_tags(self.company, ContactsFilter(), "east")
     self.assertEqual("aaaaaa", recs[0]['hexColor'])
 def test_help_tags_colors(self):
     """Tags should have colors"""
     ds = ContactsDataSource()
     recs = ds.help_tags(self.company, ContactsFilter(), "east")
     self.assertEqual("aaaaaa", recs[0]['hexColor'])