예제 #1
0
    def create_from_exception(cls, log_type, url, exception, start, classifier=None, channel=None):
        if classifier is not None:
            org = classifier.org

        if channel is not None:
            org = channel.org

        data = bytearray()
        prefixes = dump.PrefixSettings(cls.REQUEST_DELIM, cls.RESPONSE_DELIM)
        dump._dump_request_data(exception.request, prefixes, data)

        data = data.decode("utf-8")
        request_lines = data.split(cls.REQUEST_DELIM)
        request = "".join(request_lines)

        return HTTPLog.objects.create(
            channel=channel,
            classifier=classifier,
            log_type=HTTPLog.WHATSAPP_TEMPLATES_SYNCED,
            url=url,
            request=request,
            response="",
            is_error=True,
            created_on=timezone.now(),
            request_time=(timezone.now() - start).total_seconds() * 1000,
            org=org,
        )
예제 #2
0
    def create_from_exception(cls,
                              log_type,
                              url,
                              exception,
                              start,
                              classifier=None,
                              channel=None,
                              ticketer=None):
        org = (classifier or channel or ticketer).org

        data = bytearray()
        prefixes = dump.PrefixSettings(cls.REQUEST_DELIM, cls.RESPONSE_DELIM)
        dump._dump_request_data(exception.request, prefixes, data)

        data = data.decode("utf-8")
        request_lines = data.split(cls.REQUEST_DELIM)
        request = "".join(request_lines)

        return cls.objects.create(
            org=org,
            log_type=log_type,
            url=url,
            request=request,
            response="",
            is_error=True,
            created_on=timezone.now(),
            request_time=(timezone.now() - start).total_seconds() * 1000,
            channel=channel,
            classifier=classifier,
            ticketer=ticketer,
        )
예제 #3
0
    def test_dump_non_string_request_data(self):
        """Build up the request data into a bytearray."""
        self.configure_request(url='http://example.com/',
                               method='POST',
                               body=1)

        array = bytearray()
        prefixes = dump.PrefixSettings('request:', 'response:')
        dump._dump_request_data(
            request=self.request,
            prefixes=prefixes,
            bytearr=array,
            proxy_info={},
        )
        assert b'request:POST / HTTP/1.1\r\n' in array
        assert b'request:Host: example.com\r\n' in array
        assert b'<< Request body is not a string-like type >>\r\n' in array
예제 #4
0
    def test_dump_request_data(self):
        """Build up the request data into a bytearray."""
        self.configure_request(
            url='http://example.com/',
            method='GET',
        )

        array = bytearray()
        prefixes = dump.PrefixSettings('request:', 'response:')
        dump._dump_request_data(
            request=self.request,
            prefixes=prefixes,
            bytearr=array,
            proxy_info={},
        )

        assert b'request:GET / HTTP/1.1\r\n' in array
        assert b'request:Host: example.com\r\n' in array
예제 #5
0
파일: test_dump.py 프로젝트: Eveler/dmsic
    def test_dump_request_data(self):
        """Build up the request data into a bytearray."""
        self.configure_request(
            url='http://example.com/',
            method='GET',
        )

        array = bytearray()
        prefixes = dump.PrefixSettings('request:', 'response:')
        dump._dump_request_data(
            request=self.request,
            prefixes=prefixes,
            bytearr=array,
            proxy_info={},
        )

        assert b'request:GET / HTTP/1.1\r\n' in array
        assert b'request:Host: example.com\r\n' in array
예제 #6
0
    def test_dump_non_string_request_data(self):
        """Build up the request data into a bytearray."""
        self.configure_request(
            url='http://example.com/',
            method='POST',
            body=1
        )

        array = bytearray()
        prefixes = dump.PrefixSettings('request:', 'response:')
        dump._dump_request_data(
            request=self.request,
            prefixes=prefixes,
            bytearr=array,
            proxy_info={},
        )
        assert b'request:POST / HTTP/1.1\r\n' in array
        assert b'request:Host: example.com\r\n' in array
        assert b'<< Request body is not a string-like type >>\r\n' in array
예제 #7
0
    def test_dump_request_data_with_proxy_info(self):
        """Build up the request data into a bytearray."""
        self.configure_request(
            url='http://example.com/',
            method='GET',
        )

        array = bytearray()
        prefixes = dump.PrefixSettings('request:', 'response:')
        dump._dump_request_data(
            request=self.request,
            prefixes=prefixes,
            bytearr=array,
            proxy_info={
                'request_path': b'fake-request-path',
                'method': b'CONNECT',
            },
        )

        assert b'request:CONNECT fake-request-path HTTP/1.1\r\n' in array
        assert b'request:Host: example.com\r\n' in array
예제 #8
0
파일: test_dump.py 프로젝트: Eveler/dmsic
    def test_dump_request_data_with_proxy_info(self):
        """Build up the request data into a bytearray."""
        self.configure_request(
            url='http://example.com/',
            method='GET',
        )

        array = bytearray()
        prefixes = dump.PrefixSettings('request:', 'response:')
        dump._dump_request_data(
            request=self.request,
            prefixes=prefixes,
            bytearr=array,
            proxy_info={
                'request_path': b'fake-request-path',
                'method': b'CONNECT',
            },
        )

        assert b'request:CONNECT fake-request-path HTTP/1.1\r\n' in array
        assert b'request:Host: example.com\r\n' in array