pyftpd_sink_test.py 877 B

1234567891011121314151617181920212223242526
  1. # pylint: disable=missing-docstring
  2. import unittest.mock
  3. import pytest
  4. import pyftpd_sink
  5. @pytest.mark.parametrize(('env', 'argv', 'expected_umask'), [
  6. ({}, [], None),
  7. ({}, ['--umask', str(0o0027)], 0o0027),
  8. ({}, ['--umask', str(0o0177)], 0o0177),
  9. ({}, ['--umask', '23'], 0o0027),
  10. ({}, ['--umask', '127'], 0o0177),
  11. ({'UMASK': str(0o0022)}, [], 0o0022),
  12. ({'UMASK': str(0o0022)}, ['--umask', str(0o0027)], 0o0027),
  13. ])
  14. def test_main_umask(env, argv, expected_umask):
  15. with unittest.mock.patch('pyftpd_sink.serve') as serve_mock:
  16. with unittest.mock.patch('sys.argv', ['', '--user', 'u', '--pwd-hash', 'p'] + argv):
  17. with unittest.mock.patch('os.environ', env):
  18. pyftpd_sink.main()
  19. serve_mock.assert_called_once()
  20. serve_kwargs = serve_mock.call_args[1]
  21. assert expected_umask == serve_kwargs['umask']