Exemple #1
0
def test_add_empty_fields_allows_content_and_qualifier_has_children(
        mock_getattr):
    untl_dict = untldoc.add_empty_fields({})

    # In practice we don't have a case where the element has a content
    # value, qualifier, and children (though the code allows it), as the
    # children are represented in the dict as the content value and would
    # overwrite an initial content value.
    # Pretend Subject element contains a child to trigger the targeted code.

    def side_effect(*args, **kwargs):
        if args[0].tag == 'subject' and args[1] == 'contained_children':
            return ['fake child']
        else:
            return getattr(*args, **kwargs)

    mock_getattr.side_effect = side_effect
    untl_dict = untldoc.add_empty_fields({})
    assert untl_dict['subject'] == [{
        'content': {
            'fake child': ''
        },
        'qualifier': ''
    }]
Exemple #2
0
def test_add_empty_fields_raise_PyuntlException(mock_title):
    with pytest.raises(untldoc.PyuntlException) as err:
        untldoc.add_empty_fields({})
    assert 'Could not add empty element field.' == err.value.args[0]
Exemple #3
0
 def testAddEmptyFields(self):
     """Test adding the empty fields."""
     fixed = add_empty_fields(BAD_UNTL_DICT.copy())
     for x in UNTL_XML_ORDER:
         self.assertTrue(x in fixed, '%s not in %s' % (x, fixed))
Exemple #4
0
def test_add_empty_fields():
    """Check empty fields are added if not supplied in the dictionary."""
    untl_dict = deepcopy(UNTL_DICTIONARY)
    untl_dict = untldoc.add_empty_fields(untl_dict)
    assert untl_dict == {
        'title': [{
            'qualifier': 'officialtitle',
            'content': 'Tres Actos'
        }],
        'creator': [{
            'qualifier': 'aut',
            'content': {
                'name': 'Last, Furston, 1807-1865.',
                'type': 'per'
            }
        }],
        'publisher': [{
            'content': {
                'name': 'Fake Publishing'
            }
        }],
        'collection': [{
            'content': 'UNT'
        }],
        'date': [{
            'content': '1944',
            'qualifier': 'creation'
        }],
        'contributor': [{
            'content': {
                'info': '',
                'type': '',
                'name': ''
            }
        }],
        'language': [{
            'content': ''
        }],
        'description': [{
            'content': '',
            'qualifier': ''
        }],
        'subject': [{
            'content': '',
            'qualifier': ''
        }],
        'primarySource': [{
            'content': ''
        }],
        'coverage': [{
            'content': '',
            'qualifier': ''
        }],
        'source': [{
            'content': '',
            'qualifier': ''
        }],
        'citation': [{
            'content': '',
            'qualifier': ''
        }],
        'relation': [{
            'content': '',
            'qualifier': ''
        }],
        'institution': [{
            'content': ''
        }],
        'rights': [{
            'content': '',
            'qualifier': ''
        }],
        'resourceType': [{
            'content': ''
        }],
        'format': [{
            'content': ''
        }],
        'identifier': [{
            'content': '',
            'qualifier': ''
        }],
        'degree': [{
            'content': '',
            'qualifier': ''
        }],
        'note': [{
            'content': '',
            'qualifier': ''
        }],
        'meta': [{
            'content': '',
            'qualifier': ''
        }]
    }
Exemple #5
0
 def testAddEmptyFields(self):
     """Test adding the empty fields."""
     fixed = add_empty_fields(BAD_UNTL_DICT.copy())
     for x in UNTL_XML_ORDER:
         self.assertTrue(x in fixed, '%s not in %s' % (x, fixed))