Skip to content

Commit

Permalink
issue #83: changed variable type of value to Resource in Insert eleme…
Browse files Browse the repository at this point in the history
…nt class.
  • Loading branch information
SibrenJacobs committed May 30, 2022
1 parent 668331a commit ccb8ced
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cloudofficeprint/elements/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Any, Union, Iterable, Mapping, Set, FrozenSet, Dict, List
from abc import abstractmethod, ABC
import pandas
from ..resource import Resource, RawResource


class CellStyle(ABC):
Expand Down Expand Up @@ -919,8 +920,8 @@ class Insert(Property):
The documnet can be docx, pptx, xlsx, or pdf documents.
"""

def __init__(self, name: str, value: str):
super().__init__(name, value)
def __init__(self, name: str, value: Resource):
super().__init__(name, value.base64 if isinstance(value, RawResource) else value.data)

@property
def available_tags(self) -> FrozenSet[str]:
Expand Down
21 changes: 21 additions & 0 deletions tests/test_elements.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import cloudofficeprint as cop
import base64


def test_property():
Expand Down Expand Up @@ -297,6 +298,25 @@ def test_freeze_element():
}
assert freezeElement.as_dict == freezeElement_expected

def test_insert():
insertElement1 = cop.elements.Insert(
name='insert_element_name',
value=cop.resource.Base64Resource("dummy base64 data", "docx")
)
insertElement_expected1 = {
'insert_element_name' : "dummy base64 data"
}
assert insertElement1.as_dict == insertElement_expected1

insertElement2 = cop.elements.Insert(
name='insert_element_name',
value=cop.resource.RawResource(bytes("dummy base64 data", "ascii"), "docx")
)
insertElement_expected2 = {
'insert_element_name': "ZHVtbXkgYmFzZTY0IGRhdGE="
}
assert insertElement2.as_dict == insertElement_expected2

def run():
test_property()
test_cell_style_property_docx()
Expand All @@ -311,6 +331,7 @@ def run():
test_text_box()
test_element_collection()
test_freeze_element()
test_insert()
# COP charts get tested in test_charts.py


Expand Down

0 comments on commit ccb8ced

Please sign in to comment.