test_bin.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import os
  2. import shutil
  3. import sys
  4. import unittest
  5. from wagtailcrx.bin.wagtailcrx import main as wagtailcrx_main
  6. class TestwagtailcrxStart(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 = ['wagtailcrx', 'help']
  21. # Run
  22. wagtailcrx_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 = ['wagtailcrx', 'help', 'start']
  27. # Run
  28. wagtailcrx_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 = ['wagtailcrx', 'start', 'myproject', self.TEST_DIR]
  34. # Run
  35. wagtailcrx_main()
  36. # Assert files exist
  37. self.assertTrue(os.path.exists(os.path.join(self.TEST_DIR, 'README.md')))
  38. self.cleanup()
  39. def test_allopts(self):
  40. self.setup()
  41. # Set args
  42. sys.argv = [
  43. 'wagtailcrx',
  44. 'start',
  45. 'myproject',
  46. self.TEST_DIR,
  47. '--template', 'basic',
  48. '--sitename', 'MegaCorp, Inc.',
  49. '--domain', 'example.com'
  50. ]
  51. # Run
  52. wagtailcrx_main()
  53. # Assert files exist
  54. self.assertTrue(os.path.exists(os.path.join(self.TEST_DIR, 'README.md')))
  55. self.cleanup()
  56. def test_domain_www(self):
  57. self.setup()
  58. # Set args
  59. sys.argv = [
  60. 'wagtailcrx',
  61. 'start',
  62. 'myproject',
  63. self.TEST_DIR,
  64. '--domain', 'www.example.com'
  65. ]
  66. # Run
  67. wagtailcrx_main()
  68. # Assert files exist
  69. self.assertTrue(os.path.exists(os.path.join(self.TEST_DIR, 'README.md')))
  70. self.cleanup()
  71. def test_template_sass(self):
  72. self.setup()
  73. # Set args
  74. sys.argv = ['wagtailcrx', 'start', 'myproject', self.TEST_DIR, '--template', 'sass']
  75. # Run
  76. wagtailcrx_main()
  77. # Assert files exist
  78. self.assertTrue(os.path.exists(os.path.join(self.TEST_DIR, 'README.md')))
  79. self.cleanup()