Forked mumble-django project from https://bitbucket.org/Svedrin/mumble-django
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
3.6 KiB

  1. # -*- coding: utf-8 -*-
  2. # kate: space-indent on; indent-width 4; replace-tabs on;
  3. """
  4. * Copyright © 2009-2010, Michael "Svedrin" Ziegler <diese-addy@funzt-halt.net>
  5. *
  6. * Mumble-Django is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This package is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. """
  16. import os
  17. from django.test.simple import run_tests as django_run_tests
  18. from django.conf import settings
  19. from murmurenvutils import get_available_versions, run_callback, wait_for_user
  20. def run_tests( test_labels, verbosity=1, interactive=True, extra_tests=[] ):
  21. """ Run the Django built in testing framework, but before testing the mumble
  22. app, allow Murmur to be set up correctly.
  23. """
  24. if not test_labels:
  25. test_labels = [ appname.split('.')[-1] for appname in settings.INSTALLED_APPS ]
  26. # No need to sync any murmur servers for the other apps
  27. os.environ['MURMUR_CONNSTR'] = ''
  28. # The easy way: mumble is not being tested.
  29. if "mumble" not in test_labels:
  30. return django_run_tests( test_labels, verbosity, interactive, extra_tests )
  31. # First run everything apart from mumble. mumble will be tested separately, so Murmur
  32. # can be set up properly first.
  33. failed_tests = 0
  34. if len(test_labels) > 1:
  35. # only run others if mumble is not the only app to be tested
  36. test_labels = list(test_labels)
  37. test_labels.remove( "mumble" )
  38. failed_tests += django_run_tests( test_labels, verbosity, interactive, extra_tests )
  39. failed_tests += run_mumble_tests( verbosity, interactive )
  40. return failed_tests
  41. def run_mumble_tests( verbosity=1, interactive=True ):
  42. connstrings = {
  43. 'DBus': 'net.sourceforge.mumble.murmur',
  44. 'Ice': 'Meta:tcp -h 127.0.0.1 -p 6502',
  45. }
  46. def django_run_tests_wrapper( process, version ):
  47. wr_failed_tests = 0
  48. for method in connstrings:
  49. # Check if this server is ready to be used with the current method
  50. if getattr( process.capabilities, ("has_%s" % method.lower()), False ):
  51. print "Testing mumble %s via %s" % ( version, method )
  52. os.environ['MURMUR_CONNSTR'] = connstrings[method]
  53. settings.DEFAULT_CONN = connstrings[method]
  54. settings.SLICE_VERSION = [ int(dgt) for dgt in version.split('.') ]
  55. print "MURMUR_CONNSTR:", os.environ['MURMUR_CONNSTR']
  56. print "DEFAULT_CONN: ", settings.DEFAULT_CONN
  57. print "SLICE_VERSION: ", settings.SLICE_VERSION
  58. if not process.capabilities.has_users:
  59. print "Waiting for user to connect (60 seconds)."
  60. wait_for_user( process, timeout=60 )
  61. wr_failed_tests += django_run_tests( ('mumble',), verbosity, interactive, [] )
  62. else:
  63. print "Mumble %s does not support Method %s" % ( version, method )
  64. return wr_failed_tests
  65. failed_tests = 0
  66. from mctl import MumbleCtlBase
  67. for version in get_available_versions():
  68. MumbleCtlBase.clearCache()
  69. run = raw_input( "Run tests for %s? [Y/n] " % version )
  70. if run in ('Y', 'y', ''):
  71. failed_tests += run_callback( version, django_run_tests_wrapper, version )
  72. return failed_tests