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.

202 lines
6.5 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 models import *
  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( name="#another unit testing instance#", addr="0.0.0.0", port=31337 );
  49. if duplicate.ctl.method == "ICE":
  50. import Murmur
  51. self.assertRaises( Murmur.ServerFailureException, duplicate.save );
  52. else:
  53. from sqlite3 import IntegrityError
  54. self.assertRaises( IntegrityError, duplicate.save );
  55. finally:
  56. # make sure the duplicate is removed
  57. duplicate.ctl.deleteServer( duplicate.srvid );
  58. def tearDown( self ):
  59. self.murmur.delete();
  60. class DataReading( TestCase ):
  61. """ Tests reading data from murmur using the low-level CTL methods. """
  62. def setUp( self ):
  63. # BIG FAT WARNING: This sucks ass, because it assumes the tester has a
  64. # Murmur database like the one I have.
  65. # I definitely need to prepare Murmur somehow before running these tests.
  66. # Just don't yet know how.
  67. self.murmur = Mumble.objects.get(id=1);
  68. def testCtlGetChannels( self ):
  69. """ Test getChannels() """
  70. channels = self.murmur.ctl.getChannels( self.murmur.srvid );
  71. if self.murmur.ctl.method == "ICE":
  72. import Murmur
  73. self.assertEquals( type( channels[0] ), Murmur.Channel );
  74. else:
  75. self.assertEquals( type( channels[0] ), ObjectInfo );
  76. self.assert_( hasattr( channels[0], "id" ) );
  77. self.assert_( hasattr( channels[0], "name" ) );
  78. self.assert_( hasattr( channels[0], "parent" ) );
  79. self.assert_( hasattr( channels[0], "links" ) );
  80. def testCtlGetPlayers( self ):
  81. """ Test getPlayers() """
  82. players = self.murmur.ctl.getPlayers( self.murmur.srvid );
  83. self.assert_( len(players) > 0 );
  84. self.assertEquals( type(players), dict );
  85. for plidx in players:
  86. player = players[plidx];
  87. if self.murmur.ctl.method == "ICE" and self.murmur.version[:2] == ( 1, 2 ):
  88. import Murmur
  89. self.assertEquals( type( player ), Murmur.User );
  90. else:
  91. self.assertEquals( type( player ), ObjectInfo );
  92. self.assert_( hasattr( player, "session" ) );
  93. self.assert_( hasattr( player, "mute" ) );
  94. self.assert_( hasattr( player, "deaf" ) );
  95. self.assert_( hasattr( player, "selfMute" ) );
  96. self.assert_( hasattr( player, "selfDeaf" ) );
  97. self.assert_( hasattr( player, "channel" ) );
  98. self.assert_( hasattr( player, "userid" ) );
  99. self.assert_( hasattr( player, "name" ) );
  100. self.assert_( hasattr( player, "onlinesecs" ) );
  101. self.assert_( hasattr( player, "bytespersec" ) );
  102. def testCtlGetRegisteredPlayers( self ):
  103. """ Test getRegistredPlayers() and getRegistration() """
  104. players = self.murmur.ctl.getRegisteredPlayers( self.murmur.srvid );
  105. self.assert_( len(players) > 0 );
  106. self.assertEquals( type(players), dict );
  107. for plidx in players:
  108. player = players[plidx];
  109. self.assertEquals( type( player ), ObjectInfo );
  110. self.assert_( hasattr( player, "userid" ) );
  111. self.assert_( hasattr( player, "name" ) );
  112. self.assert_( hasattr( player, "email" ) );
  113. self.assert_( hasattr( player, "pw" ) );
  114. # compare with getRegistration result
  115. reg = self.murmur.ctl.getRegistration( self.murmur.srvid, player.userid );
  116. self.assertEquals( type( reg ), ObjectInfo );
  117. self.assert_( hasattr( reg, "userid" ) );
  118. self.assert_( hasattr( reg, "name" ) );
  119. self.assert_( hasattr( reg, "email" ) );
  120. self.assert_( hasattr( reg, "pw" ) );
  121. self.assertEquals( player.userid, reg.userid );
  122. self.assertEquals( player.name, reg.name );
  123. self.assertEquals( player.email, reg.email );
  124. self.assertEquals( player.pw, reg.pw );
  125. def testCtlGetAcl( self ):
  126. """ Test getACL() for the root channel """
  127. acls, groups, inherit = self.murmur.ctl.getACL( self.murmur.srvid, 0 );
  128. for rule in acls:
  129. if self.murmur.ctl.method == "ICE" and self.murmur.version[:2] == ( 1, 2 ):
  130. import Murmur
  131. self.assertEquals( type( rule ), Murmur.ACL );
  132. else:
  133. self.assertEquals( type( rule ), ObjectInfo );
  134. self.assert_( hasattr( rule, "applyHere" ) );
  135. self.assert_( hasattr( rule, "applySubs" ) );
  136. self.assert_( hasattr( rule, "inherited" ) );
  137. self.assert_( hasattr( rule, "userid" ) );
  138. self.assert_( hasattr( rule, "group" ) );
  139. self.assert_( hasattr( rule, "allow" ) );
  140. self.assert_( hasattr( rule, "deny" ) );
  141. for grp in groups:
  142. if self.murmur.ctl.method == "ICE":
  143. import Murmur
  144. self.assertEquals( type( grp ), Murmur.Group );
  145. else:
  146. self.assertEquals( type( grp ), ObjectInfo );
  147. self.assert_( hasattr( grp, "name" ) );
  148. self.assert_( hasattr( grp, "inherited" ) );
  149. self.assert_( hasattr( grp, "inherit" ) );
  150. self.assert_( hasattr( grp, "inheritable" ) );
  151. self.assert_( hasattr( grp, "add" ) );
  152. self.assert_( hasattr( grp, "remove" ) );
  153. self.assert_( hasattr( grp, "members" ) );