daemon/test: improved MoveNodesRequest to be hashable using dataclass itself, fixed grpc test not properly using a wrapped MoveNodesRequest object

This commit is contained in:
Blake Harnden 2022-04-28 23:20:17 -07:00
parent aa8ea40ce6
commit 2ab2c27d49
2 changed files with 7 additions and 18 deletions

View file

@ -1195,13 +1195,13 @@ class EmanePathlossesRequest:
)
@dataclass
@dataclass(frozen=True)
class MoveNodesRequest:
session_id: int
node_id: int
source: str = None
position: Position = None
geo: Geo = None
source: str = field(compare=False, default=None)
position: Position = field(compare=False, default=None)
geo: Geo = field(compare=False, default=None)
def to_proto(self) -> core_pb2.MoveNodesRequest:
position = self.position.to_proto() if self.position else None
@ -1213,15 +1213,3 @@ class MoveNodesRequest:
position=position,
geo=geo,
)
def __members(self) -> Tuple[int, int]:
return self.session_id, self.node_id
def __eq__(self, other: "MoveNodesRequest") -> bool:
if type(other) is type(self):
return self.__members() == other.__members()
else:
return False
def __hash__(self):
return hash(self.__members())

View file

@ -8,7 +8,7 @@ import grpc
import pytest
from mock import patch
from core.api.grpc import core_pb2, wrappers
from core.api.grpc import wrappers
from core.api.grpc.client import CoreGrpcClient, InterfaceHelper, MoveNodesStreamer
from core.api.grpc.server import CoreGrpcServer
from core.api.grpc.wrappers import (
@ -22,6 +22,7 @@ from core.api.grpc.wrappers import (
Link,
LinkOptions,
MobilityAction,
MoveNodesRequest,
Node,
NodeServiceData,
NodeType,
@ -918,7 +919,7 @@ class TestGrpc:
client = CoreGrpcClient()
session = grpc_server.coreemu.create_session()
streamer = MoveNodesStreamer(session.id)
request = core_pb2.MoveNodesRequest()
request = MoveNodesRequest(session.id + 1, 1)
streamer.send(request)
streamer.stop()