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.

251 lines
8.2 KiB

  1. # -*- coding: utf-8 -*-
  2. """
  3. * Copyright (C) 2009, Michael "Svedrin" Ziegler <diese-addy@funzt-halt.net>
  4. *
  5. * Mumble-Django is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This package is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. """
  15. import os
  16. from django.test import TestCase
  17. from django.test.simple import run_tests as django_run_tests
  18. from django.conf import settings
  19. from models import *
  20. from utils import ObjectInfo
  21. from murmurenvutils import get_available_versions, run_callback
  22. class InstancesHandling( TestCase ):
  23. """ Tests creation, editing and removing of vserver instances. """
  24. def setUp( self ):
  25. # Make sure we always start with a FRESH murmur instance, checking for left-over instances
  26. # and deleting them before creating ours.
  27. try:
  28. self.murmur = Mumble.objects.get( addr="0.0.0.0", port=31337 );
  29. except Mumble.DoesNotExist:
  30. pass
  31. else:
  32. self.murmur.delete();
  33. finally:
  34. self.murmur = Mumble( name="#unit testing instance#", addr="0.0.0.0", port=31337 );
  35. self.murmur.save();
  36. def testDefaultConf( self ):
  37. conf = self.murmur.ctl.getAllConf( self.murmur.srvid );
  38. self.assert_( type(conf) == dict );
  39. self.assert_( "host" in conf );
  40. self.assert_( "port" in conf );
  41. self.assert_( "certificate" in conf );
  42. self.assert_( "key" in conf );
  43. self.assert_( "registerhostname" in conf );
  44. self.assert_( "registername" in conf );
  45. self.assert_( "channelname" in conf );
  46. self.assert_( "username" in conf );
  47. self.assert_( "obfuscate" in conf );
  48. self.assert_( "defaultchannel" in conf );
  49. def testAddrPortUnique( self ):
  50. try:
  51. duplicate = Mumble( name="#another unit testing instance#", addr="0.0.0.0", port=31337 );
  52. if duplicate.ctl.method == "ICE":
  53. import Murmur
  54. self.assertRaises( Murmur.ServerFailureException, duplicate.save );
  55. else:
  56. from sqlite3 import IntegrityError
  57. self.assertRaises( IntegrityError, duplicate.save );
  58. finally:
  59. # make sure the duplicate is removed
  60. duplicate.ctl.deleteServer( duplicate.srvid );
  61. def tearDown( self ):
  62. self.murmur.delete();
  63. class DataReading( TestCase ):
  64. """ Tests reading data from murmur using the low-level CTL methods. """
  65. def setUp( self ):
  66. # BIG FAT WARNING: This sucks ass, because it assumes the tester has a
  67. # Murmur database like the one I have.
  68. # I definitely need to prepare Murmur somehow before running these tests.
  69. # Just don't yet know how.
  70. self.murmur = Mumble.objects.get(id=1);
  71. def testCtlGetChannels( self ):
  72. """ Test getChannels() """
  73. channels = self.murmur.ctl.getChannels( self.murmur.srvid );
  74. if self.murmur.ctl.method == "ICE":
  75. import Murmur
  76. self.assertEquals( type( channels[0] ), Murmur.Channel );
  77. else:
  78. self.assertEquals( type( channels[0] ), ObjectInfo );
  79. self.assert_( hasattr( channels[0], "id" ) );
  80. self.assert_( hasattr( channels[0], "name" ) );
  81. self.assert_( hasattr( channels[0], "parent" ) );
  82. self.assert_( hasattr( channels[0], "links" ) );
  83. def testCtlGetPlayers( self ):
  84. """ Test getPlayers() """
  85. players = self.murmur.ctl.getPlayers( self.murmur.srvid );
  86. self.assert_( len(players) > 0 );
  87. self.assertEquals( type(players), dict );
  88. for plidx in players:
  89. player = players[plidx];
  90. if self.murmur.ctl.method == "ICE" and self.murmur.version[:2] == ( 1, 2 ):
  91. import Murmur
  92. self.assertEquals( type( player ), Murmur.User );
  93. else:
  94. self.assertEquals( type( player ), ObjectInfo );
  95. self.assert_( hasattr( player, "session" ) );
  96. self.assert_( hasattr( player, "mute" ) );
  97. self.assert_( hasattr( player, "deaf" ) );
  98. self.assert_( hasattr( player, "selfMute" ) );
  99. self.assert_( hasattr( player, "selfDeaf" ) );
  100. self.assert_( hasattr( player, "channel" ) );
  101. self.assert_( hasattr( player, "userid" ) );
  102. self.assert_( hasattr( player, "name" ) );
  103. self.assert_( hasattr( player, "onlinesecs" ) );
  104. self.assert_( hasattr( player, "bytespersec" ) );
  105. def testCtlGetRegisteredPlayers( self ):
  106. """ Test getRegistredPlayers() and getRegistration() """
  107. players = self.murmur.ctl.getRegisteredPlayers( self.murmur.srvid );
  108. self.assert_( len(players) > 0 );
  109. self.assertEquals( type(players), dict );
  110. for plidx in players:
  111. player = players[plidx];
  112. self.assertEquals( type( player ), ObjectInfo );
  113. self.assert_( hasattr( player, "userid" ) );
  114. self.assert_( hasattr( player, "name" ) );
  115. self.assert_( hasattr( player, "email" ) );
  116. self.assert_( hasattr( player, "pw" ) );
  117. # compare with getRegistration result
  118. reg = self.murmur.ctl.getRegistration( self.murmur.srvid, player.userid );
  119. self.assertEquals( type( reg ), ObjectInfo );
  120. self.assert_( hasattr( reg, "userid" ) );
  121. self.assert_( hasattr( reg, "name" ) );
  122. self.assert_( hasattr( reg, "email" ) );
  123. self.assert_( hasattr( reg, "pw" ) );
  124. self.assertEquals( player.userid, reg.userid );
  125. self.assertEquals( player.name, reg.name );
  126. self.assertEquals( player.email, reg.email );
  127. self.assertEquals( player.pw, reg.pw );
  128. def testCtlGetAcl( self ):
  129. """ Test getACL() for the root channel """
  130. acls, groups, inherit = self.murmur.ctl.getACL( self.murmur.srvid, 0 );
  131. for rule in acls:
  132. if self.murmur.ctl.method == "ICE" and self.murmur.version[:2] == ( 1, 2 ):
  133. import Murmur
  134. self.assertEquals( type( rule ), Murmur.ACL );
  135. else:
  136. self.assertEquals( type( rule ), ObjectInfo );
  137. self.assert_( hasattr( rule, "applyHere" ) );
  138. self.assert_( hasattr( rule, "applySubs" ) );
  139. self.assert_( hasattr( rule, "inherited" ) );
  140. self.assert_( hasattr( rule, "userid" ) );
  141. self.assert_( hasattr( rule, "group" ) );
  142. self.assert_( hasattr( rule, "allow" ) );
  143. self.assert_( hasattr( rule, "deny" ) );
  144. for grp in groups:
  145. if self.murmur.ctl.method == "ICE" and self.murmur.version[:2] == ( 1, 2 ):
  146. import Murmur
  147. self.assertEquals( type( grp ), Murmur.Group );
  148. else:
  149. self.assertEquals( type( grp ), ObjectInfo );
  150. self.assert_( hasattr( grp, "name" ) );
  151. self.assert_( hasattr( grp, "inherited" ) );
  152. self.assert_( hasattr( grp, "inherit" ) );
  153. self.assert_( hasattr( grp, "inheritable" ) );
  154. self.assert_( hasattr( grp, "add" ) );
  155. self.assert_( hasattr( grp, "remove" ) );
  156. self.assert_( hasattr( grp, "members" ) );
  157. def run_tests( test_labels, verbosity=1, interactive=True, extra_tests=[] ):
  158. """ Run the Django built in testing framework, but before testing the mumble
  159. app, allow Murmur to be set up correctly.
  160. """
  161. if not test_labels:
  162. test_labels = [ appname.split('.')[-1] for appname in settings.INSTALLED_APPS ];
  163. # No need to sync any murmur servers for the other apps
  164. os.environ['MURMUR_CONNSTR'] = '';
  165. # The easy way: mumble is not being tested.
  166. if "mumble" not in test_labels:
  167. return django_run_tests( test_labels, verbosity, interactive, extra_tests );
  168. # First run everything apart from mumble. mumble will be tested separately, so Murmur
  169. # can be set up properly first.
  170. test_labels.remove( "mumble" );
  171. failed_tests = django_run_tests( test_labels, verbosity, interactive, extra_tests );
  172. failed_tests += run_mumble_tests( verbosity, interactive );
  173. return failed_tests;
  174. def run_mumble_tests( verbosity=1, interactive=True ):
  175. connstrings = {
  176. 'DBus': 'net.sourceforge.mumble.murmur',
  177. 'Ice': 'Meta:tcp -h 127.0.0.1 -p 6502',
  178. };
  179. failed_tests = 0;
  180. def django_run_tests_wrapper( process ):
  181. return django_run_tests( ('mumble',), verbosity, interactive, [] ), False;
  182. for version in get_available_versions():
  183. for method in connstrings:
  184. print "Testing mumble %s via %s" % ( version, method );
  185. os.environ['MURMUR_CONNSTR'] = connstrings[method];
  186. settings.DEFAULT_CONN = connstrings[method];
  187. failed_tests += run_callback( version, django_run_tests_wrapper );
  188. return failed_tests;