1
1
from typing import NoReturn
2
2
from grpc import RpcError , StatusCode
3
3
from collections .abc import Sequence , Mapping
4
+ from grpc import ServicerContext
4
5
5
6
MetadataType = Sequence [tuple [str , str ]]
6
7
7
8
8
- class FakeServicerContext :
9
+ class FakeServicerContext ( ServicerContext ) :
9
10
"""
10
11
Implementation of basic RpcContext methods that stores data
11
12
for validation in tests
@@ -50,4 +51,71 @@ def set_invocation_metadata(self, items: MetadataType) -> None:
50
51
"""
51
52
Helper to emulate request metadata
52
53
"""
53
- self ._invocation_metadata = items
54
+ self ._invocation_metadata = items
55
+
56
+ def set_code (self , code : StatusCode ) -> None :
57
+ self .abort_status = code
58
+
59
+ def set_details (self , details : str ) -> None :
60
+ """Sets the value to be used as detail string upon RPC completion.
61
+
62
+ This method need not be called by method implementations if they have
63
+ no details to transmit.
64
+
65
+ Args:
66
+ details: A UTF-8-encodable string to be sent to the client upon
67
+ termination of the RPC.
68
+ """
69
+ self .abort_message = details
70
+
71
+ def code (self ) -> StatusCode :
72
+ """Accesses the value to be used as status code upon RPC completion.
73
+
74
+ Returns:
75
+ The StatusCode value for the RPC.
76
+ """
77
+ return self .abort_status
78
+
79
+ def details (self ) -> str :
80
+ """Accesses the value to be used as detail string upon RPC completion.
81
+
82
+ Returns:
83
+ The details string of the RPC.
84
+ """
85
+ return self .abort_message
86
+
87
+ def peer (self ):
88
+ raise NotImplementedError ()
89
+
90
+ def peer_identities (self ):
91
+ raise NotImplementedError ()
92
+
93
+ def peer_identity_key (self ):
94
+ raise NotImplementedError ()
95
+
96
+ def auth_context (self ):
97
+ raise NotImplementedError ()
98
+
99
+ def set_compression (self , compression ):
100
+ raise NotImplementedError ()
101
+
102
+ def send_initial_metadata (self , initial_metadata ):
103
+ raise NotImplementedError ()
104
+
105
+ def abort_with_status (self , status ):
106
+ raise NotImplementedError ()
107
+
108
+ def disable_next_message_compression (self ):
109
+ raise NotImplementedError ()
110
+
111
+ def is_active (self ):
112
+ raise NotImplementedError ()
113
+
114
+ def time_remaining (self ):
115
+ raise NotImplementedError ()
116
+
117
+ def cancel (self ):
118
+ raise NotImplementedError ()
119
+
120
+ def add_callback (self , callback ):
121
+ raise NotImplementedError ()
0 commit comments