Ejemplo n.º 1
0
 def test_no_args(self):
     """Test exit when no arguments passed."""
     try:
         with patch('sys.argv', ["1.py"]):
             get_ldap_users.main()
     except AssertionError as exp:
         self.fail("Unexpected exception: %s" % exp)
Ejemplo n.º 2
0
 def test_verbose(self):
     """Test exit when only verbose flag passed."""
     try:
         with patch('sys.argv', ["1.py", "-v"]):
             get_ldap_users.main()
     except AssertionError as exp:
         self.fail("Unexpected exception: %s" % exp)
Ejemplo n.º 3
0
    def test_print_default_settings(self):
        """Test default settings generator."""
        default_settings = Settings()

        temp_file, temp_path = tempfile.mkstemp()
        with patch('sys.argv', ["1.py", "gen-defaults", temp_path]):
            get_ldap_users.main()

        with open(temp_path) as settings_file:
            args = namedtuple('Args',
                              "domain_user domain_password settings_file")
            parsed_args = args(None, 'pass word', settings_file)
            self.assertFalse(parsed_args.settings_file.closed)
            settings = get_ldap_users.parse_settings_file(parsed_args)
        self.assertIsNotNone(settings)
        self.assertNotEqual(default_settings.__dict__, settings.__dict__)
        self.assertEqual(settings.ldap_password, 'pass word')
        settings.ldap_password = '******'
        self.assertEqual(default_settings.__dict__, settings.__dict__)
        os.close(temp_file)
        os.remove(temp_path)
Ejemplo n.º 4
0
 def test_version(self):
     """Test exit when version flag passed."""
     with self.assertRaises(SystemExit):
         with patch('sys.argv', ["1.py", "--version"]):
             get_ldap_users.main()
Ejemplo n.º 5
0
 def test_help(self):
     """Test exit when help flag passed."""
     with self.assertRaises(SystemExit):
         with patch('sys.argv', ["1.py", "-h", "-v"]):
             get_ldap_users.main()