From d2c9aef052f252ba7444ea778e9e63f8b3f7330c Mon Sep 17 00:00:00 2001 From: Chris Harding Date: Wed, 11 Nov 2015 09:33:07 +0000 Subject: [PATCH] Add unit test for a small part of the VMUser actor class --- .../test_lib/test_dotnetagentlicensing.py | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 unittests/test_lib/test_dotnetagentlicensing.py diff --git a/unittests/test_lib/test_dotnetagentlicensing.py b/unittests/test_lib/test_dotnetagentlicensing.py new file mode 100644 index 000000000..4bcd9b2b7 --- /dev/null +++ b/unittests/test_lib/test_dotnetagentlicensing.py @@ -0,0 +1,28 @@ + +import testing +import xenrt.lib.xenserver.dotnetagentlicensing as dnl +import mock + + +class TestVMUserActorCheckKeyPresent(testing.XenRTUnitTestCase): + + def __createMockOS(self, regKeyExists, regLookupReturnValue): + mockOS = mock.Mock() + mockOS.winRegExists = mock.Mock(return_value=regKeyExists) + mockOS.winRegLookup = mock.Mock(return_value=regLookupReturnValue) + return mockOS + + @mock.patch("xenrt.TEC") + def test_checkKeyPresentFound(self, tec): + cut = dnl.VMUser(None, self.__createMockOS(True, "Fish fingers are the best")) + self.assertTrue(cut.checkKeyPresent(), "key is present") + + @mock.patch("xenrt.TEC") + def test_checkKeyPresentNotFound(self, tec): + cut = dnl.VMUser(None, self.__createMockOS(False, "Hammer Time")) + self.assertFalse(cut.checkKeyPresent(), "key is present") + + @mock.patch("xenrt.TEC") + def test_checkKeyPresentButNoValueSet(self, tec): + cut = dnl.VMUser(None, self.__createMockOS(True, None)) + self.assertFalse(cut.checkKeyPresent(), "key is present") -- 2.39.5