def test_parse_args_with_table_not_selected(self, mock_args,
                                                load_json_mock,
                                                check_config_mock,
                                                get_tables_prop_mock):
        """
        test args parsing:
            one table not found in selected tables, this should throw a  NotSelectedTableException exception
        """
        mock_args.return_value = argparse.Namespace(
            **{
                'tap': './tap.yml',
                'properties': './prop.json',
                'transform': None,
                'target': './target.yml',
                'tables': 'schema.table_not_selected',
                'temp_dir': './'
            })

        load_json_mock.return_value = {}
        check_config_mock.return_value = None
        get_tables_prop_mock.return_value = {
            'schema.table_1', 'schema.table_2'
        }

        with pytest.raises(NotSelectedTableException):
            utils.parse_args({'tap': [], 'target': []})

        get_tables_prop_mock.assert_called_once()
        check_config_mock.assert_not_called()
        self.assertEqual(load_json_mock.call_count, 3)
Exemplo n.º 2
0
    def test_parse_args_with_all_tables(self, mock_args, load_json_mock,
                                        check_config_mock,
                                        get_tables_prop_mock):
        """
        test args parsing:
            all selected tables are specified
        """
        mock_args.return_value = argparse.Namespace(
            **{
                'tap': './tap.yml',
                'properties': './prop.json',
                'transform': None,
                'drop_pg_slot': True,
                'target': './target.yml',
                'tables': 'schema.table_1,schema.table_2',
                'temp_dir': './',
            })

        load_json_mock.return_value = {}
        check_config_mock.return_value = None
        get_tables_prop_mock.return_value = {
            'schema.table_1', 'schema.table_2'
        }

        args = utils.parse_args({'tap': [], 'target': []})

        self.assertEqual(get_tables_prop_mock.call_count, 1)
        self.assertEqual(load_json_mock.call_count, 3)
        self.assertEqual(check_config_mock.call_count, 2)

        self.assertDictEqual(
            vars(args),
            {
                'tables': {'schema.table_1', 'schema.table_2'},
                'drop_pg_slot': True,
                'tap': {},
                'target': {},
                'transform': {},
                'properties': {},
                'temp_dir': './',
            },
        )
    def test_parse_args_with_table_found(self, mock_args, load_json_mock,
                                         check_config_mock,
                                         get_tables_prop_mock):
        """
        test args parsing:
            one table is specified out of 2, this should return a drop_pg_slot = False
        """
        mock_args.return_value = argparse.Namespace(
            **{
                'tap': './tap.yml',
                'properties': './prop.json',
                'transform': None,
                'target': './target.yml',
                'tables': 'schema.table_2',
                'temp_dir': './'
            })

        load_json_mock.return_value = {}
        check_config_mock.return_value = None
        get_tables_prop_mock.return_value = {
            'schema.table_1', 'schema.table_2'
        }

        args = utils.parse_args({'tap': [], 'target': []})

        get_tables_prop_mock.assert_called_once()
        self.assertEqual(load_json_mock.call_count, 3)
        self.assertEqual(check_config_mock.call_count, 2)

        self.assertDictEqual(
            vars(args), {
                'tables': {'schema.table_2'},
                'tap': {},
                'target': {},
                'transform': {},
                'properties': {},
                'temp_dir': './'
            })
Exemplo n.º 4
0
    def test_parse_args_without_tables(self, mock_args, load_json_mock,
                                       check_config_mock,
                                       get_tables_prop_mock):
        """
        test args parsing:
            not tables are specified, this should return a tables equal to the list of selected tables
        """
        mock_args.return_value = argparse.Namespace(
            **{
                'tap': './tap.yml',
                'properties': './prop.json',
                'transform': None,
                'target': './target.yml',
                'tables': None,
                'temp_dir': './'
            })

        load_json_mock.return_value = {}
        check_config_mock.return_value = None
        get_tables_prop_mock.return_value = {
            'schema.table_1', 'schema.table_2'
        }

        args = utils.parse_args({'tap': [], 'target': []})

        self.assertEqual(get_tables_prop_mock.call_count, 1)
        self.assertEqual(load_json_mock.call_count, 3)
        self.assertEqual(check_config_mock.call_count, 2)

        self.assertDictEqual(
            vars(args), {
                'tables': {'schema.table_1', 'schema.table_2'},
                'tap': {},
                'target': {},
                'transform': {},
                'properties': {},
                'temp_dir': './'
            })