test_gnunet_fs_psd.py.in 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!@PYTHON@
  2. # This file is part of GNUnet.
  3. # (C) 2010 Christian Grothoff (and other contributing authors)
  4. #
  5. # GNUnet is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published
  7. # by the Free Software Foundation; either version 2, or (at your
  8. # option) any later version.
  9. #
  10. # GNUnet is distributed in the hope that it will be useful, but
  11. # WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. # General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with GNUnet; see the file COPYING. If not, write to the
  17. # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  18. # Boston, MA 02111-1307, USA.
  19. #
  20. # Testcase for file-sharing command-line tools (publish, search, download)
  21. import sys
  22. import os
  23. import subprocess
  24. import re
  25. import shutil
  26. srcdir = "../.."
  27. gnunet_pyexpect_dir = os.path.join (srcdir, "contrib")
  28. if gnunet_pyexpect_dir not in sys.path:
  29. sys.path.append (gnunet_pyexpect_dir)
  30. from gnunet_pyexpect import pexpect
  31. if os.name == 'posix':
  32. download = 'gnunet-download'
  33. gnunetarm = 'gnunet-arm'
  34. publish = 'gnunet-publish'
  35. unindex = 'gnunet-unindex'
  36. search = 'gnunet-search'
  37. elif os.name == 'nt':
  38. download = 'gnunet-download.exe'
  39. gnunetarm = 'gnunet-arm.exe'
  40. publish = 'gnunet-publish.exe'
  41. unindex = 'gnunet-unindex.exe'
  42. search = 'gnunet-search.exe'
  43. if os.name == "nt":
  44. shutil.rmtree (os.path.join (os.getenv ("TEMP"), "gnunet-test-fs-py-psd"), True)
  45. else:
  46. shutil.rmtree ("/tmp/gnunet-test-fs-py-psd", True)
  47. arm = subprocess.Popen ([gnunetarm, '-sq', '-c', 'test_gnunet_fs_psd_data.conf'])
  48. arm.communicate ()
  49. # first, basic publish-search-download run
  50. try:
  51. pub = pexpect ()
  52. pub.spawn (None, [publish, '-c', 'test_gnunet_fs_psd_data.conf', '-n', '-m', "description:The GNU Public License", '-k', 'gpl', '../../COPYING'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  53. pub.expect ("stdout", re.compile (r"Publishing `\.\./\.\./COPYING' done\.\r?\n"))
  54. pub.expect ("stdout", re.compile (r"URI is `gnunet://fs/chk/PC0M19QMQC0BPSHR6BGA228PP6INER1D610MGEMOMEM87222FN8HVUO7PQGO0O9HD2GVLHF2N5IDHEQUNK6LKE428FPO96SKQEA486O\.PG7K85JGQ6N599MD5HEP3CHEVFPKQD9JB6NPSLVA3T1SKDS66CFI499VS6MGQ88B0QUAVT1282TCRD4GGFVUKDLGI8F0SPIANA3J2LG\.35147'\.\r?\n"))
  55. s = pexpect ()
  56. s.spawn (None, [search, '-V', '-t', '1000', '-N', '1', '-c', 'test_gnunet_fs_psd_data.conf', 'gpl'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  57. s.expect ("stdout", re.compile (r'#0:\r?\n'))
  58. s.expect ("stdout", re.compile (r'gnunet-download -o "COPYING" gnunet://fs/chk/PC0M19QMQC0BPSHR6BGA228PP6INER1D610MGEMOMEM87222FN8HVUO7PQGO0O9HD2GVLHF2N5IDHEQUNK6LKE428FPO96SKQEA486O\.PG7K85JGQ6N599MD5HEP3CHEVFPKQD9JB6NPSLVA3T1SKDS66CFI499VS6MGQ88B0QUAVT1282TCRD4GGFVUKDLGI8F0SPIANA3J2LG\.35147\r?\n'))
  59. s.expect ("stdout", re.compile (r"\s*description: The GNU Public License\r?\n"))
  60. down = pexpect ()
  61. down.spawn (None, [download, '-c', 'test_gnunet_fs_psd_data.conf', '-o', 'COPYING', 'gnunet://fs/chk/PC0M19QMQC0BPSHR6BGA228PP6INER1D610MGEMOMEM87222FN8HVUO7PQGO0O9HD2GVLHF2N5IDHEQUNK6LKE428FPO96SKQEA486O.PG7K85JGQ6N599MD5HEP3CHEVFPKQD9JB6NPSLVA3T1SKDS66CFI499VS6MGQ88B0QUAVT1282TCRD4GGFVUKDLGI8F0SPIANA3J2LG.35147'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  62. down.expect ("stdout", re.compile (r"Downloading `COPYING' done (.*).\r?\n"))
  63. os.remove ("COPYING")
  64. finally:
  65. arm = subprocess.Popen ([gnunetarm, '-eq', '-c', 'test_gnunet_fs_psd_data.conf'])
  66. arm.communicate ()
  67. if os.name == "nt":
  68. shutil.rmtree (os.path.join (os.getenv ("TEMP"), "gnunet-test-fs-py-psd"), True)
  69. else:
  70. shutil.rmtree ("/tmp/gnunet-test-fs-py-psd", True)