test_python_django.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import time
  2. from tests.package.test_python import TestPythonPackageBase
  3. class TestPythonDjango(TestPythonPackageBase):
  4. config = TestPythonPackageBase.config
  5. sample_scripts = ["tests/package/sample_python_django.py"]
  6. def run_sample_scripts(self):
  7. timeout = 35
  8. cmd = "cd /opt && /usr/bin/django-admin startproject testsite"
  9. self.assertRunOk(cmd, timeout=timeout)
  10. cmd = "cd /opt/testsite && " + self.interpreter + " ./manage.py migrate"
  11. output, exit_code = self.emulator.run(cmd, timeout=timeout)
  12. self.assertIn("Operations to perform:", output[0])
  13. self.assertEqual(exit_code, 0)
  14. cmd = "cd /opt/testsite && " + self.interpreter + " ./manage.py runserver 0.0.0.0:1234 > /dev/null 2>&1 & "
  15. self.assertRunOk(cmd, timeout=timeout)
  16. # give some time to setup the server
  17. for attempt in range(30 * self.emulator.timeout_multiplier):
  18. time.sleep(1)
  19. cmd = "netstat -ltn 2>/dev/null | grep 0.0.0.0:1234"
  20. _, exit_code = self.emulator.run(cmd)
  21. if exit_code == 0:
  22. break
  23. self.assertEqual(exit_code, 0, "Timeout while waiting for django server")
  24. class TestPythonPy3Django(TestPythonDjango):
  25. __test__ = True
  26. config = TestPythonDjango.config + \
  27. """
  28. BR2_PACKAGE_PYTHON3=y
  29. BR2_PACKAGE_PYTHON_DJANGO=y
  30. BR2_PACKAGE_PYTHON3_SQLITE=y
  31. """