aboutsummaryrefslogtreecommitdiff
path: root/tests/images_tests.py
blob: cf2e28449f1da3b6f8faafe22851da3bc35fba73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import io

from hamcrest import assert_that, contains, has_properties
from nose.tools import istest

import mammoth


@istest
def inline_is_available_as_alias_of_img_element():
    assert mammoth.images.inline is mammoth.images.img_element


@istest
def data_uri_encodes_images_in_base64():
    image_bytes = b"abc"
    image = mammoth.documents.Image(
        alt_text=None,
        content_type="image/jpeg",
        open=lambda: io.BytesIO(image_bytes),
    )
    
    result = mammoth.images.data_uri(image)
    
    assert_that(result, contains(
        has_properties(attributes={"src": "data:image/jpeg;base64,YWJj"}),
    ))