def test_returns_false_if_row_does_not_match_all_quals(self):
     options = {
         'path': 'file1.mpr',  # These are not valid path and filesystem. But it does not matter here.
         'filesystem': '/tmp'}
     columns = ['column1']
     mpr_wrapper = MPRForeignDataWrapper(options, columns)
     fake_qual = AttrDict({
         'operator': '=',
         'field_name': 'column1',
         'value': '1'})
     self.assertFalse(mpr_wrapper._matches([fake_qual], ['2']))
 def test_adds_warning_message_with_missed_operator_to_postgres_log(self, fake_log):
     options = {
         'path': 'file1.mpr',  # These are not valid path and filesystem. But it does not matter here.
         'filesystem': '/tmp'}
     columns = []
     mpr_wrapper = MPRForeignDataWrapper(options, columns)
     fake_qual = AttrDict({'operator': 'foo'})
     mpr_wrapper._matches([fake_qual], ['1'])
     self.assertEqual(fake_log.call_count, 1)
     fake_log.assert_called_with(
         'Unknown operator foo in the AttrDict({\'operator\': \'foo\'}) qual. Row will be returned.',
         WARNING,
         hint='Implement foo operator in the MPR FDW wrapper.')
Beispiel #3
0
 def test_returns_false_if_row_does_not_match_all_quals(self):
     options = {
         'path':
         'file1.mpr',  # These are not valid path and filesystem. But it does not matter here.
         'filesystem': '/tmp'
     }
     columns = ['column1']
     mpr_wrapper = MPRForeignDataWrapper(options, columns)
     fake_qual = AttrDict({
         'operator': '=',
         'field_name': 'column1',
         'value': '1'
     })
     self.assertFalse(mpr_wrapper._matches([fake_qual], ['2']))
Beispiel #4
0
 def test_adds_warning_message_with_missed_operator_to_postgres_log(
         self, fake_log):
     options = {
         'path':
         'file1.mpr',  # These are not valid path and filesystem. But it does not matter here.
         'filesystem': '/tmp'
     }
     columns = []
     mpr_wrapper = MPRForeignDataWrapper(options, columns)
     fake_qual = AttrDict({'operator': 'foo'})
     mpr_wrapper._matches([fake_qual], ['1'])
     self.assertEqual(fake_log.call_count, 1)
     fake_log.assert_called_with(
         'Unknown operator foo in the AttrDict({\'operator\': \'foo\'}) qual. Row will be returned.',
         WARNING,
         hint='Implement foo operator in the MPR FDW wrapper.')
Beispiel #5
0
 def test_raises_RuntimeError_if_filesystem_is_not_given(self):
     options = {'path': '/tmp'}
     columns = []
     try:
         MPRForeignDataWrapper(options, columns)
         raise AssertionError('RuntimeError was not raised.')
     except RuntimeError as exc:
         self.assertIn('`filesystem` is required option', str(exc))
Beispiel #6
0
 def test_raises_RuntimeError_if_path_not_given(self):
     options = {}
     columns = []
     try:
         MPRForeignDataWrapper(options, columns)
         raise AssertionError('RuntimeError was not raised.')
     except RuntimeError as exc:
         self.assertIn('`path` is required option', str(exc))
Beispiel #7
0
    def test_generates_rows_from_message_pack_rows_file(self):
        options = {
            'path':
            'file1.mpr',  # These are not valid path and filesystem. But it does not matter here.
            'filesystem': '/tmp'
        }
        columns = []
        mpr_wrapper = MPRForeignDataWrapper(options, columns)

        class FakeReader(object):
            rows = iter([['1-1', '1-2'], ['2-1', '2-2']])

            def __enter__(self):
                return self

            def __exit__(self, *args):
                pass

        with patch.object(MPRowsFile, 'reader', FakeReader()):
            rows_itr = mpr_wrapper.execute([], ['column1', 'column2'])
            rows = list(rows_itr)
            expected_rows = [['1-1', '1-2'], ['2-1', '2-2']]

        self.assertEqual(rows, expected_rows)
    def test_generates_rows_from_message_pack_rows_file(self):
        options = {
            'path': 'file1.mpr',  # These are not valid path and filesystem. But it does not matter here.
            'filesystem': '/tmp'}
        columns = []
        mpr_wrapper = MPRForeignDataWrapper(options, columns)

        class FakeReader(object):
            rows = iter([['1-1', '1-2'], ['2-1', '2-2']])

            def __enter__(self):
                return self

            def __exit__(self, *args):
                pass

        with patch.object(MPRowsFile, 'reader', FakeReader()):
            rows_itr = mpr_wrapper.execute([], ['column1', 'column2'])
            rows = list(rows_itr)
            expected_rows = [
                ['1-1', '1-2'],
                ['2-1', '2-2']]

        self.assertEqual(rows, expected_rows)