test_wake_on_lan.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import unittest
  2. import ipaddress
  3. from core.NeuronModule import InvalidParameterException, MissingParameterException
  4. from neurons.wake_on_lan.wake_on_lan import Wake_on_lan
  5. class TestWakeOnLan(unittest.TestCase):
  6. def setUp(self):
  7. self.mac_address="00:0a:95:9d:68:16"
  8. self.broadcast_address = "255.255.255.255"
  9. self.port = 42
  10. def testParameters(self):
  11. def run_test_invalidParam(parameters_to_test):
  12. with self.assertRaises(InvalidParameterException):
  13. Wake_on_lan(**parameters_to_test)
  14. def run_test_missingParam(parameters_to_test):
  15. with self.assertRaises(MissingParameterException):
  16. Wake_on_lan(**parameters_to_test)
  17. def run_test_valueError(parameters_to_test):
  18. with self.assertRaises(ValueError):
  19. Wake_on_lan(**parameters_to_test)
  20. # empty
  21. parameters = dict()
  22. run_test_missingParam(parameters)
  23. # missing mac_address
  24. parameters = {
  25. "broadcast_address": self.broadcast_address,
  26. "port": self.port
  27. }
  28. run_test_missingParam(parameters)
  29. # port is not an int
  30. self.port = "port"
  31. parameters = {
  32. "broadcast_address": self.broadcast_address,
  33. "mac_address": self.mac_address,
  34. "port": self.port
  35. }
  36. run_test_invalidParam(parameters)
  37. self.port = 42
  38. # is broadcast not a valid format
  39. self.broadcast_address = "broadcast"
  40. parameters = {
  41. "broadcast_address": self.broadcast_address,
  42. "mac_address": self.mac_address,
  43. "port": self.port
  44. }
  45. run_test_valueError(parameters)
  46. self.broadcast_address = "255.255.255.255"
  47. # is mac_address not a valid IPv4 or IPv6 format
  48. self.mac_address = "mac_address"
  49. parameters = {
  50. "broadcast_address": self.broadcast_address,
  51. "mac_address": self.mac_address,
  52. "port": self.port
  53. }
  54. run_test_valueError(parameters)
  55. self.mac_address = "00:0a:95:9d:68:16"