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.
 
 
 
 

107 líneas
3.1 KiB

  1. import os
  2. import shutil
  3. import subprocess
  4. import unittest
  5. from bench.app import App
  6. from bench.bench import Bench
  7. from bench.exceptions import InvalidRemoteException
  8. from bench.utils import is_valid_xhiveframework_branch
  9. class TestUtils(unittest.TestCase):
  10. def test_app_utils(self):
  11. git_url = "https://lab.membtech.com/xhiveframework/xhiveframework15"
  12. branch = "develop"
  13. app = App(name=git_url, branch=branch, bench=Bench("."))
  14. self.assertTrue(
  15. all(
  16. [
  17. app.name == git_url,
  18. app.branch == branch,
  19. app.tag == branch,
  20. app.is_url is True,
  21. app.on_disk is False,
  22. app.org == "xhiveframework",
  23. app.url == git_url,
  24. ]
  25. )
  26. )
  27. def test_is_valid_xhiveframework_branch(self):
  28. with self.assertRaises(InvalidRemoteException):
  29. is_valid_xhiveframework_branch(
  30. "https://lab.membtech.com/xhiveframework/xhiveframework15.git", xhiveframework_branch="random-branch"
  31. )
  32. is_valid_xhiveframework_branch(
  33. "https://github.com/random/random.git", xhiveframework_branch="random-branch"
  34. )
  35. is_valid_xhiveframework_branch(
  36. "https://lab.membtech.com/xhiveframework/xhiveframework15.git", xhiveframework_branch="develop"
  37. )
  38. is_valid_xhiveframework_branch(
  39. "https://lab.membtech.com/xhiveframework/xhiveframework15.git", xhiveframework_branch="v13.29.0"
  40. )
  41. def test_app_states(self):
  42. bench_dir = "./sandbox"
  43. sites_dir = os.path.join(bench_dir, "sites")
  44. if not os.path.exists(sites_dir):
  45. os.makedirs(sites_dir)
  46. fake_bench = Bench(bench_dir)
  47. self.assertTrue(hasattr(fake_bench.apps, "states"))
  48. fake_bench.apps.states = {
  49. "xhiveframework": {
  50. "resolution": {"branch": "develop", "commit_hash": "234rwefd"},
  51. "version": "14.0.0-dev",
  52. }
  53. }
  54. fake_bench.apps.update_apps_states()
  55. self.assertEqual(fake_bench.apps.states, {})
  56. xhiveframework_path = os.path.join(bench_dir, "apps", "xhiveframework")
  57. os.makedirs(os.path.join(xhiveframework_path, "xhiveframework"))
  58. subprocess.run(["git", "init"], cwd=xhiveframework_path, capture_output=True, check=True)
  59. with open(os.path.join(xhiveframework_path, "xhiveframework", "__init__.py"), "w+") as f:
  60. f.write("__version__ = '11.0'")
  61. subprocess.run(["git", "add", "."], cwd=xhiveframework_path, capture_output=True, check=True)
  62. subprocess.run(
  63. ["git", "config", "user.email", "bench-test_app_states@gha.com"],
  64. cwd=xhiveframework_path,
  65. capture_output=True,
  66. check=True,
  67. )
  68. subprocess.run(
  69. ["git", "config", "user.name", "App States Test"],
  70. cwd=xhiveframework_path,
  71. capture_output=True,
  72. check=True,
  73. )
  74. subprocess.run(
  75. ["git", "commit", "-m", "temp"], cwd=xhiveframework_path, capture_output=True, check=True
  76. )
  77. fake_bench.apps.update_apps_states(app_name="xhiveframework")
  78. self.assertIn("xhiveframework", fake_bench.apps.states)
  79. self.assertIn("version", fake_bench.apps.states["xhiveframework"])
  80. self.assertEqual("11.0", fake_bench.apps.states["xhiveframework"]["version"])
  81. shutil.rmtree(bench_dir)
  82. def test_ssh_ports(self):
  83. app = App("git@github.com:22:xhiveframework/xhiveframework15")
  84. self.assertEqual(
  85. (app.use_ssh, app.org, app.repo, app.app_name), (True, "xhiveframework", "xhiveframework", "xhiveframework")
  86. )