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.

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