Beispiel #1
0
    def event_callback(self, event):
        """Callback called when an event is received from ARI"""
        for event_description in self.config:
            match = event_description["match"]
            nomatch = event_description.get("nomatch", None)
            if not all_match(match, event):
                continue

            # Now validate the nomatch, if it's there
            if nomatch and all_match(nomatch, event):
                continue
            event_description["event_count"] += 1
            self.triggered_callback(self, self.test_object.ari, event)
Beispiel #2
0
    def event_callback(self, event):
        """Callback called when an event is received from ARI"""
        for event_description in self.config:
            match = event_description["match"]
            nomatch = event_description.get("nomatch", None)
            if not all_match(match, event):
                continue

            # Now validate the nomatch, if it's there
            if nomatch and all_match(nomatch, event):
                continue
            event_description["event_count"] += 1
            self.triggered_callback(self, self.test_object.ari, event)
Beispiel #3
0
    def matches(self, message):
        """Compares a message against the configured conditions.

        :param message: Incoming ARI WebSocket event.
        :returns: True if message matches conditions; False otherwise.
        """
        match = self.conditions.get('match')
        res = all_match(match, message)

        # Now validate the nomatch, if it's there
        nomatch = self.conditions.get('nomatch')
        if res and nomatch:
            res = not all_match(nomatch, message)
        return res
Beispiel #4
0
    def matches(self, message):
        """Compares a message against the configured conditions.

        :param message: Incoming ARI WebSocket event.
        :returns: True if message matches conditions; False otherwise.
        """
        match = self.conditions.get('match')
        res = all_match(match, message)

        # Now validate the nomatch, if it's there
        nomatch = self.conditions.get('nomatch')
        if res and nomatch:
            res = not all_match(nomatch, message)
        return res
Beispiel #5
0
    def send(self, values):
        """Send this ARI request substituting the given values"""
        uri = var_replace(self.uri, values)
        url = self.ari.build_url(uri)
        requests_method = getattr(requests, self.method)
        params = dict((key, var_replace(val, values))
                      for key, val in self.params.iteritems())

        response = requests_method(url,
                                   params=params,
                                   data=self.body,
                                   headers=self.headers,
                                   auth=self.ari.userpass)

        if self.response_body:
            match = self.response_body.get('match')
            return all_match(match, response.json())

        if self.expect:
            if response.status_code != self.expect:
                LOGGER.error('sent %s %s %s expected %s response %d %s',
                             self.method, self.uri, self.params, self.expect,
                             response.status_code, response.text)
                return False
        else:
            if response.status_code / 100 != 2:
                LOGGER.error('sent %s %s %s response %d %s', self.method,
                             self.uri, self.params, response.status_code,
                             response.text)
                return False

        LOGGER.info('sent %s %s %s response %d %s', self.method, self.uri,
                    self.params, response.status_code, response.text)
        return response
    def verify_rtcp_packet(self, payload, expected):
        """Verify an RTCP packet

        Keyword Arguments:
        payload  The actual payload
        expected The expected values
        """
        return all_match(expected, json.loads(payload))
    def verify_rtcp_packet(self, payload, expected):
        """Verify an RTCP packet

        Keyword Arguments:
        payload  The actual payload
        expected The expected values
        """
        return all_match(expected, json.loads(payload))
Beispiel #8
0
    def send(self, values):
        """Send this ARI request substituting the given values"""
        uri = var_replace(self.uri, values)
        url = self.ari.build_url(uri)
        requests_method = getattr(requests, self.method)
        params = dict((key, var_replace(val, values))
                      for key, val in self.params.iteritems())

        response = requests_method(
            url,
            params=params,
            data=self.body,
            headers=self.headers,
            auth=self.ari.userpass)

        if self.response_body:
            match = self.response_body.get('match')
            return all_match(match, response.json())

        if self.expect:
            if response.status_code != self.expect:
                LOGGER.error('sent %s %s %s expected %s response %d %s',
                             self.method, self.uri, self.params, self.expect,
                             response.status_code, response.text)
                return False
        else:
            if response.status_code / 100 != 2:
                LOGGER.error('sent %s %s %s response %d %s',
                             self.method, self.uri, self.params,
                             response.status_code, response.text)
                return False

        LOGGER.info('sent %s %s %s response %d %s',
                    self.method, self.uri, self.params,
                    response.status_code, response.text)
        return response