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.

208 lines
6.8 KiB

  1. # -*- coding: utf-8 -*-
  2. """
  3. * Copyright © 2009-2010, 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. from django.conf import settings
  16. from django.test import TestCase
  17. from models import Mumble
  18. from utils import ObjectInfo
  19. class InstancesHandling( TestCase ):
  20. """ Tests creation, editing and removing of vserver instances. """
  21. def setUp( self ):
  22. # Make sure we always start with a FRESH murmur instance, checking for left-over instances
  23. # and deleting them before creating ours.
  24. try:
  25. self.murmur = Mumble.objects.get( addr="0.0.0.0", port=31337 );
  26. except Mumble.DoesNotExist:
  27. pass
  28. else:
  29. self.murmur.delete();
  30. finally:
  31. self.murmur = Mumble( name="#unit testing instance#", addr="0.0.0.0", port=31337 );
  32. self.murmur.save();
  33. def testDefaultConf( self ):
  34. conf = self.murmur.ctl.getAllConf( self.murmur.srvid );
  35. self.assert_( type(conf) == dict );
  36. self.assert_( "host" in conf );
  37. self.assert_( "port" in conf );
  38. self.assert_( "certificate" in conf );
  39. self.assert_( "key" in conf );
  40. self.assert_( "registerhostname" in conf );
  41. self.assert_( "registername" in conf );
  42. self.assert_( "channelname" in conf );
  43. self.assert_( "username" in conf );
  44. self.assert_( "obfuscate" in conf );
  45. self.assert_( "defaultchannel" in conf );
  46. def testAddrPortUnique( self ):
  47. try:
  48. duplicate = Mumble(
  49. name="#another unit testing instance#",
  50. addr=self.murmur.addr, port=self.murmur.port,
  51. dbus=settings.DEFAULT_CONN
  52. );
  53. if duplicate.ctl.method == "ICE":
  54. import Murmur
  55. self.assertRaises( Murmur.ServerFailureException, duplicate.save );
  56. elif self.murmur.version[:2] == [ 1, 2 ]:
  57. from dbus import DBusException
  58. self.assertRaises( DBusException, duplicate.save );
  59. else:
  60. from sqlite3 import IntegrityError
  61. self.assertRaises( IntegrityError, duplicate.save );
  62. finally:
  63. # make sure the duplicate is removed
  64. duplicate.ctl.deleteServer( duplicate.srvid );
  65. def tearDown( self ):
  66. self.murmur.delete();
  67. class DataReading( TestCase ):
  68. """ Tests reading data from murmur using the low-level CTL methods. """
  69. def setUp( self ):
  70. # BIG FAT WARNING: This sucks ass, because it assumes the tester has a
  71. # Murmur database like the one I have.
  72. # I definitely need to prepare Murmur somehow before running these tests.
  73. # Just don't yet know how.
  74. self.murmur = Mumble.objects.get(id=1);
  75. def testCtlGetChannels( self ):
  76. """ Test getChannels() """
  77. channels = self.murmur.ctl.getChannels( self.murmur.srvid );
  78. if self.murmur.ctl.method == "ICE":
  79. import Murmur
  80. self.assertEquals( type( channels[0] ), Murmur.Channel );
  81. else:
  82. self.assertEquals( type( channels[0] ), ObjectInfo );
  83. self.assert_( hasattr( channels[0], "id" ) );
  84. self.assert_( hasattr( channels[0], "name" ) );
  85. self.assert_( hasattr( channels[0], "parent" ) );
  86. self.assert_( hasattr( channels[0], "links" ) );
  87. def testCtlGetPlayers( self ):
  88. """ Test getPlayers() """
  89. players = self.murmur.ctl.getPlayers( self.murmur.srvid );
  90. self.assert_( len(players) > 0 );
  91. self.assertEquals( type(players), dict );
  92. for plidx in players:
  93. player = players[plidx];
  94. if self.murmur.ctl.method == "ICE" and self.murmur.version[:2] == ( 1, 2 ):
  95. import Murmur
  96. self.assertEquals( type( player ), Murmur.User );
  97. else:
  98. self.assertEquals( type( player ), ObjectInfo );
  99. self.assert_( hasattr( player, "session" ) );
  100. self.assert_( hasattr( player, "mute" ) );
  101. self.assert_( hasattr( player, "deaf" ) );
  102. self.assert_( hasattr( player, "selfMute" ) );
  103. self.assert_( hasattr( player, "selfDeaf" ) );
  104. self.assert_( hasattr( player, "channel" ) );
  105. self.assert_( hasattr( player, "userid" ) );
  106. self.assert_( hasattr( player, "name" ) );
  107. self.assert_( hasattr( player, "onlinesecs" ) );
  108. self.assert_( hasattr( player, "bytespersec" ) );
  109. def testCtlGetRegisteredPlayers( self ):
  110. """ Test getRegistredPlayers() and getRegistration() """
  111. players = self.murmur.ctl.getRegisteredPlayers( self.murmur.srvid );
  112. self.assert_( len(players) > 0 );
  113. self.assertEquals( type(players), dict );
  114. for plidx in players:
  115. player = players[plidx];
  116. self.assertEquals( type( player ), ObjectInfo );
  117. self.assert_( hasattr( player, "userid" ) );
  118. self.assert_( hasattr( player, "name" ) );
  119. self.assert_( hasattr( player, "email" ) );
  120. self.assert_( hasattr( player, "pw" ) );
  121. # compare with getRegistration result
  122. reg = self.murmur.ctl.getRegistration( self.murmur.srvid, player.userid );
  123. self.assertEquals( type( reg ), ObjectInfo );
  124. self.assert_( hasattr( reg, "userid" ) );
  125. self.assert_( hasattr( reg, "name" ) );
  126. self.assert_( hasattr( reg, "email" ) );
  127. self.assert_( hasattr( reg, "pw" ) );
  128. self.assertEquals( player.userid, reg.userid );
  129. self.assertEquals( player.name, reg.name );
  130. self.assertEquals( player.email, reg.email );
  131. self.assertEquals( player.pw, reg.pw );
  132. def testCtlGetAcl( self ):
  133. """ Test getACL() for the root channel """
  134. acls, groups, inherit = self.murmur.ctl.getACL( self.murmur.srvid, 0 );
  135. for rule in acls:
  136. if self.murmur.ctl.method == "ICE" and self.murmur.version[:2] == ( 1, 2 ):
  137. import Murmur
  138. self.assertEquals( type( rule ), Murmur.ACL );
  139. else:
  140. self.assertEquals( type( rule ), ObjectInfo );
  141. self.assert_( hasattr( rule, "applyHere" ) );
  142. self.assert_( hasattr( rule, "applySubs" ) );
  143. self.assert_( hasattr( rule, "inherited" ) );
  144. self.assert_( hasattr( rule, "userid" ) );
  145. self.assert_( hasattr( rule, "group" ) );
  146. self.assert_( hasattr( rule, "allow" ) );
  147. self.assert_( hasattr( rule, "deny" ) );
  148. for grp in groups:
  149. if self.murmur.ctl.method == "ICE":
  150. import Murmur
  151. self.assertEquals( type( grp ), Murmur.Group );
  152. else:
  153. self.assertEquals( type( grp ), ObjectInfo );
  154. self.assert_( hasattr( grp, "name" ) );
  155. self.assert_( hasattr( grp, "inherited" ) );
  156. self.assert_( hasattr( grp, "inherit" ) );
  157. self.assert_( hasattr( grp, "inheritable" ) );
  158. self.assert_( hasattr( grp, "add" ) );
  159. self.assert_( hasattr( grp, "remove" ) );
  160. self.assert_( hasattr( grp, "members" ) );