Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sajith committed Sep 10, 2024
1 parent 6d55e4e commit 16e17a9
Showing 1 changed file with 88 additions and 1 deletion.
89 changes: 88 additions & 1 deletion tests/test_connection_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,93 @@ def test_connection_request_vlan_invalid_range(self):
**testdata,
)

def test_connection_request_vlan_invalid_integers_in_range(self):
testdata = {
"name": "Bad connection request: vlan must be in [1,4095] range",
"endpoints": [
{
"port_id": "urn:sdx:port:example.net:p:1",
"vlan": "1:10000",
},
{
"port_id": "urn:sdx:port:example.net:p:2",
"vlan": "10000:1",
},
],
}

# Both VLANs are not in the [1,4095] range; expect two
# validation errors.
self.assertRaisesRegex(
ValidationError,
"2 validation errors for ConnectionRequestV1",
ConnectionRequestV1,
**testdata,
)

def test_connection_request_vlan_invalid_strings_in_range(self):
testdata = {
"name": "Bad connection request: vlan must be in [1,4095] range",
"endpoints": [
{
"port_id": "urn:sdx:port:example.net:p:1",
"vlan": "1:10000",
},
{
"port_id": "urn:sdx:port:example.net:p:2",
"vlan": "10000:any",
},
],
}

# Both VLANs are not in the [1,4095] range; expect two
# validation errors.
self.assertRaisesRegex(
ValidationError,
"2 validation errors for ConnectionRequestV1",
ConnectionRequestV1,
**testdata,
)

def test_connection_request_vlan_all_all(self):
testdata = {
"name": "Bad connection request: vlan must be in [1,4095] range",
"endpoints": [
{
"port_id": "urn:sdx:port:example.net:p:1",
"vlan": "all",
},
{
"port_id": "urn:sdx:port:example.net:p:2",
"vlan": "all",
},
],
}

request = ConnectionRequestV1(**testdata)

self.assertEqual(request.endpoints[0].vlan, "all")
self.assertEqual(request.endpoints[1].vlan, "all")

def test_connection_request_vlan_any_any(self):
testdata = {
"name": "Bad connection request: vlan must be in [1,4095] range",
"endpoints": [
{
"port_id": "urn:sdx:port:example.net:p:1",
"vlan": "any",
},
{
"port_id": "urn:sdx:port:example.net:p:2",
"vlan": "any",
},
],
}

request = ConnectionRequestV1(**testdata)

self.assertEqual(request.endpoints[0].vlan, "any")
self.assertEqual(request.endpoints[1].vlan, "any")

def test_connection_request_vlan_invalid_strings(self):
testdata = {
Expand All @@ -182,7 +269,7 @@ def test_connection_request_vlan_invalid_strings(self):
ConnectionRequestV1,
**testdata,
)

def test_connection_request_vlan_valid_range(self):
request_name = "Connection request with valid vlan ranges"
port0_id = "urn:sdx:port:example.net:p:1"
Expand Down

0 comments on commit 16e17a9

Please sign in to comment.