Esempio n. 1
0
class CommandGetModelTest(TestCase):
    def setUp(self):
        self.command = Command()

    def test_existing(self):
        charmodel = self.command._get_model('charmodel')
        self.assertEqual(charmodel, models.CharModel)

    def test_non_existing(self):
        with self.assertRaises(CommandError):
            self.command._get_model('FooModel')
Esempio n. 2
0
class CommandGetModelTest(TestCase):
    def setUp(self):
        self.command = Command()

    def test_existing(self):
        charmodel = self.command._get_model('charmodel')
        self.assertEqual(charmodel, models.CharModel)

    def test_non_existing(self):
        with self.assertRaises(CommandError):
            self.command._get_model('FooModel')
Esempio n. 3
0
 def setUp(self):
     self.command = Command()
Esempio n. 4
0
class UserHasAccessTest(TestCase):
    def setUp(self):
        self.command = Command()

    def test_default_access(self):
        self.command._user_has_access('R')
        self.command._user_has_access('W')

    @patch('admin_cli.settings.USERS', {})
    def test_empty_setting_access(self, *args):
        self.command._user_has_access('R')
        self.command._user_has_access('W')

    @patch('admin_cli.settings.USERS', {os.getlogin(): 'R'})
    def test_user_read_access(self, *args):
        self.command._user_has_access('R')

    @patch('admin_cli.settings.USERS', {os.getlogin(): 'W'})
    def test_user_no_read_access(self, *args):
        with self.assertRaises(CommandError):
            self.command._user_has_access('R')

    @patch('admin_cli.settings.USERS', {os.getuid(): 'R'})
    def test_uid_read_access(self, *args):
        self.command._user_has_access('R')

    @patch('admin_cli.settings.USERS', {os.getuid(): 'W'})
    def test_uid_no_read_access(self, *args):
        with self.assertRaises(CommandError):
            self.command._user_has_access('R')

    @patch('admin_cli.settings.USERS', {'FOOUSER': '******'})
    def test_user_not_found(self, *args):
        with self.assertRaises(CommandError):
            self.command._user_has_access('R')
Esempio n. 5
0
 def setUp(self):
     self.command = Command()
Esempio n. 6
0
class UserHasAccessTest(TestCase):
    def setUp(self):
        self.command = Command()

    def test_default_access(self):
        self.command._user_has_access('R')
        self.command._user_has_access('W')

    @patch('admin_cli.settings.USERS', {})
    def test_empty_setting_access(self, *args):
        self.command._user_has_access('R')
        self.command._user_has_access('W')

    @patch('admin_cli.settings.USERS', {os.getlogin(): 'R'})
    def test_user_read_access(self, *args):
        self.command._user_has_access('R')

    @patch('admin_cli.settings.USERS', {os.getlogin(): 'W'})
    def test_user_no_read_access(self, *args):
        with self.assertRaises(CommandError):
            self.command._user_has_access('R')

    @patch('admin_cli.settings.USERS', {os.getuid(): 'R'})
    def test_uid_read_access(self, *args):
        self.command._user_has_access('R')

    @patch('admin_cli.settings.USERS', {os.getuid(): 'W'})
    def test_uid_no_read_access(self, *args):
        with self.assertRaises(CommandError):
            self.command._user_has_access('R')

    @patch('admin_cli.settings.USERS', {'FOOUSER': '******'})
    def test_user_not_found(self, *args):
        with self.assertRaises(CommandError):
            self.command._user_has_access('R')