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: class MoveNodesRequest:
session_id: int session_id: int
node_id: int node_id: int
source: str = None source: str = field(compare=False, default=None)
position: Position = None position: Position = field(compare=False, default=None)
geo: Geo = None geo: Geo = field(compare=False, default=None)
def to_proto(self) -> core_pb2.MoveNodesRequest: def to_proto(self) -> core_pb2.MoveNodesRequest:
position = self.position.to_proto() if self.position else None position = self.position.to_proto() if self.position else None
@ -1213,15 +1213,3 @@ class MoveNodesRequest:
position=position, position=position,
geo=geo, 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 import pytest
from mock import patch 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.client import CoreGrpcClient, InterfaceHelper, MoveNodesStreamer
from core.api.grpc.server import CoreGrpcServer from core.api.grpc.server import CoreGrpcServer
from core.api.grpc.wrappers import ( from core.api.grpc.wrappers import (
@ -22,6 +22,7 @@ from core.api.grpc.wrappers import (
Link, Link,
LinkOptions, LinkOptions,
MobilityAction, MobilityAction,
MoveNodesRequest,
Node, Node,
NodeServiceData, NodeServiceData,
NodeType, NodeType,
@ -918,7 +919,7 @@ class TestGrpc:
client = CoreGrpcClient() client = CoreGrpcClient()
session = grpc_server.coreemu.create_session() session = grpc_server.coreemu.create_session()
streamer = MoveNodesStreamer(session.id) streamer = MoveNodesStreamer(session.id)
request = core_pb2.MoveNodesRequest() request = MoveNodesRequest(session.id + 1, 1)
streamer.send(request) streamer.send(request)
streamer.stop() streamer.stop()