No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 
 

47 líneas
1.5 KiB

  1. # Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors
  2. # imports - standard imports
  3. import shlex
  4. import subprocess
  5. import unittest
  6. # imports - module imports
  7. import frappe
  8. def clean(value):
  9. if isinstance(value, (bytes, str)):
  10. value = value.decode().strip()
  11. return value
  12. class BaseTestCommands:
  13. def execute(self, command):
  14. command = command.format(**{"site": frappe.local.site})
  15. command = shlex.split(command)
  16. self._proc = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  17. self.stdout = clean(self._proc.stdout)
  18. self.stderr = clean(self._proc.stderr)
  19. self.returncode = clean(self._proc.returncode)
  20. class TestCommands(BaseTestCommands, unittest.TestCase):
  21. def test_execute(self):
  22. # test 1: execute a command expecting a numeric output
  23. self.execute("bench --site {site} execute frappe.db.get_database_size")
  24. self.assertEquals(self.returncode, 0)
  25. self.assertIsInstance(float(self.stdout), float)
  26. # test 2: execute a command expecting an errored output as local won't exist
  27. self.execute("bench --site {site} execute frappe.local.site")
  28. self.assertEquals(self.returncode, 1)
  29. self.assertIsNotNone(self.stderr)
  30. # test 3: execute a command with kwargs
  31. # Note:
  32. # terminal command has been escaped to avoid .format string replacement
  33. # The returned value has quotes which have been trimmed for the test
  34. self.execute("""bench --site {site} execute frappe.bold --kwargs '{{"text": "DocType"}}'""")
  35. self.assertEquals(self.returncode, 0)
  36. self.assertEquals(self.stdout[1:-1], frappe.bold(text='DocType'))