def __init__(self, json): # type: (dict) -> None self.__event = json["event"] if self.__event == "OPEN": self.__peer_info = PeerInfo(json["params"]["peer_id"], json["params"]["token"]) elif self.__event == "CLOSE": self.__peer_info = PeerInfo(json["params"]["peer_id"], json["params"]["token"]) elif self.__event == "CALL": self.__peer_info = PeerInfo(json["params"]["peer_id"], json["params"]["token"]) self.__media_connection_id = MediaConnectionId( json["call_params"]["media_connection_id"]) elif self.__event == "CONNECTION": self.__peer_info = PeerInfo(json["params"]["peer_id"], json["params"]["token"]) self.__data_connection_id = DataConnectionId( json["data_params"]["data_connection_id"]) elif self.__event == "ERROR": self.__peer_info = PeerInfo(json["params"]["peer_id"], json["params"]["token"]) self.__error_message = json["error_message"] else: raise MyException("This json is not an peer event")
def setup_method(self, method): self.peer_info = PeerInfo(u"hoge", u"pt-870c2c49-c16d-4c69-b1ad-fec7550564af") self.open_json = {"event": "OPEN", "params": self.peer_info.json()} self.close_json = {"event": "CLOSE", "params": self.peer_info.json()} self.data_connection_id = u"dc-102127d9-30de-413b-93f7-41a33e39d82b" self.connect_json = { "event": "CONNECTION", "params": self.peer_info.json(), "data_params": { "data_connection_id": self.data_connection_id }, } self.media_connection_id = u"mc-102127d9-30de-413b-93f7-41a33e39d82b" self.call_json = { "event": "CALL", "params": self.peer_info.json(), "call_params": { "media_connection_id": self.media_connection_id }, } self.error_message = u"BROWSER_INCOMPATIBLE" self.error_json = { "event": "ERROR", "params": self.peer_info.json(), "error_message": self.error_message, }
def test_feed_peer_api(self): Factory.set_domain(self.url) create_request = Factory.feed_peer_api(CreateRequest) assert create_request.run({ "key": "KEY_FOO", "domain": "example.com", "peer_id": "ID_FOO", "turn": True, }) == PeerInfo("ID_FOO", "pt-9749250e-d157-4f80-9ee2-359ce8524308")
def create_request(self, param): """ Send a PeerObject create request http://35.200.46.204/#/1.peers/peer :param CreateRequestParams params: Parameters for creating a PeerObject :return: Information to identify the object :rtype: PeerInfo """ try: response = self.__rest.post("peers", param.json(), 201) except json.JSONDecodeError as e: raise MyException(e.msg) return PeerInfo(response["params"]["peer_id"], response["params"]["token"])
def test_create_peer_info_failed(self, peer_id, token): with pytest.raises(MyException): _peer_info = PeerInfo(peer_id, token)
def test_create_success(self, peer_id, token): peer_info = PeerInfo(peer_id, token) assert peer_info.id() == u"my_id", "peer_id is not correct" assert (peer_info.token() == u"pt-102127d9-30de-413b-93f7-41a33e39d82b" ), "token is not correct"