Example #1
0
 def test_filter_by_data_source(self):
     """Check datasource filter works at all."""
     ds = PartnersDataSource()
     recs = ds.run_unaggregated(
         self.company, PartnersFilter(data_source=MatchFilter("zap")), [])
     names = {r['name'] for r in recs}
     expected = {self.partner_a.name}
     self.assertEqual(expected, names)
 def test_help_data_source(self):
     """Check data_source help works at all."""
     ds = PartnersDataSource()
     recs = ds.help_data_source(
         self.company,
         PartnersFilter(),
         "z")
     actual = set([r['key'] for r in recs])
     self.assertEqual({'zap'}, actual)
 def test_help_city(self):
     """Check city help works and ignores current city filter."""
     ds = PartnersDataSource()
     recs = ds.help_city(
         self.company,
         PartnersFilter(locations={'city': "zz"}),
         "angel")
     actual = set([r['key'] for r in recs])
     self.assertEqual({'Los Angeles'}, actual)
 def test_help_state(self):
     """Check state help works and ignores current state filter."""
     ds = PartnersDataSource()
     recs = ds.help_state(
         self.company,
         PartnersFilter(locations={'state': "zz"}),
         "i")
     actual = set([r['key'] for r in recs])
     self.assertEqual({'IL', 'IN'}, actual)
 def test_help_uri(self):
     """Check uri help works at all."""
     ds = PartnersDataSource()
     recs = ds.help_uri(
         self.company,
         PartnersFilter(),
         "ex")
     actual = set([r['key'] for r in recs])
     self.assertEqual({'http://www.example.com/'}, actual)
Example #6
0
 def test_filter_by_uri(self):
     """Check uri filter works at all."""
     ds = PartnersDataSource()
     recs = ds.run_unaggregated(
         self.company,
         PartnersFilter(uri=MatchFilter("http://www.asdf.com/")), [])
     names = {r['name'] for r in recs}
     expected = {self.partner_b.name}
     self.assertEqual(expected, names)
Example #7
0
 def test_help_city(self):
     """Check city help works and ignores current city filter."""
     ds = PartnersDataSource()
     recs = ds.help_city(
         self.company,
         PartnersFilter(
             locations=CompositeAndFilter({'city': MatchFilter("zz")})),
         "angel")
     actual = {r['value'] for r in recs}
     self.assertEqual({'Los Angeles'}, actual)
Example #8
0
 def test_help_state(self):
     """Check state help works and ignores current state filter."""
     ds = PartnersDataSource()
     recs = ds.help_state(
         self.company,
         PartnersFilter(
             locations=CompositeAndFilter({'state': MatchFilter("zz")})),
         "i")
     actual = {r['value'] for r in recs}
     self.assertEqual({'IL', 'IN'}, actual)
Example #9
0
 def test_filter_by_date_after(self):
     """Should show only partner with last_action_time after date."""
     ds = PartnersDataSource()
     recs = ds.run_unaggregated(
         self.company,
         PartnersFilter(
             date=DateRangeFilter([datetime(2015, 10, 1), None])), [])
     names = {r['name'] for r in recs}
     expected = {self.partner_b.name}
     self.assertEqual(expected, names)
Example #10
0
 def test_filter_by_uri(self):
     """Check uri filter works at all."""
     ds = PartnersDataSource()
     recs = ds.run_unaggregated(
         self.company,
         PartnersFilter(uri="http://www.asdf.com/"),
         [])
     names = set([r['name'] for r in recs])
     expected = {self.partner_b.name}
     self.assertEqual(expected, names)
Example #11
0
 def test_filter_by_data_source(self):
     """Check datasource filter works at all."""
     ds = PartnersDataSource()
     recs = ds.run_unaggregated(
         self.company,
         PartnersFilter(data_source="zap"),
         [])
     names = set([r['name'] for r in recs])
     expected = {self.partner_a.name}
     self.assertEqual(expected, names)
Example #12
0
 def test_order(self):
     """Check ordering results works at all."""
     ds = PartnersDataSource()
     recs = ds.run_unaggregated(
         self.company,
         PartnersFilter(),
         ["-name"])
     names = [r['name'] for r in recs]
     expected = [self.partner_b.name, self.partner_a.name]
     self.assertEqual(expected, names)
Example #13
0
 def test_filter_by_tags_or(self):
     """Show only partner with correct tags in 'or' configuration."""
     ds = PartnersDataSource()
     recs = ds.run_unaggregated(
         self.company,
         PartnersFilter(tags=[['EaSt', 'wEsT']]),
         [])
     names = set([r['name'] for r in recs])
     expected = {self.partner_a.name, self.partner_b.name}
     self.assertEqual(expected, names)
 def test_help_state(self):
     """Check state help works and ignores current state filter."""
     ds = PartnersDataSource()
     recs = ds.help_state(
         self.company,
         PartnersFilter(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 = PartnersDataSource()
     recs = ds.help_city(
         self.company,
         PartnersFilter(locations=CompositeAndFilter({
             'city': MatchFilter("zz")})),
         "angel")
     actual = {r['value'] for r in recs}
     self.assertEqual({'Los Angeles'}, actual)
Example #16
0
 def test_filter_by_tags_or(self):
     """Show only partner with correct tags in 'or' configuration."""
     ds = PartnersDataSource()
     recs = ds.run_unaggregated(
         self.company,
         PartnersFilter(tags=AndGroupFilter(
             [OrGroupFilter([MatchFilter('EaSt'),
                             MatchFilter('wEsT')])])), [])
     names = {r['name'] for r in recs}
     expected = {self.partner_a.name, self.partner_b.name}
     self.assertEqual(expected, names)
 def test_filter_by_tags_or(self):
     """Show only partner with correct tags in 'or' configuration."""
     ds = PartnersDataSource()
     recs = ds.run_unaggregated(
         self.company,
         PartnersFilter(tags=AndGroupFilter([
             OrGroupFilter([MatchFilter('EaSt'), MatchFilter('wEsT')])])),
         [])
     names = {r['name'] for r in recs}
     expected = {self.partner_a.name, self.partner_b.name}
     self.assertEqual(expected, names)
 def test_filter_by_date_before(self):
     """Should show only partner with last_action_time before date."""
     ds = PartnersDataSource()
     recs = ds.run_unaggregated(
         self.company,
         PartnersFilter(
             date=DateRangeFilter([None, datetime(2015, 9, 30)])),
         [])
     names = {r['name'] for r in recs}
     expected = {self.partner_a.name}
     self.assertEqual(expected, names)
Example #19
0
 def test_filter_by_empty_things(self):
     """Empty filters should not filter, just like missing filters."""
     ds = PartnersDataSource()
     recs = ds.run_unaggregated(
         self.company,
         PartnersFilter(
             locations={'city': '', 'state': ''}),
         [])
     names = set([r['name'] for r in recs])
     expected = {self.partner_a.name, self.partner_b.name}
     self.assertEqual(expected, names)
Example #20
0
 def test_filter_by_date_after(self):
     """Should show only partner with last_action_time after date."""
     ds = PartnersDataSource()
     recs = ds.run_unaggregated(
         self.company,
         PartnersFilter(
             date=[datetime(2015, 10, 1), None]),
         [])
     names = set([r['name'] for r in recs])
     expected = {self.partner_b.name}
     self.assertEqual(expected, names)
Example #21
0
 def test_default_filter(self):
     """should produce a populated filter object."""
     ds = PartnersDataSource()
     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 = PartnersFilter(
         date=DateRangeFilter([datetime(2014, 1, 1), None]))
     self.assertEquals(expected, default_filter)
 def test_values(self):
     """Check limiting values works at all."""
     ds = PartnersDataSource()
     recs = ds.run_unaggregated(
         self.company,
         PartnersFilter(),
         ["name", "uri"])
     expected = [
         {'name': self.partner_a.name, 'uri': 'http://www.example.com/'},
         {'name': self.partner_b.name, 'uri': 'http://www.asdf.com/'},
     ]
     self.assertEqual(expected, recs)
 def test_default_filter(self):
     """should produce a populated filter object."""
     ds = PartnersDataSource()
     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 = PartnersFilter(
         date=DateRangeFilter([datetime(2014, 1, 1), None]))
     self.assertEquals(expected, default_filter)
Example #24
0
 def test_filter_by_city(self):
     """Should show only partners with correct city."""
     ds = PartnersDataSource()
     recs = ds.run_unaggregated(
         self.company,
         PartnersFilter(locations=CompositeAndFilter({
             'city':
             MatchFilter('Los Angeles'),
         })), [])
     names = [r['name'] for r in recs]
     expected = [self.partner_b.name]
     self.assertEqual(expected, names)
Example #25
0
 def test_filter_by_city(self):
     """Should show only partners with correct city."""
     ds = PartnersDataSource()
     recs = ds.run_unaggregated(
         self.company,
         PartnersFilter(
             locations={
                 'city': 'Los Angeles'
             }),
         [])
     names = [r['name'] for r in recs]
     expected = [self.partner_b.name]
     self.assertEqual(expected, names)
 def test_filter_by_state(self):
     """Should show only partners with correct state."""
     ds = PartnersDataSource()
     recs = ds.run_unaggregated(
         self.company,
         PartnersFilter(
             locations=CompositeAndFilter({
                 'state': MatchFilter('CA'),
             })),
         [])
     names = [r['name'] for r in recs]
     expected = [self.partner_b.name]
     self.assertEqual(expected, names)
Example #27
0
    def test_run_count_comm_rec_per_month_no_partners(self):
        """Trip over a bug in the mysql client driver."""
        for (subject, itx) in enumerate(['a', 'b', 'c']):
            for month in [2, 3, 4]:
                self.sue.contactrecord_set.add(
                    ContactRecordFactory(subject=subject,
                                         date_time=datetime(2015, month, 1)))

        ds = PartnersDataSource()
        partners_filter = PartnersFilter(
            tags=AndGroupFilter([OrGroupFilter([MatchFilter('zzz')])]))
        recs = ds.run_count_comm_rec_per_month(self.company, partners_filter,
                                               ['name', 'year', '-month'])
        self.assertEqual(0, len(recs))
Example #28
0
 def test_run_count_comm_rec_per_month_empty_partner(self):
     """One partner, no communication records."""
     ds = PartnersDataSource()
     partners_filter = PartnersFilter(
         tags=AndGroupFilter([OrGroupFilter([MatchFilter('east')])]))
     recs = ds.run_count_comm_rec_per_month(self.company, partners_filter,
                                            ['name', 'year', '-month'])
     data = [(r['name'], r['year'], r['month'], r['comm_rec_count'])
             for r in recs]
     self.assertEqual(12, len(data))
     default_year = datetime.now().year
     for item in data:
         self.assertEqual(default_year, item[1])
         self.assertEqual(0, item[3])
Example #29
0
    def test_run_count_comm_rec_per_month_no_partners(self):
        """Trip over a bug in the mysql client driver."""
        for (subject, itx) in enumerate(['a', 'b', 'c']):
            for month in [2, 3, 4]:
                self.sue.contactrecord_set.add(
                    ContactRecordFactory(
                        subject=subject,
                        date_time=datetime(2015, month, 1)))

        ds = PartnersDataSource()
        partners_filter = PartnersFilter(tags=[['zzz']])
        recs = ds.run_count_comm_rec_per_month(
            self.company, partners_filter, ['name', 'year', '-month'])
        self.assertEqual(0, len(recs))
Example #30
0
 def test_run_count_comm_rec_per_month_empty_partner(self):
     """One partner, no communication records."""
     ds = PartnersDataSource()
     partners_filter = PartnersFilter(tags=[['east']])
     recs = ds.run_count_comm_rec_per_month(
         self.company, partners_filter, ['name', 'year', '-month'])
     data = [
         (r['name'], r['year'], r['month'], r['comm_rec_count'])
         for r in recs
     ]
     self.assertEqual(12, len(data))
     default_year = datetime.now().year
     for item in data:
         self.assertEqual(default_year, item[1])
         self.assertEqual(0, item[3])
Example #31
0
 def test_values(self):
     """Check limiting values works at all."""
     ds = PartnersDataSource()
     recs = ds.run_unaggregated(self.company, PartnersFilter(),
                                ["name", "uri"])
     expected = [
         {
             'name': self.partner_a.name,
             'uri': 'http://www.example.com/'
         },
         {
             'name': self.partner_b.name,
             'uri': 'http://www.asdf.com/'
         },
     ]
     self.assertEqual(expected, recs)
Example #32
0
    def test_run_unfiltered(self):
        """Make sure we only get data for this user."""
        ds = PartnersDataSource()
        recs = ds.run_unaggregated(self.company, PartnersFilter(), [])
        names = {r['name'] for r in recs}
        expected = {self.partner_a.name, self.partner_b.name}
        self.assertEqual(expected, names)
        expected_tags = {
            self.partner_a.pk: {'east'},
            self.partner_b.pk: {'west'},
        }

        def tags_by_pk(rec):
            return (rec['partner_id'], set(t['name'] for t in rec['tags']))

        found_tags = dict(tags_by_pk(r) for r in recs)

        self.assertEqual(expected_tags, found_tags)
Example #33
0
    def test_run_count_comm_rec_per_month_one_partner(self):
        """Trip over a bug in the mysql client driver."""
        for (subject, itx) in enumerate(['a', 'b', 'c']):
            for year in [2013, 2015, 2014]:
                for month in [2, 3, 4]:
                    self.sue.contactrecord_set.add(
                        ContactRecordFactory(subject=subject,
                                             date_time=datetime(
                                                 year, month, 1)))

        ds = PartnersDataSource()
        partners_filter = PartnersFilter(
            tags=AndGroupFilter([OrGroupFilter([MatchFilter('west')])]))
        recs = ds.run_count_comm_rec_per_month(self.company, partners_filter,
                                               ['name', 'year', '-month'])
        data = [(r['name'], r['year'], r['month'], r['comm_rec_count'])
                for r in recs]
        self.assertEqual(36, len(data))
Example #34
0
    def test_run_unfiltered(self):
        """Make sure we only get data for this user."""
        ds = PartnersDataSource()
        recs = ds.run_unaggregated(self.company, PartnersFilter(), [])
        names = set([r['name'] for r in recs])
        expected = {self.partner_a.name, self.partner_b.name}
        self.assertEqual(expected, names)
        expected_tags = {
            self.partner_a.pk: {'east'},
            self.partner_b.pk: {'west'},
        }

        def tags_by_pk(rec):
            return (rec['partner_id'], set(t['name'] for t in rec['tags']))

        found_tags = dict(tags_by_pk(r) for r in recs)

        self.assertEqual(expected_tags, found_tags)
Example #35
0
    def test_run_count_comm_rec_per_month_one_partner(self):
        """Trip over a bug in the mysql client driver."""
        for (subject, itx) in enumerate(['a', 'b', 'c']):
            for year in [2013, 2015, 2014]:
                for month in [2, 3, 4]:
                    self.sue.contactrecord_set.add(
                        ContactRecordFactory(
                            subject=subject,
                            date_time=datetime(year, month, 1)))

        ds = PartnersDataSource()
        partners_filter = PartnersFilter(tags=[['west']])
        recs = ds.run_count_comm_rec_per_month(
            self.company, partners_filter, ['name', 'year', '-month'])
        data = [
            (r['name'], r['year'], r['month'], r['comm_rec_count'])
            for r in recs
        ]
        self.assertEqual(36, len(data))
Example #36
0
    def test_run_count_comm_rec_per_month(self):
        """Make sure we only get data for this user."""
        for (subject, itx) in enumerate(['a', 'b', 'c']):
            for month in [2, 3, 4]:
                self.sue.contactrecord_set.add(
                    ContactRecordFactory(
                        subject=subject,
                        date_time=datetime(2015, month, 1)))

        ds = PartnersDataSource()
        recs = ds.run_count_comm_rec_per_month(
            self.company, PartnersFilter(), ['name', 'year', '-month'])
        data = [
            (r['name'], r['year'], r['month'], r['comm_rec_count'])
            for r in recs
        ]
        expected = [
            (self.partner_a.name, 2015, 12, 0),
            (self.partner_a.name, 2015, 11, 0),
            (self.partner_a.name, 2015, 10, 0),
            (self.partner_a.name, 2015, 9, 0),
            (self.partner_a.name, 2015, 8, 0),
            (self.partner_a.name, 2015, 7, 0),
            (self.partner_a.name, 2015, 6, 0),
            (self.partner_a.name, 2015, 5, 0),
            (self.partner_a.name, 2015, 4, 0),
            (self.partner_a.name, 2015, 3, 0),
            (self.partner_a.name, 2015, 2, 0),
            (self.partner_a.name, 2015, 1, 0),
            (self.partner_b.name, 2015, 12, 0),
            (self.partner_b.name, 2015, 11, 0),
            (self.partner_b.name, 2015, 10, 0),
            (self.partner_b.name, 2015, 9, 0),
            (self.partner_b.name, 2015, 8, 0),
            (self.partner_b.name, 2015, 7, 0),
            (self.partner_b.name, 2015, 6, 0),
            (self.partner_b.name, 2015, 5, 0),
            (self.partner_b.name, 2015, 4, 3),
            (self.partner_b.name, 2015, 3, 3),
            (self.partner_b.name, 2015, 2, 3),
            (self.partner_b.name, 2015, 1, 0),
        ]
        self.assertEqual(expected, data)
Example #37
0
    def test_filter_by_tags_and(self):
        """Show only partner with correct tags in 'and' configuration."""
        ds = PartnersDataSource()
        recs = ds.run_unaggregated(
            self.company,
            PartnersFilter(tags=[['EaSt'], ['wEsT']]),
            [])
        names = set([r['name'] for r in recs])
        expected = set()
        self.assertEqual(expected, names)

        # Now try adding another tag.
        self.partner_a.tags.add(self.west_tag)
        recs = ds.run_unaggregated(
            self.company,
            PartnersFilter(tags=[['EaSt'], ['wEsT']]),
            [])
        names = set([r['name'] for r in recs])
        expected = {self.partner_a.name}
        self.assertEqual(expected, names)
Example #38
0
    def test_run_count_comm_rec_per_month(self):
        """Make sure we only get data for this user."""
        for (subject, itx) in enumerate(['a', 'b', 'c']):
            for month in [2, 3, 4]:
                self.sue.contactrecord_set.add(
                    ContactRecordFactory(subject=subject,
                                         date_time=datetime(2015, month, 1)))

        ds = PartnersDataSource()
        recs = ds.run_count_comm_rec_per_month(self.company, PartnersFilter(),
                                               [])
        data = [(r['name'], r['year'], r['month'], r['comm_rec_count'])
                for r in recs]
        expected = [
            (self.partner_a.name, 2015, 1, 0),
            (self.partner_a.name, 2015, 2, 0),
            (self.partner_a.name, 2015, 3, 0),
            (self.partner_a.name, 2015, 4, 0),
            (self.partner_a.name, 2015, 5, 0),
            (self.partner_a.name, 2015, 6, 0),
            (self.partner_a.name, 2015, 7, 0),
            (self.partner_a.name, 2015, 8, 0),
            (self.partner_a.name, 2015, 9, 0),
            (self.partner_a.name, 2015, 10, 0),
            (self.partner_a.name, 2015, 11, 0),
            (self.partner_a.name, 2015, 12, 0),
            (self.partner_b.name, 2015, 1, 0),
            (self.partner_b.name, 2015, 2, 3),
            (self.partner_b.name, 2015, 3, 3),
            (self.partner_b.name, 2015, 4, 3),
            (self.partner_b.name, 2015, 5, 0),
            (self.partner_b.name, 2015, 6, 0),
            (self.partner_b.name, 2015, 7, 0),
            (self.partner_b.name, 2015, 8, 0),
            (self.partner_b.name, 2015, 9, 0),
            (self.partner_b.name, 2015, 10, 0),
            (self.partner_b.name, 2015, 11, 0),
            (self.partner_b.name, 2015, 12, 0),
        ]
        self.assertEqual(expected, data)
    def test_adorn_filter_items(self):
        found_filter_items = {
            'tags': ['east', 'west'],
            'uri': 'http://www.example.com/',
        }
        expected = {
            u'tags': {
                'east': {
                    'value': u'east',
                    'display': u'east',
                    'hexColor': u'aaaaaa',
                },
                'west': {
                    'value': u'west',
                    'display': u'west',
                    'hexColor': u'bbbbbb',
                },
            },
        }

        ds = PartnersDataSource()
        adorned_filter = ds.adorn_filter_items(
            self.company, found_filter_items)
        self.assertEqual(expected, adorned_filter)
Example #40
0
    def test_filter_by_tags_and(self):
        """Show only partner with correct tags in 'and' configuration."""
        ds = PartnersDataSource()
        recs = ds.run_unaggregated(
            self.company,
            PartnersFilter(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.partner_a.tags.add(self.west_tag)
        recs = ds.run_unaggregated(
            self.company,
            PartnersFilter(tags=AndGroupFilter([
                OrGroupFilter([MatchFilter('EaSt')]),
                OrGroupFilter([MatchFilter('wEsT')])
            ])), [])
        names = {r['name'] for r in recs}
        expected = {self.partner_a.name}
        self.assertEqual(expected, names)
Example #41
0
    def test_adorn_filter_items(self):
        found_filter_items = {
            'tags': ['east', 'west'],
            'uri': 'http://www.example.com/',
        }
        expected = {
            u'tags': {
                'east': {
                    'value': u'east',
                    'display': u'east',
                    'hexColor': u'aaaaaa',
                },
                'west': {
                    'value': u'west',
                    'display': u'west',
                    'hexColor': u'bbbbbb',
                },
            },
        }

        ds = PartnersDataSource()
        adorned_filter = ds.adorn_filter_items(self.company,
                                               found_filter_items)
        self.assertEqual(expected, adorned_filter)
Example #42
0
 def test_help_tags_colors(self):
     """Tags should have colors"""
     ds = PartnersDataSource()
     recs = ds.help_tags(self.company, PartnersFilter(), "east")
     self.assertEqual("aaaaaa", recs[0]['hexColor'])
Example #43
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()),
}
Example #44
0
 def test_help_tags_colors(self):
     """Tags should have colors"""
     ds = PartnersDataSource()
     recs = ds.help_tags(self.company, PartnersFilter(), "east")
     self.assertEqual("aaaaaa", recs[0]['hexColor'])
Example #45
0
 def test_help_tags(self):
     """Check tags help works at all."""
     ds = PartnersDataSource()
     recs = ds.help_tags(self.company, PartnersFilter(), "E")
     actual = set([r['key'] for r in recs])
     self.assertEqual({'east', 'west'}, actual)
Example #46
0
 def test_help_tags(self):
     """Check tags help works at all."""
     ds = PartnersDataSource()
     recs = ds.help_tags(self.company, PartnersFilter(), "E")
     actual = {r['value'] for r in recs}
     self.assertEqual({'east', 'west'}, actual)
Example #47
0
 def test_help_uri(self):
     """Check uri help works at all."""
     ds = PartnersDataSource()
     recs = ds.help_uri(self.company, PartnersFilter(), "ex")
     actual = {r['value'] for r in recs}
     self.assertEqual({'http://www.example.com/'}, actual)
Example #48
0
 def test_help_data_source(self):
     """Check data_source help works at all."""
     ds = PartnersDataSource()
     recs = ds.help_data_source(self.company, PartnersFilter(), "z")
     actual = {r['value'] for r in recs}
     self.assertEqual({'zap'}, actual)