Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_identifies_simple_fields_correctly(self):
document = Document(docx_path('outdated_docproperty_with_umlauts.docx'))
properties = CustomProperties(document).find_docprops_in_document()
assert 1 == len(properties), \
'input should contain 1 simple field docproperty'
prop = properties[0]
assert u'F\xfc\xfc' == prop.name
assert isinstance(prop, SimpleField)
def _find_docprops_in(self, element, name=None):
# First we search for the simple fields:
sfield_nodes = xpath(
element,
u'.//w:fldSimple[contains(@w:instr, \'DOCPROPERTY \')]')
docprops = [SimpleField(sfield_node) for sfield_node in sfield_nodes]
# Now for the complex fields
cfield_nodes = xpath(
element,
u'.//w:instrText[contains(.,\'DOCPROPERTY \')]')
docprops.extend([ComplexField(cfield_node) for cfield_node in cfield_nodes])
if name is not None:
docprops = filter(lambda prop: prop.name == name, docprops)
return docprops