Example #1
0
 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,
     }
Example #2
0
    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 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")
Example #4
0
    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"])
Example #5
0
class TestPeerEvent:
    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 teardown_method(self, method):
        del self.open_json
        del self.close_json
        del self.data_connection_id
        del self.connect_json
        del self.media_connection_id
        del self.call_json
        del self.error_message
        del self.error_json

    @pytest.fixture(params=[
        "no_event",
        "no_peer_id",
        "no_token",
        "no_data_params",
        "no_call_params",
        "no_error_messages",
    ])
    def context(self, request):
        if request.param == "no_event":
            del self.open_json["event"]
            return self.open_json
        elif request.param == "no_peer_id":
            del self.open_json["params"]["peer_id"]
            return self.open_json
        elif request.param == "no_token":
            del self.open_json["params"]["token"]
            return self.open_json
        elif request.param == "no_data_params":
            del self.connect_json["data_params"]
            return self.connect_json
        elif request.param == "no_call_params":
            del self.call_json["call_params"]
            return self.call_json
        elif request.param == "no_error_messages":
            del self.error_json["error_message"]
            return self.error_json

    def test_peer_event_open_valid(self):
        peer_event = PeerEvent(self.open_json)
        assert peer_event.peer_info() == self.peer_info, "invalid peer_info"
        with pytest.raises(AttributeError):
            peer_event.media_connection_id()
        with pytest.raises(AttributeError):
            peer_event.data_connection_id()
        with pytest.raises(AttributeError):
            peer_event.error_message()

    def test_peer_event_close_valid(self):
        peer_event = PeerEvent(self.close_json)
        assert peer_event.peer_info() == self.peer_info, "invalid peer_info"
        with pytest.raises(AttributeError):
            peer_event.media_connection_id()
        with pytest.raises(AttributeError):
            peer_event.data_connection_id()
        with pytest.raises(AttributeError):
            peer_event.error_message()

    def test_peer_event_connect_valid(self):
        peer_event = PeerEvent(self.connect_json)
        assert peer_event.peer_info() == self.peer_info, "invalid peer_info"
        assert (peer_event.data_connection_id().id() == self.data_connection_id
                ), "invalid data_connection_id"
        with pytest.raises(AttributeError):
            peer_event.media_connection_id()
        with pytest.raises(AttributeError):
            peer_event.error_message()

    def test_peer_event_call_valid(self):
        peer_event = PeerEvent(self.call_json)
        assert peer_event.peer_info() == self.peer_info, "invalid peer_info"
        assert (peer_event.media_connection_id().id() ==
                self.media_connection_id), "invalid media_connection_id"
        with pytest.raises(AttributeError):
            peer_event.data_connection_id()
        with pytest.raises(AttributeError):
            peer_event.error_message()

    def test_peer_event_error_valid(self):
        peer_event = PeerEvent(self.error_json)
        assert peer_event.peer_info() == self.peer_info, "invalid peer_info"
        assert peer_event.error_message(
        ) == self.error_message, "invalid error_message"
        with pytest.raises(AttributeError):
            peer_event.data_connection_id()
        with pytest.raises(AttributeError):
            peer_event.media_connection_id()

    def test_peer_event_invalid_params(self, context):
        with pytest.raises(KeyError):
            _peer_event = PeerEvent(context)
Example #6
0
 def test_create_peer_info_failed(self, peer_id, token):
     with pytest.raises(MyException):
         _peer_info = PeerInfo(peer_id, token)
Example #7
0
 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"