Skip to content

Commit 7044f55

Browse files
committed
fix(network): integrate test (#85)
1 parent 14bfd70 commit 7044f55

File tree

1 file changed

+18
-40
lines changed

1 file changed

+18
-40
lines changed

tests/tools/test_network_tools.py

Lines changed: 18 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,6 +1370,7 @@ def test_update_reassign_bulk_and_auto_assign_floating_ip(
13701370
assert isinstance(auto, FloatingIP)
13711371

13721372
def test_get_security_groups_filters(self, mock_openstack_connect_network):
1373+
"""Test getting security groups with filters."""
13731374
mock_conn = mock_openstack_connect_network
13741375

13751376
sg = Mock()
@@ -1382,54 +1383,31 @@ def test_get_security_groups_filters(self, mock_openstack_connect_network):
13821383
{"id": "r-1"},
13831384
{"id": "r-2"},
13841385
]
1385-
mock_conn.network.security_groups.return_value = [sg]
1386+
1387+
expected_sg = SecurityGroup(
1388+
id="sg-1",
1389+
name="default",
1390+
status=None,
1391+
description="desc",
1392+
project_id="proj-1",
1393+
security_group_rule_ids=["r-1", "r-2"],
1394+
)
13861395

13871396
tools = self.get_network_tools()
1397+
1398+
# Test by project_id and name
1399+
mock_conn.network.security_groups.return_value = [sg]
13881400
res = tools.get_security_groups(project_id="proj-1", name="default")
1389-
assert res == [
1390-
SecurityGroup(
1391-
id="sg-1",
1392-
name="default",
1393-
status=None,
1394-
description="desc",
1395-
project_id="proj-1",
1396-
security_group_rule_ids=["r-1", "r-2"],
1397-
)
1398-
]
1399-
mock_conn.network.security_groups.assert_called_once_with(
1401+
assert res == [expected_sg]
1402+
mock_conn.network.security_groups.assert_called_with(
14001403
project_id="proj-1", name="default"
14011404
)
14021405

1403-
def test_get_security_groups_filter_by_id(
1404-
self, mock_openstack_connect_network
1405-
):
1406-
mock_conn = mock_openstack_connect_network
1407-
1408-
sg = Mock()
1409-
sg.id = "sg-1"
1410-
sg.name = "default"
1411-
sg.status = None
1412-
sg.description = "desc"
1413-
sg.project_id = "proj-1"
1414-
sg.security_group_rules = [
1415-
{"id": "r-1"},
1416-
{"id": "r-2"},
1417-
]
1406+
# Test by id
14181407
mock_conn.network.security_groups.return_value = [sg]
1419-
1420-
tools = self.get_network_tools()
14211408
res = tools.get_security_groups(id="sg-1")
1422-
assert res == [
1423-
SecurityGroup(
1424-
id="sg-1",
1425-
name="default",
1426-
status=None,
1427-
description="desc",
1428-
project_id="proj-1",
1429-
security_group_rule_ids=["r-1", "r-2"],
1430-
)
1431-
]
1432-
mock_conn.network.security_groups.assert_called_once_with(id="sg-1")
1409+
assert res == [expected_sg]
1410+
mock_conn.network.security_groups.assert_called_with(id="sg-1")
14331411

14341412
def test_create_security_group(self, mock_openstack_connect_network):
14351413
mock_conn = mock_openstack_connect_network

0 commit comments

Comments
 (0)