예제 #1
0
class MambaAdminSqlConfigureTest(unittest.TestCase):
    def setUp(self):
        self.config = SqlConfigOptions()

    def test_wrong_number_of_args(self):
        self.assertRaises(usage.UsageError, self.config.parseOptions, ['test'])

    def test_drop_table_and_create_if_not_exists_conflicts(self):
        self.assertRaises(usage.UsageError, self.config.parseOptions,
                          ['--drop-table', '--create-if-not-exists'])

    def test_min_thread_can_not_be_less_or_equals_to_zero(self):
        self.assertRaises(usage.UsageError, self.config.parseOptions,
                          ['--min-threads=0'])
        self.assertRaises(usage.UsageError, self.config.parseOptions,
                          ['--min-threads=-1'])

    def test_max_threads_can_not_be_less_than_five_or_more_than_1024(self):
        self.assertRaises(usage.UsageError, self.config.parseOptions,
                          ['--max-threads=4'])
        self.assertRaises(usage.UsageError, self.config.parseOptions,
                          ['--max-threads=1025'])

    def test_backend_must_be_valid_on_hostname_or_username_options(self):
        self.assertRaises(
            usage.UsageError, self.config.parseOptions,
            ['--hostname=localhost', '--backend=test', '--database=test'])

    def test_database_should_be_passed_on_hostanme_or_username_options(self):
        self.assertRaises(usage.UsageError, self.config.parseOptions,
                          ['--hostname=localhost', '--backend=sqlite'])

    def test_generate_uri(self):
        self.config.parseOptions([
            '--username', 'testuser', '--password', 'testpassword',
            '--backend', 'mysql', '--database', 'testdb'
        ])
        self.assertEqual(self.config['uri'],
                         'mysql://*****:*****@localhost/testdb')

        self.config.parseOptions([
            '--username', 'testuser', '--password', 'testpassword',
            '--backend', 'postgres', '--database', 'testdb'
        ])
        self.assertEqual(self.config['uri'],
                         'postgres://*****:*****@localhost/testdb')

        self.config.parseOptions(['--backend', 'sqlite', '--path', 'testdb'])
        self.assertEqual(self.config['uri'], 'sqlite:testdb')
예제 #2
0
 def setUp(self):
     self.config = SqlConfigOptions()
예제 #3
0
class MambaAdminSqlConfigureTest(unittest.TestCase):

    def setUp(self):
        self.config = SqlConfigOptions()

    def test_wrong_number_of_args(self):
        self.assertRaises(usage.UsageError, self.config.parseOptions, ['test'])

    def test_drop_table_and_create_if_not_exists_conflicts(self):
        self.assertRaises(
            usage.UsageError,
            self.config.parseOptions,
            ['--drop-table', '--create-if-not-exists']
        )

    def test_min_thread_can_not_be_less_or_equals_to_zero(self):
        self.assertRaises(
            usage.UsageError,
            self.config.parseOptions,
            ['--min-threads=0']
        )
        self.assertRaises(
            usage.UsageError,
            self.config.parseOptions,
            ['--min-threads=-1']
        )

    def test_max_threads_can_not_be_less_than_five_or_more_than_1024(self):
        self.assertRaises(
            usage.UsageError,
            self.config.parseOptions,
            ['--max-threads=4']
        )
        self.assertRaises(
            usage.UsageError,
            self.config.parseOptions,
            ['--max-threads=1025']
        )

    def test_backend_must_be_valid_on_hostname_or_username_options(self):
        self.assertRaises(
            usage.UsageError,
            self.config.parseOptions,
            ['--hostname=localhost', '--backend=test', '--database=test']
        )

    def test_database_should_be_passed_on_hostanme_or_username_options(self):
        self.assertRaises(
            usage.UsageError,
            self.config.parseOptions,
            ['--hostname=localhost', '--backend=sqlite']
        )

    def test_generate_uri(self):
        self.config.parseOptions([
            '--username', 'testuser', '--password', 'testpassword',
            '--backend', 'mysql', '--database', 'testdb'
        ])
        self.assertEqual(
            self.config['uri'],
            'mysql://*****:*****@localhost/testdb'
        )

        self.config.parseOptions([
            '--username', 'testuser', '--password', 'testpassword',
            '--backend', 'postgres', '--database', 'testdb'
        ])
        self.assertEqual(
            self.config['uri'],
            'postgres://*****:*****@localhost/testdb'
        )

        self.config.parseOptions([
            '--backend', 'sqlite', '--path', 'testdb'
        ])
        self.assertEqual(
            self.config['uri'],
            'sqlite:testdb'
        )
예제 #4
0
 def setUp(self):
     self.config = SqlConfigOptions()