예제 #1
0
def test_01_main(mockpopen):
    import server_check
    with patch('__builtin__.raw_input') as mock_raw_input:
        with patch('getpass.getpass') as mock_getpass:
            with patch('os.geteuid') as mock_geteuid:
                with patch('os.path.isfile') as mock_isfile:

                    mock_isfile.return_value = True
                    mock_raw_input.return_value = "foo"
                    mock_getpass.return_value = "bar"
                    mock_geteuid.return_value = 0

                    assert server_check.main([])

                    # Fake not-finding directadmin.conf.
                    mock_isfile.return_value = False
                    with pytest.raises(SystemExit):
                        server_check.main([])
                    mock_isfile.return_value = True

                    # Check without arguments.
                    argv = sys.argv
                    sys.argv = ['']
                    assert server_check.main()
                    sys.argv = argv

                    # Without root.
                    mock_geteuid.return_value = 1000
                    with pytest.raises(SystemExit):
                        server_check.main([])
예제 #2
0
def test_02_main(phpmyadmin, roundcube, spamassassin, ftp, smtp, imap, pop3, php, directadmin,
                 mockpopen):
    import server_check
    with patch('__builtin__.raw_input') as mock_raw_input:
        with patch('getpass.getpass') as mock_getpass:
            with patch('os.geteuid') as mock_geteuid:
                with patch('os.path.isfile') as mock_isfile:

                    mock_isfile.return_value = True
                    mock_raw_input.return_value = "foo"
                    mock_getpass.return_value = "bar"

                    mock_geteuid.return_value = 0
                    directadmin.create_random_domain.return_value = ['foo', 'bar', 'baz']

                    mocked_open = mock_open(read_data='465\n')
                    with patch('__builtin__.open', mocked_open):
                        assert server_check.main([])