def test_command_output_positive(self):
     """
     Test that the command is executed successfully if everything is configured fine
     """
     out = StringIO()
     call_command(preflightcheck.Command(), stdout=out)
     output = out.getvalue().strip()
     self.assertRegex(output, r'(PASSED).{0,10}$')
 def test_command_output_negative(self):
     """
     Test that the command execution raises an exception on a failed test
     """
     out = StringIO()
     self.assertRaisesMessage(CommandError,
                              'Pre-flight Check FAILED',
                              call_command,
                              preflightcheck.Command(),
                              stdout=out)
 def test_allowed_hosts_test_positive(self):
     """
     Test that the check is successful if the ALLOWED_HOSTS config is not empty
     """
     with redirect_stdout(StringIO()):
         self.assertTrue(preflightcheck.Command().check_allowed_hosts())
 def test_allowed_hosts_test_negative(self):
     """
     Test that the check fails if the ALLOWED_HOSTS config is still empty
     """
     with redirect_stdout(StringIO()):
         self.assertFalse(preflightcheck.Command().check_allowed_hosts())
 def test_debug_test_positive(self):
     """
     Test that the check is successful if the DEBUG mode is off
     """
     with redirect_stdout(StringIO()):
         self.assertTrue(preflightcheck.Command().check_debug())
 def test_debug_test_negative(self):
     """
     Test that the check fails if the DEBUG mode is still on
     """
     with redirect_stdout(StringIO()):
         self.assertFalse(preflightcheck.Command().check_debug())
 def test_secret_key_test_positive(self):
     """
     Test that the check is successful if the SECRET_KEY is set to something non-default
     """
     with redirect_stdout(StringIO()):
         self.assertTrue(preflightcheck.Command().check_django_secret())
 def test_secret_key_test_negative(self):
     """
     Test that the check fails if the SECRET_KEY is set to default
     """
     with redirect_stdout(StringIO()):
         self.assertFalse(preflightcheck.Command().check_django_secret())