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.

82 lines
3.4 KiB

  1. # -*- coding: utf-8 -*-
  2. # kate: space-indent on; indent-width 4; replace-tabs on;
  3. """
  4. * Copyright © 2009-2014, 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. # This is somewhat ugly, but it makes life much easier.
  17. import os
  18. os.environ['MURMUR_CONNSTR'] = 'Meta:tcp -h 127.0.0.1 -p 6502'
  19. os.environ['MURMUR_ICESECRET'] = ''
  20. import mock
  21. from django.test import TestCase
  22. from mumble.models import MumbleServer, Mumble, MumbleUser
  23. class IceTestCase(TestCase):
  24. def test_loadSlice_getSliceDir(self):
  25. with mock.patch("mumble.MumbleCtlIce.Ice") as mock_Ice:
  26. mock_Ice.getSliceDir.return_value = "/tmp/slice"
  27. from mumble.MumbleCtlIce import loadSlice
  28. loadSlice("someslice")
  29. self.assertTrue( mock_Ice.loadSlice.called)
  30. self.assertEqual(mock_Ice.loadSlice.call_count, 1)
  31. self.assertEqual(mock_Ice.loadSlice.call_args[0], ('', ['-I/tmp/slice', 'someslice']))
  32. def test_loadSlice_getSliceDir_empty(self):
  33. with mock.patch("mumble.MumbleCtlIce.Ice") as mock_Ice:
  34. mock_Ice.getSliceDir.return_value = ""
  35. from django.conf import settings
  36. from mumble.MumbleCtlIce import loadSlice
  37. loadSlice("someslice")
  38. self.assertTrue( mock_Ice.loadSlice.called)
  39. self.assertEqual(mock_Ice.loadSlice.call_count, 1)
  40. self.assertEqual(mock_Ice.loadSlice.call_args[0], ('', ['-I' + settings.SLICEDIR, 'someslice']))
  41. def test_loadSlice_getSliceDir_nonexistant(self):
  42. with mock.patch("mumble.MumbleCtlIce.Ice") as mock_Ice:
  43. mock_Ice.mock_add_spec(["loadSlice"])
  44. from django.conf import settings
  45. from mumble.MumbleCtlIce import loadSlice
  46. loadSlice("someslice")
  47. self.assertTrue( mock_Ice.loadSlice.called)
  48. self.assertEqual(mock_Ice.loadSlice.call_count, 1)
  49. self.assertEqual(mock_Ice.loadSlice.call_args[0], ('', ['-I' + settings.SLICEDIR, 'someslice']))
  50. def test_MumbleCtlIce(self):
  51. with mock.patch("mumble.MumbleCtlIce.Ice") as mock_Ice, \
  52. mock.patch("mumble.MumbleCtlIce.IcePy") as mock_IcePy, \
  53. mock.patch("Murmur.MetaPrx") as mock_MetaPrx:
  54. mock_MetaPrx.checkedCast().getVersion.return_value = (1, 2, 3, "12oi3j1")
  55. from mumble.MumbleCtlIce import MumbleCtlIce
  56. ctl = MumbleCtlIce('Meta:tcp -h 127.0.0.1 -p 6502')
  57. self.assertTrue( mock_Ice.createProperties().setProperty.called)
  58. self.assertEqual(mock_Ice.createProperties().setProperty.call_count, 2)
  59. self.assertEqual(mock_Ice.createProperties().setProperty.call_args_list[0][0], ("Ice.ImplicitContext", "Shared"))
  60. self.assertEqual(mock_Ice.createProperties().setProperty.call_args_list[1][0], ("Ice.MessageSizeMax", "65535"))
  61. mock_prx = mock_Ice.initialize().stringToProxy()
  62. self.assertTrue( mock_prx.ice_ping.called)