Skip to content

Commit

Permalink
Rename TestNode to FakeNode
Browse files Browse the repository at this point in the history
Classes that start with `Test` are identified as test cases, causing
warnings during test discovery. In this commit we rename `TestNode` to
`FakeNode` to prevent it from being erroneously collected as a test.
  • Loading branch information
larsks committed Jul 19, 2024
1 parent 7fbf8df commit 8db5b55
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 62 deletions.
2 changes: 1 addition & 1 deletion esi_leap/resource_objects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# types derived from base won't show as subclasses unless imported somewhere
from esi_leap.resource_objects import dummy_node # noqa: F401
from esi_leap.resource_objects import ironic_node # noqa: F401
from esi_leap.resource_objects import test_node # noqa: F401
from esi_leap.resource_objects import fake_node # noqa: F401


_RESOURCE_TYPE_MAP = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from esi_leap.resource_objects import base


class TestNode(base.ResourceObjectInterface):
class FakeNode(base.ResourceObjectInterface):
resource_type = "test_node"

def __init__(self, uuid, project_id="12345"):
Expand Down
4 changes: 2 additions & 2 deletions esi_leap/tests/api/controllers/v1/test_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import mock

from esi_leap.common import exception
from esi_leap.resource_objects.test_node import TestNode
from esi_leap.resource_objects.fake_node import FakeNode
from esi_leap.tests.api import base as test_api_base


Expand Down Expand Up @@ -82,7 +82,7 @@ def test_get_all_resource_filter(self, mock_ega, mock_gro, mock_gpufi, mock_pa):
fake_event = FakeEvent()
expected_filters = {"resource_type": "test_node", "resource_uuid": "1111"}
mock_pa.side_effect = None
mock_gro.return_value = TestNode("1111")
mock_gro.return_value = FakeNode("1111")
mock_ega.return_value = [fake_event]

data = self.get_json("/events?resource_uuid=1111&resource_type=test_node")
Expand Down
6 changes: 3 additions & 3 deletions esi_leap/tests/api/controllers/v1/test_lease.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from esi_leap.common import statuses
from esi_leap.objects import lease as lease_obj
from esi_leap.resource_objects.ironic_node import IronicNode
from esi_leap.resource_objects.test_node import TestNode
from esi_leap.resource_objects.fake_node import FakeNode
from esi_leap.tests.api import base as test_api_base


Expand Down Expand Up @@ -98,7 +98,7 @@ def test_post(
mock_gro,
mock_lgdwai,
):
resource = TestNode("1234567890")
resource = FakeNode("1234567890")
data = {
"project_id": "lesseeid",
"resource_type": "test_node",
Expand Down Expand Up @@ -453,7 +453,7 @@ def test_get_owner_filter(
def test_get_resource_filter(
self, mock_get_all, mock_lgaaf, mock_gro, mock_lgdwai, mock_gpl, mock_gnl
):
mock_gro.return_value = TestNode("54321")
mock_gro.return_value = FakeNode("54321")
mock_get_all.return_value = [self.test_lease, self.test_lease]
mock_gpl.return_value = []
mock_gnl.return_value = []
Expand Down
12 changes: 6 additions & 6 deletions esi_leap/tests/api/controllers/v1/test_offer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from esi_leap.common import statuses
from esi_leap.objects import offer
from esi_leap.resource_objects.ironic_node import IronicNode
from esi_leap.resource_objects.test_node import TestNode
from esi_leap.resource_objects.fake_node import FakeNode
from esi_leap.tests.api import base as test_api_base


Expand Down Expand Up @@ -124,7 +124,7 @@ def test_empty(self):
def test_post(
self, mock_ogdwai, mock_create, mock_cra, mock_generate_uuid, mock_gro
):
resource = TestNode(self.test_offer.resource_uuid)
resource = FakeNode(self.test_offer.resource_uuid)
mock_gro.return_value = resource
mock_generate_uuid.return_value = self.test_offer.uuid
mock_create.return_value = self.test_offer
Expand Down Expand Up @@ -210,7 +210,7 @@ def test_post_lessee(
mock_gpufi,
mock_gro,
):
resource = TestNode(self.test_offer_lessee.resource_uuid)
resource = FakeNode(self.test_offer_lessee.resource_uuid)
mock_gro.return_value = resource
mock_gpufi.return_value = "lessee_uuid"
mock_generate_uuid.return_value = self.test_offer_lessee.uuid
Expand Down Expand Up @@ -260,7 +260,7 @@ def test_post_non_admin_parent_lease(
mock_gro,
mock_crla,
):
resource = TestNode(self.test_offer_with_parent.resource_uuid)
resource = FakeNode(self.test_offer_with_parent.resource_uuid)
mock_gro.return_value = resource
mock_generate_uuid.return_value = self.test_offer_with_parent.uuid
mock_create.return_value = self.test_offer_with_parent
Expand Down Expand Up @@ -320,7 +320,7 @@ def test_post_non_admin_no_parent_lease(
mock_gro,
mock_crla,
):
resource = TestNode(self.test_offer_with_parent.resource_uuid)
resource = FakeNode(self.test_offer_with_parent.resource_uuid)
mock_gro.return_value = resource
mock_generate_uuid.return_value = self.test_offer_with_parent.uuid
mock_create.return_value = self.test_offer_with_parent
Expand Down Expand Up @@ -496,7 +496,7 @@ def test_get_resource_filter(
_get_offer_response(self.test_offer, use_datetime=True),
_get_offer_response(self.test_offer_2, use_datetime=True),
]
mock_gro.return_value = TestNode("54321")
mock_gro.return_value = FakeNode("54321")
mock_gpl.return_value = []
mock_gnl.return_value = []

Expand Down
10 changes: 5 additions & 5 deletions esi_leap/tests/api/controllers/v1/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from esi_leap.common import statuses
from esi_leap.objects import lease
from esi_leap.objects import offer
from esi_leap.resource_objects.test_node import TestNode
from esi_leap.resource_objects.fake_node import FakeNode


admin_ctx = ctx.RequestContext(project_id="adminid", roles=["admin"])
Expand All @@ -45,8 +45,8 @@
end = start + datetime.timedelta(days=100)
end_iso = "2016-10-24T00:00:00"

test_node_1 = TestNode("111", owner_ctx.project_id)
test_node_2 = TestNode("bbb", owner_ctx_2.project_id)
test_node_1 = FakeNode("111", owner_ctx.project_id)
test_node_2 = FakeNode("bbb", owner_ctx_2.project_id)

o_uuid = uuidutils.generate_uuid()

Expand Down Expand Up @@ -684,11 +684,11 @@ def setUp(self):
parent_lease_uuid=None,
)

@mock.patch("esi_leap.resource_objects.test_node.TestNode.get_name")
@mock.patch("esi_leap.resource_objects.fake_node.FakeNode.get_name")
@mock.patch("esi_leap.common.keystone.get_project_name")
@mock.patch("esi_leap.objects.lease.get_resource_object")
def test_lease_get_dict_with_added_info(self, mock_gro, mock_gpn, mock_gn):
mock_gro.return_value = TestNode("111")
mock_gro.return_value = FakeNode("111")
mock_gpn.return_value = "project-name"
mock_gn.return_value = "resource-name"

Expand Down
4 changes: 2 additions & 2 deletions esi_leap/tests/common/test_notification_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from esi_leap.common import notification_utils as notif_utils
from esi_leap.objects import fields
from esi_leap.objects import lease as lease_obj
from esi_leap.resource_objects.test_node import TestNode
from esi_leap.resource_objects.fake_node import FakeNode
from esi_leap.tests import base as tests_base


Expand Down Expand Up @@ -48,7 +48,7 @@ def setUp(self):
status="created",
purpose=None,
)
self.node = TestNode(uuidutils.generate_uuid(), "12345")
self.node = FakeNode(uuidutils.generate_uuid(), "12345")

def test_emit_notification(self):
self.config(host="fake-host")
Expand Down
72 changes: 36 additions & 36 deletions esi_leap/tests/objects/test_lease.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from esi_leap.objects import fields as obj_fields
from esi_leap.objects import lease as lease_obj
from esi_leap.objects import offer as offer_obj
from esi_leap.resource_objects.test_node import TestNode
from esi_leap.resource_objects.fake_node import FakeNode
from esi_leap.tests import base


Expand Down Expand Up @@ -243,12 +243,12 @@ def update_mock(updates, context):
mock_save.assert_called_once()

@mock.patch("esi_leap.objects.lease.Lease.resource_object")
@mock.patch("esi_leap.resource_objects.test_node.TestNode.set_lease")
@mock.patch("esi_leap.resource_objects.fake_node.FakeNode.set_lease")
@mock.patch("esi_leap.objects.lease.Lease.save")
@mock.patch("esi_leap.common.notification_utils" "._emit_notification")
def test_fulfill(self, mock_notify, mock_save, mock_set_lease, mock_ro):
lease = lease_obj.Lease(self.context, **self.test_lease_dict)
test_node = TestNode(uuidutils.generate_uuid(), "12345")
test_node = FakeNode(uuidutils.generate_uuid(), "12345")

mock_ro.return_value = test_node

Expand Down Expand Up @@ -282,12 +282,12 @@ def test_fulfill(self, mock_notify, mock_save, mock_set_lease, mock_ro):
self.assertEqual(lease.status, statuses.ACTIVE)

@mock.patch("esi_leap.objects.lease.Lease.resource_object")
@mock.patch("esi_leap.resource_objects.test_node.TestNode.set_lease")
@mock.patch("esi_leap.resource_objects.fake_node.FakeNode.set_lease")
@mock.patch("esi_leap.objects.lease.Lease.save")
@mock.patch("esi_leap.common.notification_utils" "._emit_notification")
def test_fulfill_error(self, mock_notify, mock_save, mock_set_lease, mock_ro):
lease = lease_obj.Lease(self.context, **self.test_lease_dict)
test_node = TestNode(uuidutils.generate_uuid(), "12345")
test_node = FakeNode(uuidutils.generate_uuid(), "12345")

mock_ro.return_value = test_node
mock_set_lease.side_effect = Exception("bad")
Expand Down Expand Up @@ -321,18 +321,18 @@ def test_fulfill_error(self, mock_notify, mock_save, mock_set_lease, mock_ro):
mock_save.assert_called_once()
self.assertEqual(lease.status, statuses.WAIT_FULFILL)

@mock.patch("esi_leap.resource_objects.test_node.TestNode.set_lease")
@mock.patch("esi_leap.resource_objects.fake_node.FakeNode.set_lease")
@mock.patch("esi_leap.objects.lease.Lease.get")
@mock.patch("esi_leap.objects.lease.Lease.resource_object")
@mock.patch("esi_leap.resource_objects.test_node.TestNode.get_lease_uuid")
@mock.patch("esi_leap.resource_objects.test_node.TestNode.remove_lease")
@mock.patch("esi_leap.resource_objects.fake_node.FakeNode.get_lease_uuid")
@mock.patch("esi_leap.resource_objects.fake_node.FakeNode.remove_lease")
@mock.patch("esi_leap.objects.lease.Lease.save")
@mock.patch("esi_leap.common.notification_utils" "._emit_notification")
def test_cancel(
self, mock_notify, mock_save, mock_rl, mock_glu, mock_ro, mock_lg, mock_sl
):
lease = lease_obj.Lease(self.context, **self.test_lease_dict)
test_node = TestNode(uuidutils.generate_uuid(), "12345")
test_node = FakeNode(uuidutils.generate_uuid(), "12345")

mock_ro.return_value = test_node
mock_glu.return_value = lease.uuid
Expand Down Expand Up @@ -368,18 +368,18 @@ def test_cancel(
mock_save.assert_called_once()
self.assertEqual(lease.status, statuses.DELETED)

@mock.patch("esi_leap.resource_objects.test_node.TestNode.set_lease")
@mock.patch("esi_leap.resource_objects.fake_node.FakeNode.set_lease")
@mock.patch("esi_leap.objects.lease.Lease.get")
@mock.patch("esi_leap.objects.lease.Lease.resource_object")
@mock.patch("esi_leap.resource_objects.test_node.TestNode.get_lease_uuid")
@mock.patch("esi_leap.resource_objects.test_node.TestNode.remove_lease")
@mock.patch("esi_leap.resource_objects.fake_node.FakeNode.get_lease_uuid")
@mock.patch("esi_leap.resource_objects.fake_node.FakeNode.remove_lease")
@mock.patch("esi_leap.objects.lease.Lease.save")
@mock.patch("esi_leap.common.notification_utils" "._emit_notification")
def test_cancel_error(
self, mock_notify, mock_save, mock_rl, mock_glu, mock_ro, mock_lg, mock_sl
):
lease = lease_obj.Lease(self.context, **self.test_lease_dict)
test_node = TestNode(uuidutils.generate_uuid(), "12345")
test_node = FakeNode(uuidutils.generate_uuid(), "12345")

mock_ro.return_value = test_node
mock_glu.return_value = lease.uuid
Expand Down Expand Up @@ -417,18 +417,18 @@ def test_cancel_error(
mock_save.assert_called_once()
self.assertEqual(lease.status, statuses.WAIT_CANCEL)

@mock.patch("esi_leap.resource_objects.test_node.TestNode.set_lease")
@mock.patch("esi_leap.resource_objects.fake_node.FakeNode.set_lease")
@mock.patch("esi_leap.objects.lease.Lease.get")
@mock.patch("esi_leap.objects.lease.Lease.resource_object")
@mock.patch("esi_leap.resource_objects.test_node.TestNode.get_lease_uuid")
@mock.patch("esi_leap.resource_objects.test_node.TestNode.remove_lease")
@mock.patch("esi_leap.resource_objects.fake_node.FakeNode.get_lease_uuid")
@mock.patch("esi_leap.resource_objects.fake_node.FakeNode.remove_lease")
@mock.patch("esi_leap.objects.lease.Lease.save")
@mock.patch("esi_leap.common.notification_utils" "._emit_notification")
def test_cancel_with_parent(
self, mock_notify, mock_save, mock_rl, mock_glu, mock_ro, mock_lg, mock_sl
):
lease = lease_obj.Lease(self.context, **self.test_lease_parent_lease_dict)
test_node = TestNode(uuidutils.generate_uuid(), "12345")
test_node = FakeNode(uuidutils.generate_uuid(), "12345")

mock_ro.return_value = test_node
mock_glu.return_value = lease.uuid
Expand Down Expand Up @@ -466,13 +466,13 @@ def test_cancel_with_parent(
self.assertEqual(lease.status, statuses.DELETED)

@mock.patch("esi_leap.objects.lease.Lease.resource_object")
@mock.patch("esi_leap.resource_objects.test_node.TestNode.get_lease_uuid")
@mock.patch("esi_leap.resource_objects.test_node.TestNode.remove_lease")
@mock.patch("esi_leap.resource_objects.fake_node.FakeNode.get_lease_uuid")
@mock.patch("esi_leap.resource_objects.fake_node.FakeNode.remove_lease")
@mock.patch("esi_leap.objects.lease.Lease.save")
@mock.patch("esi_leap.common.notification_utils" "._emit_notification")
def test_cancel_no_expire(self, mock_notify, mock_save, mock_rl, mock_glu, mock_ro):
lease = lease_obj.Lease(self.context, **self.test_lease_dict)
test_node = TestNode(uuidutils.generate_uuid(), "12345")
test_node = FakeNode(uuidutils.generate_uuid(), "12345")

mock_ro.return_value = test_node
mock_glu.return_value = "some-other-lease-uuid"
Expand Down Expand Up @@ -507,18 +507,18 @@ def test_cancel_no_expire(self, mock_notify, mock_save, mock_rl, mock_glu, mock_
mock_save.assert_called_once()
self.assertEqual(lease.status, statuses.DELETED)

@mock.patch("esi_leap.resource_objects.test_node.TestNode.set_lease")
@mock.patch("esi_leap.resource_objects.fake_node.FakeNode.set_lease")
@mock.patch("esi_leap.objects.lease.Lease.get")
@mock.patch("esi_leap.objects.lease.Lease.resource_object")
@mock.patch("esi_leap.resource_objects.test_node.TestNode.get_lease_uuid")
@mock.patch("esi_leap.resource_objects.test_node.TestNode.remove_lease")
@mock.patch("esi_leap.resource_objects.fake_node.FakeNode.get_lease_uuid")
@mock.patch("esi_leap.resource_objects.fake_node.FakeNode.remove_lease")
@mock.patch("esi_leap.objects.lease.Lease.save")
@mock.patch("esi_leap.common.notification_utils" "._emit_notification")
def test_expire(
self, mock_notify, mock_save, mock_rl, mock_glu, mock_ro, mock_lg, mock_sl
):
lease = lease_obj.Lease(self.context, **self.test_lease_dict)
test_node = TestNode(uuidutils.generate_uuid(), "12345")
test_node = FakeNode(uuidutils.generate_uuid(), "12345")

mock_ro.return_value = test_node
mock_glu.return_value = lease.uuid
Expand Down Expand Up @@ -555,18 +555,18 @@ def test_expire(
mock_save.assert_called_once()
self.assertEqual(lease.status, statuses.EXPIRED)

@mock.patch("esi_leap.resource_objects.test_node.TestNode.set_lease")
@mock.patch("esi_leap.resource_objects.fake_node.FakeNode.set_lease")
@mock.patch("esi_leap.objects.lease.Lease.get")
@mock.patch("esi_leap.objects.lease.Lease.resource_object")
@mock.patch("esi_leap.resource_objects.test_node.TestNode.get_lease_uuid")
@mock.patch("esi_leap.resource_objects.test_node.TestNode.remove_lease")
@mock.patch("esi_leap.resource_objects.fake_node.FakeNode.get_lease_uuid")
@mock.patch("esi_leap.resource_objects.fake_node.FakeNode.remove_lease")
@mock.patch("esi_leap.objects.lease.Lease.save")
@mock.patch("esi_leap.common.notification_utils" "._emit_notification")
def test_expire_error(
self, mock_notify, mock_save, mock_rl, mock_glu, mock_ro, mock_lg, mock_sl
):
lease = lease_obj.Lease(self.context, **self.test_lease_dict)
test_node = TestNode(uuidutils.generate_uuid(), "12345")
test_node = FakeNode(uuidutils.generate_uuid(), "12345")

mock_ro.return_value = test_node
mock_glu.return_value = lease.uuid
Expand Down Expand Up @@ -604,18 +604,18 @@ def test_expire_error(
mock_save.assert_called_once()
self.assertEqual(lease.status, statuses.WAIT_EXPIRE)

@mock.patch("esi_leap.resource_objects.test_node.TestNode.set_lease")
@mock.patch("esi_leap.resource_objects.fake_node.FakeNode.set_lease")
@mock.patch("esi_leap.objects.lease.Lease.get")
@mock.patch("esi_leap.objects.lease.Lease.resource_object")
@mock.patch("esi_leap.resource_objects.test_node.TestNode.get_lease_uuid")
@mock.patch("esi_leap.resource_objects.test_node.TestNode.remove_lease")
@mock.patch("esi_leap.resource_objects.fake_node.FakeNode.get_lease_uuid")
@mock.patch("esi_leap.resource_objects.fake_node.FakeNode.remove_lease")
@mock.patch("esi_leap.objects.lease.Lease.save")
@mock.patch("esi_leap.common.notification_utils" "._emit_notification")
def test_expire_with_parent(
self, mock_notify, mock_save, mock_rl, mock_glu, mock_ro, mock_lg, mock_sl
):
lease = lease_obj.Lease(self.context, **self.test_lease_parent_lease_dict)
test_node = TestNode(uuidutils.generate_uuid(), "12345")
test_node = FakeNode(uuidutils.generate_uuid(), "12345")

mock_ro.return_value = test_node
mock_glu.return_value = lease.uuid
Expand Down Expand Up @@ -653,13 +653,13 @@ def test_expire_with_parent(
self.assertEqual(lease.status, statuses.EXPIRED)

@mock.patch("esi_leap.objects.lease.Lease.resource_object")
@mock.patch("esi_leap.resource_objects.test_node.TestNode.get_lease_uuid")
@mock.patch("esi_leap.resource_objects.test_node.TestNode.remove_lease")
@mock.patch("esi_leap.resource_objects.fake_node.FakeNode.get_lease_uuid")
@mock.patch("esi_leap.resource_objects.fake_node.FakeNode.remove_lease")
@mock.patch("esi_leap.objects.lease.Lease.save")
@mock.patch("esi_leap.common.notification_utils" "._emit_notification")
def test_expire_no_expire(self, mock_notify, mock_save, mock_rl, mock_glu, mock_ro):
lease = lease_obj.Lease(self.context, **self.test_lease_dict)
test_node = TestNode(uuidutils.generate_uuid(), "12345")
test_node = FakeNode(uuidutils.generate_uuid(), "12345")

mock_ro.return_value = test_node
mock_glu.return_value = "some-other-lease-uuid"
Expand Down Expand Up @@ -863,7 +863,7 @@ def setUp(self):
status="created",
purpose=None,
)
self.node = TestNode(uuidutils.generate_uuid(), "12345")
self.node = FakeNode(uuidutils.generate_uuid(), "12345")

def test_lease_crud_payload(self):
payload = lease_obj.LeaseCRUDPayload(self.lease, self.node)
Expand Down
Loading

0 comments on commit 8db5b55

Please sign in to comment.