Exemplo n.º 1
0
def test_request_set_content(mock_request_params):
    rqst = Request(**mock_request_params)
    assert rqst.content == mock_request_params['content']
    assert rqst.content_type == 'application/json'
    assert rqst._pack_content() is rqst.content

    mock_request_params['content'] = 'hello'
    mock_request_params['content_type'] = None
    rqst = Request(**mock_request_params)
    assert rqst.content == b'hello'
    assert rqst.content_type == 'text/plain'
    assert rqst._pack_content() is rqst.content

    mock_request_params['content'] = b'\x00\x01\xfe\xff'
    mock_request_params['content_type'] = None
    rqst = Request(**mock_request_params)
    assert rqst.content == b'\x00\x01\xfe\xff'
    assert rqst.content_type == 'application/octet-stream'
    assert rqst._pack_content() is rqst.content
Exemplo n.º 2
0
    def test_request_set_content(self, mock_request_params):
        rqst = Request(**mock_request_params)
        assert rqst.content == mock_request_params['content']
        assert rqst.content_type == 'application/json'
        assert rqst._pack_content() is rqst.content

        mock_request_params['content'] = 'hello'
        mock_request_params['content_type'] = None
        rqst = Request(**mock_request_params)
        assert rqst.content == b'hello'
        assert rqst.content_type == 'text/plain'
        assert rqst._pack_content() is rqst.content

        mock_request_params['content'] = b'\x00\x01\xfe\xff'
        mock_request_params['content_type'] = None
        rqst = Request(**mock_request_params)
        assert rqst.content == b'\x00\x01\xfe\xff'
        assert rqst.content_type == 'application/octet-stream'
        assert rqst._pack_content() is rqst.content
Exemplo n.º 3
0
def test_request_attach_files(mock_request_params):
    files = [
        AttachedFile('test1.txt', io.BytesIO(), 'application/octet-stream'),
        AttachedFile('test2.txt', io.BytesIO(), 'application/octet-stream'),
    ]

    mock_request_params['content'] = b'something'
    rqst = Request(**mock_request_params)
    with pytest.raises(AssertionError):
        rqst.attach_files(files)

    mock_request_params['content'] = b''
    rqst = Request(**mock_request_params)
    rqst.attach_files(files)

    assert rqst.content_type == 'multipart/form-data'
    assert rqst.content == b''
    packed_content = rqst._pack_content()
    assert packed_content.is_multipart
Exemplo n.º 4
0
    def test_request_attach_files(self, mock_request_params):
        files = [
            AttachedFile('test1.txt', io.BytesIO(), 'application/octet-stream'),
            AttachedFile('test2.txt', io.BytesIO(), 'application/octet-stream'),
        ]

        mock_request_params['content'] = b'something'
        rqst = Request(**mock_request_params)
        with pytest.raises(AssertionError):
            rqst.attach_files(files)

        mock_request_params['content'] = b''
        rqst = Request(**mock_request_params)
        rqst.attach_files(files)

        assert rqst.content_type == 'multipart/form-data'
        assert rqst.content == b''
        packed_content = rqst._pack_content()
        assert packed_content.is_multipart
Exemplo n.º 5
0
def test_request_set_content_none(mock_request_params):
    mock_request_params = mock_request_params.copy()
    mock_request_params['content'] = None
    rqst = Request(**mock_request_params)
    assert rqst.content == b''
    assert rqst._pack_content() is rqst.content
Exemplo n.º 6
0
 def test_request_set_content_none(self, mock_request_params):
     mock_request_params = mock_request_params.copy()
     mock_request_params['content'] = None
     rqst = Request(**mock_request_params)
     assert rqst.content == b''
     assert rqst._pack_content() is rqst.content