示例#1
0
 def test_clone_without_full(self):
     """Cloning should remove certain fields."""
     filter = PartnersFilter(
             tags=['C'],
             locations={'city': 'A', 'state': 'B'})
     expected_with_city = PartnersFilter(
             tags=['C'],
             locations={'city': 'A'})
     expected_with_state = PartnersFilter(
             tags=['C'],
             locations={'state': 'B'})
     self.assertEqual(expected_with_state, filter.clone_without_city())
     self.assertEqual(expected_with_city, filter.clone_without_state())
示例#2
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)
示例#3
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)
示例#4
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)
示例#5
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)
示例#6
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)
示例#7
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)
示例#8
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_clone_without_full(self):
     """Cloning should remove certain fields."""
     filter = PartnersFilter(
             tags=AndGroupFilter([
                 OrGroupFilter([MatchFilter('C')])]),
             locations=CompositeAndFilter({
                 'city': MatchFilter('A'),
                 'state': MatchFilter('B')}))
     expected_with_city = PartnersFilter(
             tags=AndGroupFilter([
                 OrGroupFilter([MatchFilter('C')])]),
             locations=CompositeAndFilter({
                 'city': MatchFilter('A')}))
     expected_with_state = PartnersFilter(
             tags=AndGroupFilter([
                 OrGroupFilter([MatchFilter('C')])]),
             locations=CompositeAndFilter({
                 'state': MatchFilter('B')}))
     self.assertEqual(expected_with_state, filter.clone_without_city())
     self.assertEqual(expected_with_city, filter.clone_without_state())
示例#10
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)
示例#11
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))
示例#12
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])
示例#13
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)
示例#14
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)
示例#15
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)
示例#16
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))
示例#17
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)
示例#18
0
 def test_clone_without_full(self):
     """Cloning should remove certain fields."""
     filter = PartnersFilter(tags=AndGroupFilter(
         [OrGroupFilter([MatchFilter('C')])]),
                             locations=CompositeAndFilter({
                                 'city':
                                 MatchFilter('A'),
                                 'state':
                                 MatchFilter('B')
                             }))
     expected_with_city = PartnersFilter(
         tags=AndGroupFilter([OrGroupFilter([MatchFilter('C')])]),
         locations=CompositeAndFilter({'city': MatchFilter('A')}))
     expected_with_state = PartnersFilter(
         tags=AndGroupFilter([OrGroupFilter([MatchFilter('C')])]),
         locations=CompositeAndFilter({'state': MatchFilter('B')}))
     self.assertEqual(expected_with_state, filter.clone_without_city())
     self.assertEqual(expected_with_city, filter.clone_without_state())
示例#19
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'])
示例#20
0
 def test_clone_without_empty(self):
     """Cloning empty filters shouldn't crash."""
     filter = PartnersFilter()
     self.assertEqual(PartnersFilter(), filter.clone_without_city())
     self.assertEqual(PartnersFilter(), filter.clone_without_state())
 def test_plain_filter_match(self):
     """Convert MatchFilter to plain object."""
     filt = PartnersFilter(uri=MatchFilter('www'))
     self.assertEqual({
         'uri': 'www',
     }, plain_filter(filt))
示例#22
0
 def test_clone_without_empty(self):
     """Cloning empty filters shouldn't crash."""
     filter = PartnersFilter()
     self.assertEqual(PartnersFilter(), filter.clone_without_city())
     self.assertEqual(PartnersFilter(), filter.clone_without_state())
示例#23
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)
示例#24
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)
示例#25
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)