runtests.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import os
  2. import pwd
  3. import shutil
  4. import sys
  5. from django import setup
  6. from django.core.management import call_command
  7. from django.test.utils import setup_test_environment
  8. def runtests():
  9. test_runner_path = os.path.dirname(__file__)
  10. project_template_path = os.path.join(
  11. test_runner_path, 'misago/project_template/project_name')
  12. test_project_path = os.path.join(test_runner_path, "testproject")
  13. if not os.path.exists(test_project_path):
  14. shutil.copytree(project_template_path, test_project_path)
  15. settings_path = os.path.join(test_project_path, "settings.py")
  16. with open(settings_path, "r") as py_file:
  17. settings_file = py_file.read()
  18. # Do some configuration magic
  19. settings_file = settings_file.replace("{{ project_name }}",
  20. "testproject")
  21. settings_file = settings_file.replace("{{ secret_key }}",
  22. "t3stpr0j3ct")
  23. settings_file += """
  24. EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend'
  25. """
  26. if os.environ.get('TRAVIS'):
  27. settings_file += """
  28. DATABASES = {
  29. 'default': {
  30. 'ENGINE': 'django.db.backends.postgresql_psycopg2',
  31. 'NAME': 'travis_ci_test',
  32. 'USER': 'postgres',
  33. 'PASSWORD': '',
  34. 'HOST': '127.0.0.1',
  35. 'PORT': '',
  36. }
  37. }
  38. TEST_NAME = 'travis_ci_test'
  39. """
  40. else:
  41. settings_file += """
  42. DATABASES = {
  43. 'default': {
  44. 'ENGINE': 'django.db.backends.postgresql_psycopg2',
  45. 'NAME': 'misago_postgres',
  46. 'USER': '%s',
  47. 'PASSWORD': '',
  48. 'HOST': '',
  49. 'PORT': '',
  50. }
  51. }
  52. """ % pwd.getpwuid(os.getuid())[0]
  53. with open(settings_path, "w") as py_file:
  54. py_file.write(settings_file)
  55. os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testproject.settings")
  56. setup()
  57. setup_test_environment()
  58. from django.core.management.commands import test
  59. sys.exit(test.Command().execute(verbosity=1))
  60. if __name__ == '__main__':
  61. runtests()