Пример #1
0
def test_data_type_builder_doc_bad():
    a = DocumentProto()
    a.id = 'a236cbb0eda62d58'
    with pytest.raises(BadDocType):
        _new_doc_from_data(b'BREAKIT!' + a.SerializeToString(), DataInputType.DOCUMENT)

    with pytest.raises(BadDocType):
        _new_doc_from_data(MessageToJson(a) + '�', DataInputType.DOCUMENT)
Пример #2
0
def new_doc_id(doc: 'DocumentProto') -> str:
    """ Generate a new hexdigest based on the content of the document.

    .. note::
        Always use it AFTER you fill in the content of the document

    :param doc: a non-empty document
    :return: the hexdigest based on :meth:`blake2b`
    """
    d = doc
    if _doc_field_mask:
        d = DocumentProto()
        _doc_field_mask.MergeMessage(doc, d)
    return blake2b(d.SerializeToString(), digest_size=_digest_size).hexdigest()
Пример #3
0
def test_data_type_builder_doc_bad():
    a = DocumentProto()
    a.id = 'a236cbb0eda62d58'
    with pytest.raises(BadDocType):
        _build_doc(b'BREAKIT!' + a.SerializeToString(),
                   DataInputType.DOCUMENT,
                   override_doc_id=False)

    with pytest.raises(BadDocType):
        _build_doc(MessageToJson(a) + '🍔',
                   DataInputType.DOCUMENT,
                   override_doc_id=False)

    with pytest.raises(BadDocType):
        _build_doc({'🍔': '🍔'}, DataInputType.DOCUMENT, override_doc_id=False)