test_bin.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import os
  2. import shutil
  3. import sys
  4. import unittest
  5. from coderedcms.bin.coderedcms import main as coderedcms_main
  6. class TestCoderedcmsStart(unittest.TestCase):
  7. CURR_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  8. TEST_DIR = os.path.join(CURR_DIR, "testproject-unittest")
  9. def setup(self):
  10. # Clean/create directory to start into
  11. if os.path.exists(self.TEST_DIR):
  12. shutil.rmtree(self.TEST_DIR)
  13. os.mkdir(self.TEST_DIR)
  14. def cleanup(self):
  15. # Cleanup
  16. if os.path.exists(self.TEST_DIR):
  17. shutil.rmtree(self.TEST_DIR)
  18. def test_help(self):
  19. # Set args
  20. sys.argv = ["coderedcms", "help"]
  21. # Run
  22. coderedcms_main()
  23. # Nothing to assert here... just make sure it doesn't error out.
  24. def test_help_start(self):
  25. # Set args
  26. sys.argv = ["coderedcms", "help", "start"]
  27. # Run
  28. coderedcms_main()
  29. # Nothing to assert here... just make sure it doesn't error out.
  30. def test_default(self):
  31. self.setup()
  32. # Set args
  33. sys.argv = ["coderedcms", "start", "myproject", self.TEST_DIR]
  34. # Run
  35. coderedcms_main()
  36. # Assert files exist
  37. self.assertTrue(
  38. os.path.exists(os.path.join(self.TEST_DIR, "README.md"))
  39. )
  40. self.cleanup()
  41. def test_allopts(self):
  42. self.setup()
  43. # Set args
  44. sys.argv = [
  45. "coderedcms",
  46. "start",
  47. "myproject",
  48. self.TEST_DIR,
  49. "--template",
  50. "basic",
  51. "--sitename",
  52. "MegaCorp, Inc.",
  53. "--domain",
  54. "example.com",
  55. ]
  56. # Run
  57. coderedcms_main()
  58. # Assert files exist
  59. self.assertTrue(
  60. os.path.exists(os.path.join(self.TEST_DIR, "README.md"))
  61. )
  62. self.cleanup()
  63. def test_domain_www(self):
  64. self.setup()
  65. # Set args
  66. sys.argv = [
  67. "coderedcms",
  68. "start",
  69. "myproject",
  70. self.TEST_DIR,
  71. "--domain",
  72. "www.example.com",
  73. ]
  74. # Run
  75. coderedcms_main()
  76. # Assert files exist
  77. self.assertTrue(
  78. os.path.exists(os.path.join(self.TEST_DIR, "README.md"))
  79. )
  80. self.cleanup()
  81. def test_template_pro(self):
  82. self.setup()
  83. # Set args
  84. sys.argv = [
  85. "coderedcms",
  86. "start",
  87. "myproject",
  88. self.TEST_DIR,
  89. "--template",
  90. "pro",
  91. ]
  92. # Run
  93. coderedcms_main()
  94. # Assert files exist
  95. self.assertTrue(
  96. os.path.exists(os.path.join(self.TEST_DIR, "README.md"))
  97. )
  98. self.cleanup()