Nir Soffer has uploaded a new change for review.

Change subject: iscsi: Add ChapCredentials equality and hash tests
......................................................................

iscsi: Add ChapCredentials equality and hash tests

Add tests before cleaning up the implementation. Mark __ne__ test as
@brokentest for now, as it is not implemented.

Change-Id: I7f3fde727c179936ba480f5b4cf4c24cacb195b8
Signed-off-by: Nir Soffer <[email protected]>
---
M tests/iscsiTests.py
1 file changed, 59 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/89/43989/1

diff --git a/tests/iscsiTests.py b/tests/iscsiTests.py
index 95e3af4..30df6cd 100644
--- a/tests/iscsiTests.py
+++ b/tests/iscsiTests.py
@@ -4,8 +4,11 @@
 from monkeypatch import MonkeyPatch
 from testlib import VdsmTestCase as TestCaseBase
 from testlib import make_config
+from testlib import expandPermutations, permutations
+from testValidation import brokentest
 
 from vdsm import utils
+from vdsm.password import ProtectedPassword
 
 from storage import iscsi
 from storage import iscsiadm
@@ -59,3 +62,59 @@
                Iface('eth2', 'tcp', None, None, 'eth2', None))
 
         self.assertEqual(tuple(iscsi.iscsiadm.iface_list(out=out)), res)
+
+
+@expandPermutations
+class TestChapCredentialsEquality(TestCaseBase):
+
+    def test_eq_equal(self):
+        c1 = iscsi.ChapCredentials("username", ProtectedPassword("password"))
+        c2 = iscsi.ChapCredentials("username", ProtectedPassword("password"))
+        self.assertTrue(c1 == c2, "%s should equal %s" % (c1, c2))
+
+    def test_eq_subclass(self):
+        class Subclass(iscsi.ChapCredentials):
+            pass
+        c1 = iscsi.ChapCredentials("username", ProtectedPassword("password"))
+        c2 = Subclass("username", ProtectedPassword("password"))
+        self.assertFalse(c1 == c2, "%s should not equal %s" % (c1, c2))
+
+    @permutations([
+        ("a", "a", "a", "b"),
+        ("a", "b", "a", "a"),
+    ])
+    def test_eq_different(self, user1, user2, pass1, pass2):
+        c1 = iscsi.ChapCredentials(user1, ProtectedPassword(pass1))
+        c2 = iscsi.ChapCredentials(user2, ProtectedPassword(pass2))
+        self.assertFalse(c1 == c2, "%s should not equal %s" % (c1, c2))
+
+    @brokentest("__ne__ not implemented")
+    def test_ne_equal(self):
+        c1 = iscsi.ChapCredentials("username", ProtectedPassword("password"))
+        c2 = iscsi.ChapCredentials("username", ProtectedPassword("password"))
+        self.assertFalse(c1 != c2, "%s should equal %s" % (c1, c2))
+
+
+@expandPermutations
+class TestChapCredentialsHash(TestCaseBase):
+
+    def test_equal_same_hash(self):
+        c1 = iscsi.ChapCredentials("username", ProtectedPassword("password"))
+        c2 = iscsi.ChapCredentials("username", ProtectedPassword("password"))
+        self.assertEqual(hash(c1), hash(c2))
+
+    def test_subclass_diffrent_hash(self):
+        class Subclass(iscsi.ChapCredentials):
+            pass
+        c1 = iscsi.ChapCredentials("username", ProtectedPassword("password"))
+        c2 = Subclass("username", ProtectedPassword("password"))
+        self.assertNotEqual(hash(c1), hash(c2))
+
+    @permutations([
+        ("a", "a", "a", "b"),
+        ("a", "b", "a", "a"),
+    ])
+    def test_not_equal_different_hash(self, user1, user2, pass1, pass2):
+        c1 = iscsi.ChapCredentials(user1, ProtectedPassword(pass1))
+        c2 = iscsi.ChapCredentials(user2, ProtectedPassword(pass2))
+        self.assertNotEqual(hash(c1), hash(c2))


-- 
To view, visit https://gerrit.ovirt.org/43989
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7f3fde727c179936ba480f5b4cf4c24cacb195b8
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to