Browse Source

Merge pull request 'Fix Blob.data accessor for binary data, esp. bull-bytes' (#5) from htgoebel/pEpPythonAdapter:fix-PYADPT-116 into Release_2.1

Reviewed-on: https://gitea.pep.foundation/pEp.foundation/pEpPythonAdapter/pulls/5
Release_2.1
heck 5 months ago
parent
commit
41a0f49281
2 changed files with 22 additions and 11 deletions
  1. +2
    -1
      src/pEp/_pEp/message.cc
  2. +20
    -10
      tests/test_blob.py

+ 2
- 1
src/pEp/_pEp/message.cc View File

@ -95,7 +95,8 @@ namespace pEp {
}
object Message::Blob::data() {
return object(handle<>(PyBytes_FromString(_bl->value)));
return object(handle<>(PyBytes_FromStringAndSize(_bl->value,
_bl->size)));
}
void Message::Blob::data(object data) {


+ 20
- 10
tests/test_blob.py View File

@ -4,18 +4,28 @@
"""Blob unit tests."""
import pytest
from . import constants
from . import model
def test_blob_data_constructor(pEp, model):
bdata = bytes('this is test data', 'utf-8')
def test_blob_data_constructor(pEp):
bdata = b'this is binary \x00\x01\xbb\xa7\xa4\xab test data'
b = pEp.Blob(bdata)
assert(b.data == bdata)
assert b.data == bdata
assert not b.mime_type
assert not b.filename
def test_blob_data_property(pEp, model):
def test_blob_data_property(pEp):
bdata = b'this is binary \x00\x01\xbb\xa7\xa4\xab test data'
b = pEp.Blob(b'dummy')
bdata = bytes('this is test data', 'utf-8')
b.data = bdata
assert(b.data == bdata)
assert b.data == bdata
assert not b.mime_type
assert not b.filename
def test_blob_data_property_keeps_other_fields(pEp):
bdata = b'this is binary \x00\x01\xbb\xa7\xa4\xab test data'
b = pEp.Blob(b'dummy', 'application/x-mydata', 'myfile.dat')
b.data = bdata
assert b.data == bdata
assert b.mime_type == 'application/x-mydata'
assert b.filename == 'myfile.dat'

Loading…
Cancel
Save