Skip to content

Commit

Permalink
Update UnitTests to check for Identities of multiple bases
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseIgnacioTamayo committed Jul 31, 2024
1 parent 64a785a commit 5ac4a75
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 26 deletions.
20 changes: 10 additions & 10 deletions tests/identityref/identityref.yang
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module identityref {
yang-version "1";
yang-version "1.1";
namespace "http://rob.sh/yang/test/identityref";
prefix "foo";

Expand Down Expand Up @@ -66,46 +66,46 @@ module identityref {
identity local-base;

container test-container {
leaf id1 {
leaf id_base {
type identityref {
base base-identity;
}
}

leaf idr1 {
leaf id_remote {
type identityref {
base defn:remote-base;
}
}

leaf id2 {
leaf grandfather {
type identityref {
base grandfather;
}
}

leaf id3 {
leaf greatgrandmother {
type identityref {
base greatgrandmother;
}
}

leaf id4 {
leaf mother {
type identityref {
base mother;
}
}

leaf id5 {
leaf grandmother {
type identityref {
base grandmother;
}
}

leaf id6 {
leaf grandparent {
type identityref {
base son;
base daughter;
base grandfather;
base grandmother;
}
}
}
Expand Down
51 changes: 35 additions & 16 deletions tests/identityref/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ def setUp(self):
self.instance = self.bindings.identityref()

def test_identityref_leafs_get_created(self):
for leaf in ["id1", "idr1"]:
for leaf in ["id_base", "id_remote"]:
with self.subTest(leaf=leaf):
self.assertTrue(hasattr(self.instance.test_container, leaf))

def test_cant_assign_invalid_string_to_identityref(self):
with self.assertRaises(ValueError):
self.instance.test_container.id1 = "hello"
self.instance.test_container.grandfather = "hello"

def test_identityref_leafs_are_blank_by_default(self):
for leaf in ["id1", "idr1"]:
for leaf in ["id_base", "id_remote"]:
with self.subTest(leaf=leaf):
self.assertEqual(getattr(self.instance.test_container, leaf), "")

Expand All @@ -33,7 +33,7 @@ def test_identityref_accepts_valid_identity_values(self):
with self.subTest(identity=identity):
allowed = True
try:
self.instance.test_container.id1 = identity
self.instance.test_container.id_base = identity
except ValueError:
allowed = False
self.assertTrue(allowed)
Expand All @@ -43,7 +43,7 @@ def test_remote_identityref_accepts_valid_identity_values(self):
with self.subTest(identity=identity):
allowed = True
try:
self.instance.test_container.idr1 = identity
self.instance.test_container.id_remote = identity
except ValueError:
allowed = False
self.assertTrue(allowed)
Expand All @@ -52,6 +52,8 @@ def test_set_ancestral_identities_one(self):
for identity, valid in [
("father", True),
("son", True),
("daughter", True),
("mother", False),
("foo:father", True),
("foo:son", True),
("elephant", False),
Expand All @@ -60,10 +62,10 @@ def test_set_ancestral_identities_one(self):
with self.subTest(identity=identity, valid=valid):
allowed = True
try:
self.instance.test_container.id2 = identity
self.instance.test_container.grandfather = identity
except ValueError:
allowed = False
self.assertEqual(allowed, valid)
self.assertEqual(allowed, valid, identity)

def test_set_ancestral_identities_two(self):
for identity, valid in [
Expand All @@ -73,43 +75,60 @@ def test_set_ancestral_identities_two(self):
("aunt", True),
("cousin", True),
("daughter", True),
("son", False),
("son", True),
("father", False),
("grandfather", False),
]:
with self.subTest(identity=identity, valid=valid):
allowed = True
try:
self.instance.test_container.id3 = identity
self.instance.test_container.greatgrandmother = identity
except ValueError:
allowed = False
self.assertEqual(allowed, valid)
self.assertEqual(allowed, valid, identity)

def test_set_ancestral_identities_three(self):
for identity, valid in [("daughter", True), ("cousin", False), ("aunt", False)]:
for identity, valid in [("daughter", True), ("son", True), ("cousin", False), ("aunt", False)]:
with self.subTest(identity=identity, valid=valid):
allowed = True
try:
self.instance.test_container.id4 = identity
self.instance.test_container.mother = identity
except ValueError:
allowed = False
self.assertEqual(allowed, valid)
self.assertEqual(allowed, valid, identity)

def test_set_ancestral_identities_four(self):
for identity, valid in [
("daughter", True),
("son", True),
("cousin", True),
("mother", True),
("father", False),
("aunt", True),
("greatgrandmother", False),
]:
with self.subTest(identity=identity, valid=valid):
allowed = True
try:
self.instance.test_container.id5 = identity
self.instance.test_container.grandmother = identity
except ValueError:
allowed = False
self.assertEqual(allowed, valid)
self.assertEqual(allowed, valid, identity)

def test_set_ancestral_identities_five(self):
for identity, valid in [
("mother", False),
("father", True),
("cousin", False),
("son", True),
]:
with self.subTest(identity=identity, valid=valid):
allowed = True
try:
self.instance.test_container.grandparent = identity
except ValueError:
allowed = False
self.assertEqual(allowed, valid, identity)

def test_grouping_identity_inheritance(self):
for address_type, valid in [
Expand All @@ -135,7 +154,7 @@ def test_set_identityref_from_imported_module(self):
with self.subTest(identity=identity, valid=valid):
allowed = True
try:
self.instance.test_container.idr1 = identity
self.instance.test_container.id_remote = identity
except ValueError:
allowed = False
self.assertEqual(allowed, valid)
Expand Down

0 comments on commit 5ac4a75

Please sign in to comment.