コード例 #1
0
 def setUp(self):
     super(TestDataSourceJsonDriver, self).setUp()
     self.ds = MockDataSource()
     self.driver = DataSourceJsonDriver(self.ds)
コード例 #2
0
class TestDataSourceJsonDriver(TestCase):
    def setUp(self):
        super(TestDataSourceJsonDriver, self).setUp()
        self.ds = MockDataSource()
        self.driver = DataSourceJsonDriver(self.ds)

    def test_encode_filter_interface(self):
        """Test that filter interface is serialized properly."""
        self.maxDiff = 10000
        report_config = ReportConfiguration([
            ColumnConfiguration(
                column='name',
                format='text'),
            ColumnConfiguration(
                column='date',
                format='us_date',
                filter_interface='date_range',
                filter_display='Date'),
            ColumnConfiguration(
                column='locations',
                format='city_state_list',
                filter_interface='city_state',
                filter_display='Locations',
                help=True),
            ColumnConfiguration(
                column='tags',
                format='comma_sep',
                filter_interface='search_multiselect',
                filter_display='Tags',
                help=True),
            ColumnConfiguration(
                column='partner',
                format='text',
                filter_interface='search_multiselect',
                filter_display='Partners',
                help=True),
        ])

        self.assertEquals({
            'filters': [
                {
                    'display': 'Date',
                    'filter': 'date',
                    'interface_type': 'date_range',
                },
                {
                    'display': 'Locations',
                    'filter': 'locations',
                    'interface_type': 'city_state',
                },
                {
                    'display': 'Tags',
                    'filter': 'tags',
                    'interface_type': 'search_multiselect',
                },
                {
                    'display': 'Partners',
                    'filter': 'partner',
                    'interface_type': 'search_multiselect',
                },
            ],
            'help': {
                'partner': True,
                'tags': True,
                'locations': True,
            },
        }, self.driver.encode_filter_interface(report_config))

    def test_order(self):
        """Test that order is built properly."""
        self.assertEqual(['name'], self.driver.build_order('["name"]'))

    def test_help(self):
        """Test that city help gets plumbed to datasource correctly."""
        result = self.driver.help('company', '{}', 'city', 'zzz')
        self.assertEqual('aaa', result)
        self.assertEqual([
            ['help', 'company', ContactsFilter(), 'city', 'zzz']
            ], self.ds.calls)

    def test_run(self):
        """Test that json run calls are plumbed to datasource correctly."""
        result = self.driver.run('unaggregated', 'company', '{}', '["zzz"]')
        self.assertEqual('aaa', result)
        self.assertEqual([
            ['run', 'unaggregated', 'company', ContactsFilter(), ['zzz']]
            ], self.ds.calls)

    def test_empty_filter(self):
        """Test that ContactsFilter has all proper defaults."""
        result = self.driver.build_filter("{}")
        self.assertEquals(ContactsFilter(), result)

    def test_tag_filter(self):
        """Test that tag filter is built properly."""
        result = self.driver.build_filter(
                '{"tags": [[1, 2], [3, 4]]}')
        self.assertEquals(ContactsFilter(
            tags=AndGroupFilter([
                OrGroupFilter([MatchFilter(1), MatchFilter(2)]),
                OrGroupFilter([MatchFilter(3), MatchFilter(4)]),
            ])), result)

    def test_city_filter(self):
        """Test that city filter is built properly."""
        result = self.driver.build_filter(
                '{"locations": {"city": "Indy"}}')
        self.assertEquals(
            ContactsFilter(
                locations=CompositeAndFilter({
                    'city': MatchFilter('Indy')})), result)

    def test_partner_filter(self):
        """Test that partner filter is built properly."""
        result = self.driver.build_filter(
                '{"partner": [1, 2]}')
        self.assertEquals(
            ContactsFilter(
                partner=OrGroupFilter([
                    MatchFilter(1),
                    MatchFilter(2)])), result)

    def test_date_filters(self):
        """Test that date filters are built properly."""
        spec = '{"date": ["09/01/2015", "09/30/2015"]}'
        result = self.driver.build_filter(spec)
        expected = ContactsFilter(
            date=DateRangeFilter([
                datetime(2015, 9, 1),
                datetime(2015, 9, 30)]))
        self.assertEquals(expected, result)

    def test_empty_list_filters(self):
        """
        Test that an empty list is interpreted as no filter.
        """
        spec = '{"partner": [], "partner_tags": []}'
        result = self.driver.build_filter(spec)
        expected = ContactsFilter()
        self.assertEquals(expected, result)

    def test_unlinked_filters(self):
        """
        Test that we can build an unlinked filter
        """
        spec = '{"partner": {"nolink": true}}'
        result = self.driver.build_filter(spec)
        expected = ContactsFilter(partner=UnlinkedFilter())
        self.assertEquals(expected, result)

    def test_filterlike_serialize(self):
        result = self.driver.serialize_filterlike(
            [{'a': 'b'}, {'c': datetime(2016, 1, 2)}])
        expected = '[{"a": "b"}, {"c": "01/02/2016"}]'
        self.assertEquals(expected, result)
コード例 #3
0
class TestDataSourceJsonDriver(TestCase):
    def setUp(self):
        super(TestDataSourceJsonDriver, self).setUp()
        self.ds = MockDataSource()
        self.driver = DataSourceJsonDriver(self.ds)

    def test_encode_filter_interface(self):
        """Test that filter interface is serialized properly."""
        self.maxDiff = 10000
        report_config = ReportConfiguration([
            ColumnConfiguration(column='name', format='text'),
            ColumnConfiguration(column='date',
                                format='us_date',
                                filter_interface='date_range',
                                filter_display='Date'),
            ColumnConfiguration(column='locations',
                                format='city_state_list',
                                filter_interface='city_state',
                                filter_display='Locations',
                                help=True),
            ColumnConfiguration(column='tags',
                                format='comma_sep',
                                filter_interface='search_multiselect',
                                filter_display='Tags',
                                help=True),
            ColumnConfiguration(column='partner',
                                format='text',
                                filter_interface='search_multiselect',
                                filter_display='Partners',
                                help=True),
        ])

        self.assertEquals(
            {
                'filters': [
                    {
                        'display': 'Date',
                        'filter': 'date',
                        'interface_type': 'date_range',
                    },
                    {
                        'display': 'Locations',
                        'filter': 'locations',
                        'interface_type': 'city_state',
                    },
                    {
                        'display': 'Tags',
                        'filter': 'tags',
                        'interface_type': 'search_multiselect',
                    },
                    {
                        'display': 'Partners',
                        'filter': 'partner',
                        'interface_type': 'search_multiselect',
                    },
                ],
                'help': {
                    'partner': True,
                    'tags': True,
                    'locations': True,
                },
            }, self.driver.encode_filter_interface(report_config))

    def test_order(self):
        """Test that order is built properly."""
        self.assertEqual(['name'], self.driver.build_order('["name"]'))

    def test_help(self):
        """Test that city help gets plumbed to datasource correctly."""
        result = self.driver.help('company', '{}', 'city', 'zzz')
        self.assertEqual('aaa', result)
        self.assertEqual([['help', 'company',
                           ContactsFilter(), 'city', 'zzz']], self.ds.calls)

    def test_run(self):
        """Test that json run calls are plumbed to datasource correctly."""
        result = self.driver.run('unaggregated', 'company', '{}', '["zzz"]')
        self.assertEqual('aaa', result)
        self.assertEqual(
            [['run', 'unaggregated', 'company',
              ContactsFilter(), ['zzz']]], self.ds.calls)

    def test_empty_filter(self):
        """Test that ContactsFilter has all proper defaults."""
        result = self.driver.build_filter("{}")
        self.assertEquals(ContactsFilter(), result)

    def test_tag_filter(self):
        """Test that tag filter is built properly."""
        result = self.driver.build_filter('{"tags": [[1, 2], [3, 4]]}')
        self.assertEquals(
            ContactsFilter(tags=AndGroupFilter([
                OrGroupFilter([MatchFilter(1), MatchFilter(2)]),
                OrGroupFilter([MatchFilter(3), MatchFilter(4)]),
            ])), result)

    def test_city_filter(self):
        """Test that city filter is built properly."""
        result = self.driver.build_filter('{"locations": {"city": "Indy"}}')
        self.assertEquals(
            ContactsFilter(
                locations=CompositeAndFilter({'city': MatchFilter('Indy')})),
            result)

    def test_partner_filter(self):
        """Test that partner filter is built properly."""
        result = self.driver.build_filter('{"partner": [1, 2]}')
        self.assertEquals(
            ContactsFilter(partner=OrGroupFilter(
                [MatchFilter(1), MatchFilter(2)])), result)

    def test_date_filters(self):
        """Test that date filters are built properly."""
        spec = '{"date": ["09/01/2015", "09/30/2015"]}'
        result = self.driver.build_filter(spec)
        expected = ContactsFilter(date=DateRangeFilter(
            [datetime(2015, 9, 1), datetime(2015, 9, 30)]))
        self.assertEquals(expected, result)

    def test_empty_list_filters(self):
        """
        Test that an empty list is interpreted as no filter.
        """
        spec = '{"partner": [], "partner_tags": []}'
        result = self.driver.build_filter(spec)
        expected = ContactsFilter()
        self.assertEquals(expected, result)

    def test_unlinked_filters(self):
        """
        Test that we can build an unlinked filter
        """
        spec = '{"partner": {"nolink": true}}'
        result = self.driver.build_filter(spec)
        expected = ContactsFilter(partner=UnlinkedFilter())
        self.assertEquals(expected, result)

    def test_filterlike_serialize(self):
        result = self.driver.serialize_filterlike([{
            'a': 'b'
        }, {
            'c': datetime(2016, 1, 2)
        }])
        expected = '[{"a": "b"}, {"c": "01/02/2016"}]'
        self.assertEquals(expected, result)
コード例 #4
0
 def setUp(self):
     super(TestDataSourceJsonDriver, self).setUp()
     self.ds = MockDataSource()
     self.driver = DataSourceJsonDriver(self.ds)
コード例 #5
0
ファイル: __init__.py プロジェクト: supervisitor20/MyJobs
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()),
}