예제 #1
0
 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 = set([r['key'] for r in recs])
     self.assertEqual({'Phone'}, actual)
예제 #2
0
    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_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)
예제 #4
0
 def test_help_partner(self):
     """Check partner help works at all."""
     ds = CommRecordsDataSource()
     recs = ds.help_partner(self.company, CommRecordsFilter(), "A")
     self.assertEqual(
         [{'key': self.partner_a.pk, 'display': self.partner_a.name}],
         recs)
예제 #5
0
 def test_help_contact(self):
     """Check contact help works at all."""
     ds = CommRecordsDataSource()
     recs = ds.help_contact(self.company, CommRecordsFilter(), "U")
     self.assertEqual(
         [{'key': self.sue.pk, 'display': self.sue.name}],
         recs)
예제 #6
0
    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_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_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_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)
예제 #10
0
 def test_help_city(self):
     """Check city help works and ignores current city filter."""
     ds = CommRecordsDataSource()
     recs = ds.help_city(
         self.company,
         CommRecordsFilter(locations={'city': "zz"}),
         "angel")
     actual = set([r['key'] for r in recs])
     self.assertEqual({'Los Angeles'}, actual)
예제 #11
0
 def test_help_state(self):
     """Check state help works and ignores current state filter."""
     ds = CommRecordsDataSource()
     recs = ds.help_state(
         self.company,
         CommRecordsFilter(locations={'state': "zz"}),
         "i")
     actual = set([r['key'] for r in recs])
     self.assertEqual({'IL', 'IN'}, actual)
    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)
예제 #13
0
    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)
예제 #14
0
    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)
예제 #15
0
    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)
예제 #16
0
 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)
예제 #17
0
 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)
예제 #18
0
 def test_filter_by_contact(self):
     """Check partner filter works at all."""
     ds = CommRecordsDataSource()
     recs = ds.run_unaggregated(
         self.company,
         CommRecordsFilter(contact=[self.sue.pk]),
         [])
     subjects = set([r['subject'] for r in recs])
     expected = {self.record_3.subject}
     self.assertEqual(expected, subjects)
예제 #19
0
 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='Email'),
         [])
     subjects = set([r['subject'] for r in recs])
     expected = {self.record_1.subject}
     self.assertEqual(expected, subjects)
예제 #20
0
 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)
예제 #21
0
 def test_filter_by_tags(self):
     """Show only commrec with correct tags."""
     ds = CommRecordsDataSource()
     recs = ds.run_unaggregated(
         self.company,
         CommRecordsFilter(tags=[['EaSt']]),
         [])
     subjects = set([r['subject'] for r in recs])
     expected = {self.record_1.subject, self.record_2.subject}
     self.assertEqual(expected, subjects)
예제 #22
0
    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)
예제 #23
0
 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)
예제 #24
0
    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)
예제 #25
0
 def test_filter_by_date_after(self):
     """Should show only commrec with last_action_time after date."""
     ds = CommRecordsDataSource()
     recs = ds.run_unaggregated(
         self.company,
         CommRecordsFilter(
             date_time=[datetime(2015, 10, 1), None]),
         [])
     subjects = set([r['subject'] for r in recs])
     expected = {self.record_3.subject}
     self.assertEqual(expected, subjects)
 def test_filter_by_state(self):
     """Should show only commrecs with correct state."""
     ds = CommRecordsDataSource()
     recs = ds.run_unaggregated(
         self.company,
         CommRecordsFilter(
             locations=CompositeAndFilter({'state': MatchFilter('CA')})),
         [])
     subjects = {r['subject'] for r in recs}
     expected = {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)
예제 #28
0
 def test_run_unfiltered(self):
     """Make sure we only get data for this user."""
     ds = CommRecordsDataSource()
     recs = ds.run_unaggregated(self.company, CommRecordsFilter(), [])
     subjects = set([r['subject'] for r in recs])
     expected = {
         self.record_1.subject,
         self.record_2.subject,
         self.record_3.subject,
     }
     self.assertEqual(expected, subjects)
예제 #29
0
    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_filter_by_date_before(self):
     """Should show only commrec with last_action_time before date."""
     ds = CommRecordsDataSource()
     date_range = DateRangeFilter(
         [None, datetime(2015, 9, 30)])
     recs = ds.run_unaggregated(
         self.company,
         CommRecordsFilter(date_time=date_range),
         [])
     subjects = {r['subject'] for r in recs}
     expected = {self.record_1.subject, self.record_2.subject}
     self.assertEqual(expected, subjects)
예제 #31
0
    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)
예제 #32
0
    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)
예제 #33
0
    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)
예제 #34
0
    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)
예제 #35
0
    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)
예제 #36
0
    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)
예제 #37
0
 def test_filter_by_city(self):
     """Should show only commrecs with correct city."""
     ds = CommRecordsDataSource()
     recs = ds.run_unaggregated(
         self.company,
         CommRecordsFilter(
             locations={
                 'city': 'Los Angeles'
             }),
         [])
     subjects = set([r['subject'] for r in recs])
     expected = {self.record_3.subject}
     self.assertEqual(expected, subjects)
예제 #38
0
    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)
예제 #39
0
 def test_order(self):
     """Check ordering results works at all."""
     ds = CommRecordsDataSource()
     recs = ds.run_unaggregated(
         self.company,
         CommRecordsFilter(),
         ["-subject"])
     subjects = [r['subject'] for r in recs]
     expected = [
         self.record_3.subject,
         self.record_2.subject,
         self.record_1.subject,
     ]
     self.assertEqual(expected, subjects)
예제 #40
0
    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_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_filter_by_partner(self):
        """
        Check partner filter works at all.

        """
        ds = CommRecordsDataSource()
        recs = ds.run_unaggregated(
            self.company,
            CommRecordsFilter(
                partner=OrGroupFilter([MatchFilter(self.partner_a.pk)])),
            [])
        subjects = {r['subject'] for r in recs}
        expected = {self.record_1.subject, self.record_2.subject}
        self.assertEqual(expected, subjects)
    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_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_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)
예제 #47
0
 def test_filter_by_empty_things(self):
     """Empty filters should not filter, just like missing filters."""
     ds = CommRecordsDataSource()
     recs = ds.run_unaggregated(
         self.company,
         CommRecordsFilter(
             locations={'city': '', 'state': ''}),
         [])
     subjects = set([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_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_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_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)
예제 #51
0
    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)
예제 #52
0
    def test_adorn_filter(self):
        self.maxDiff = 10000
        found_filter_items = {
            'tags': ['east', 'west'],
            'communication_type': ['Email'],
            'partner': [str(self.partner_a.pk)],
            'contact': [str(self.sue.pk)],
            'contact_tags': ['nOrth', 'south'],
            'partner_tags': ['lEft', 'riGht'],
        }

        expected = {
            u'partner': {
                self.partner_a.pk: {
                    'value': self.partner_a.pk,
                    'display': u'aaa'
                },
            },
            u'contact': {
                self.sue.pk: {
                    'value': self.sue.pk,
                    'display': u'Sue Baxter'
                },
            },
            u'tags': {
                u'east': {
                    'value': u'east',
                    'display': u'east',
                    'hexColor': u'aaaaaa',
                },
                u'west': {
                    'value': u'west',
                    'display': u'west',
                    'hexColor': u'bbbbbb',
                },
            },
            u'communication_type': {
                'email': {
                    'value': 'email',
                    'display': 'Email'
                }
            },
            u'contact_tags': {
                u'north': {
                    'value': u'north',
                    'display': u'north',
                    'hexColor': u'cccccc',
                },
                u'south': {
                    'value': u'south',
                    'display': u'south',
                    'hexColor': u'dddddd',
                },
            },
            u'partner_tags': {
                u'left': {
                    'value': u'left',
                    'display': u'left',
                    'hexColor': u'eeeeee',
                },
                u'right': {
                    'value': u'right',
                    'display': u'right',
                    'hexColor': u'ffffff',
                },
            },
        }

        ds = CommRecordsDataSource()
        result = ds.adorn_filter_items(self.company, found_filter_items)
        self.assertEqual(expected, result)
예제 #53
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()),
}