def test_configglue_validate_default_value(self, mock_is_valid):
        """Test configglue validation default."""
        mock_is_valid.return_value = (True, [])

        configglue(Schema, [])

        # validation was not invoked
        self.assertEqual(mock_is_valid.called, False)
Beispiel #2
0
    def test_configglue_validate_default_value(self, mock_is_valid):
        """Test configglue validation default."""
        mock_is_valid.return_value = (True, [])

        configglue(Schema, [])

        # validation was not invoked
        self.assertEqual(mock_is_valid.called, False)
    def test_configglue_validate(self, mock_is_valid):
        """Test configglue with validation enabled."""
        mock_is_valid.return_value = (True, [])

        configglue(Schema, [], validate=True)

        # validation was invoked
        self.assertEqual(mock_is_valid.called, True)
Beispiel #4
0
    def test_configglue_validate(self, mock_is_valid):
        """Test configglue with validation enabled."""
        mock_is_valid.return_value = (True, [])

        configglue(Schema, [], validate=True)

        # validation was invoked
        self.assertEqual(mock_is_valid.called, True)
Beispiel #5
0
    def test_configglue_no_validate(self, mock_is_valid):
        """Test configglue with validation disabled."""
        mock_is_valid.return_value = (True, [])

        configglue(Schema, [], validate=False)

        # validation was not invoked
        self.assertEqual(mock_is_valid.called, False)
    def test_configglue_no_validate(self, mock_is_valid):
        """Test configglue with validation disabled."""
        mock_is_valid.return_value = (True, [])

        configglue(Schema, [], validate=False)

        # validation was not invoked
        self.assertEqual(mock_is_valid.called, False)
    def test_configglue_validate_without_option(self, mock_is_valid):
        """Test configglue with validation from options."""
        mock_is_valid.return_value = (True, [])

        op = OptionParser()
        with patch.object(sys, 'argv', ['foo']):
            configglue(Schema, [], op=op)

        self.assertEqual(mock_is_valid.called, False)
Beispiel #8
0
    def test_configglue_validate_without_option(self, mock_is_valid):
        """Test configglue with validation from options."""
        mock_is_valid.return_value = (True, [])

        op = OptionParser()
        with patch.object(sys, 'argv', ['foo']):
            configglue(Schema, [], op=op)

        self.assertEqual(mock_is_valid.called, False)
    def test_configglue_validate_from_options(self, mock_is_valid):
        """Test configglue with validation from options."""
        mock_is_valid.return_value = (True, [])

        op = OptionParser()
        op.add_option('--validate', dest='validate', action='store_true')
        with patch.object(sys, 'argv', ['foo', '--validate']):
            configglue(Schema, [], op=op)

        self.assertEqual(mock_is_valid.called, True)
Beispiel #10
0
    def test_configglue_validate_from_options(self, mock_is_valid):
        """Test configglue with validation from options."""
        mock_is_valid.return_value = (True, [])

        op = OptionParser()
        op.add_option('--validate', dest='validate', action='store_true')
        with patch.object(sys, 'argv', ['foo', '--validate']):
            configglue(Schema, [], op=op)

        self.assertEqual(mock_is_valid.called, True)
Beispiel #11
0
    def __init__(self, app):
        schemas = [app.schema] + app.plugins.schemas
        self.schema = merge(*schemas)

        # initialize config
        config_files = self.get_config_files(app)
        self.glue = configglue(self.schema, config_files, op=app.parser)
Beispiel #12
0
    def test_configglue_with_options(self, mock_schemaconfigglue,
                                     mock_schema_parser):
        """Test configglue with a custom OptionParser."""

        # define the inputs
        class MySchema(Schema):
            foo = IntOption()

        configs = ['config.ini']

        op = OptionParser(usage='foo')

        # prepare mocks
        expected_schema_parser = Mock()
        expected_schema_parser.is_valid.return_value = (True, None)
        expected_args = Mock()
        mock_schemaconfigglue.return_value = (op, op.values, expected_args)
        mock_schema_parser.return_value = expected_schema_parser

        # call the function under test
        glue = configglue(MySchema, configs, op=op)

        # schema_parse is a SchemaConfigParser, initialized with MySchema
        # and fed with the configs file list
        self.assertEqual(glue.schema_parser, expected_schema_parser)
        mock_schema_parser.assert_called_with(MySchema())
        mock_schema_parser.return_value.read.assert_called_with(configs)
        # the other attributes are the result of calling schemaconfigglue
        mock_schemaconfigglue.assert_called_with(expected_schema_parser, op=op)
        self.assertEqual(glue.option_parser, op)
        self.assertEqual(glue.options, op.values)
        self.assertEqual(glue.args, expected_args)
    def test_configglue_with_options(self, mock_schemaconfigglue,
        mock_schema_parser):
        """Test configglue with a custom OptionParser."""
        # define the inputs
        class MySchema(Schema):
            foo = IntOption()

        configs = ['config.ini']

        op = OptionParser(usage='foo')

        # prepare mocks
        expected_schema_parser = Mock()
        expected_schema_parser.is_valid.return_value = (True, None)
        expected_args = Mock()
        mock_schemaconfigglue.return_value = (op,
            op.values, expected_args)
        mock_schema_parser.return_value = expected_schema_parser

        # call the function under test
        glue = configglue(MySchema, configs, op=op)

        # schema_parse is a SchemaConfigParser, initialized with MySchema
        # and fed with the configs file list
        self.assertEqual(glue.schema_parser, expected_schema_parser)
        mock_schema_parser.assert_called_with(MySchema())
        mock_schema_parser.return_value.read.assert_called_with(configs)
        # the other attributes are the result of calling schemaconfigglue
        mock_schemaconfigglue.assert_called_with(expected_schema_parser,
            op=op)
        self.assertEqual(glue.option_parser, op)
        self.assertEqual(glue.options, op.values)
        self.assertEqual(glue.args, expected_args)
    def test_configglue_with_errors(self, mock_schemaconfigglue,
        mock_schema_parser):
        """Test configglue when an error happens."""
        # prepare mocks
        expected_schema_parser = Mock()
        expected_schema_parser.is_valid.return_value = (False, ['some error'])
        expected_option_parser = Mock()
        expected_options = Mock()
        expected_args = Mock()
        mock_schemaconfigglue.return_value = (expected_option_parser,
            expected_options, expected_args)
        mock_schema_parser.return_value = expected_schema_parser

        # define the inputs
        class MySchema(Schema):
            foo = IntOption()

        configs = ['config.ini']

        # call the function under test
        glue = configglue(MySchema, configs)

        # schema_parse is a SchemaConfigParser, initialized with MySchema
        # and fed with the configs file list
        self.assertEqual(glue.schema_parser, expected_schema_parser)
        mock_schema_parser.assert_called_with(MySchema())
        mock_schema_parser.return_value.read.assert_called_with(configs)
        # the other attributes are the result of calling schemaconfigglue
        mock_schemaconfigglue.assert_called_with(expected_schema_parser,
            op=None)
        self.assertEqual(glue.option_parser, expected_option_parser)
        expected_option_parser.error.assert_called_with('some error')
        self.assertEqual(glue.options, expected_options)
        self.assertEqual(glue.args, expected_args)
Beispiel #15
0
    def __init__(self, app):
        schemas = [app.schema] + app.plugins.schemas
        self.schema = merge(*schemas)

        # initialize config
        config_files = self.get_config_files(app)
        self.glue = configglue(self.schema, config_files, op=app.parser)
Beispiel #16
0
    def test_configglue_with_errors(self, mock_schemaconfigglue,
                                    mock_schema_parser):
        """Test configglue when an error happens."""
        # prepare mocks
        expected_schema_parser = Mock()
        expected_schema_parser.is_valid.return_value = (False, ['some error'])
        expected_option_parser = Mock()
        expected_options = Mock()
        expected_args = Mock()
        mock_schemaconfigglue.return_value = (expected_option_parser,
                                              expected_options, expected_args)
        mock_schema_parser.return_value = expected_schema_parser

        # define the inputs
        class MySchema(Schema):
            foo = IntOption()

        configs = ['config.ini']

        # call the function under test
        glue = configglue(MySchema, configs)

        # schema_parse is a SchemaConfigParser, initialized with MySchema
        # and fed with the configs file list
        self.assertEqual(glue.schema_parser, expected_schema_parser)
        mock_schema_parser.assert_called_with(MySchema())
        mock_schema_parser.return_value.read.assert_called_with(configs)
        # the other attributes are the result of calling schemaconfigglue
        mock_schemaconfigglue.assert_called_with(expected_schema_parser,
                                                 op=None)
        self.assertEqual(glue.option_parser, expected_option_parser)
        expected_option_parser.error.assert_called_with('some error')
        self.assertEqual(glue.options, expected_options)
        self.assertEqual(glue.args, expected_args)
Beispiel #17
0
                    ('', csv_name, warning_msg))
            else:
                print data
                print "It's OK\n"


def main(config, opts):
    #print_values(config, opts)
    # exit()
    values = config.values('__main__')

    # Extracting parameters in variables
    for var in variables:
        exec("%s = values.get('%s')" % (var, var))

    print "***Connecting to server %s:%s..\n." % (server,port)
    oerp = oerplib.OERP(server=server, port=port, timeout=timeout)
    print "***Connection to the server %s:%s was successful.\n" % (server,port)

    print "***Acceding to the database '%s' with user.\n" % (database)
    admin_brw = oerp.login(user=user, passwd=passwd, database=database)
    print "***Access to the instance was successful.\n"

    read_csv(csv, oerp)

if __name__ == '__main__':

    glue = configglue(MySchema, ['config.ini'])

    main(glue.schema_parser, glue.options)
Beispiel #18
0
                print data
                print "It's OK\n"


def main(config, opts):
    #print_values(config, opts)
    # exit()
    values = config.values('__main__')

    # Extracting parameters in variables
    for var in variables:
        exec("%s = values.get('%s')" % (var, var))

    print "***Connecting to server %s:%s..\n." % (server, port)
    oerp = oerplib.OERP(server=server, port=port, timeout=timeout)
    print "***Connection to the server %s:%s was successful.\n" % (server,
                                                                   port)

    print "***Acceding to the database '%s' with user.\n" % (database)
    admin_brw = oerp.login(user=user, passwd=passwd, database=database)
    print "***Access to the instance was successful.\n"

    read_csv(csv, oerp)


if __name__ == '__main__':

    glue = configglue(MySchema, ['config.ini'])

    main(glue.schema_parser, glue.options)