Exemple #1
0
def test_untl_to_hash_dict(meaningful_meta, expected_hash_dict):
    title = us.Title(qualifier='serialtitle', content='The Bronco')
    meta_modifier = us.Meta(qualifier='metadataModifier', content='Daniel')
    meta_modification = us.Meta(qualifier='metadataModificationDate',
                                content='2007-09-20, 13:46:15')
    meta_object = us.Meta(qualifier='objectType', content='simple')
    elements = us.Metadata()
    elements.add_child(title)
    elements.add_child(meta_modification)
    elements.add_child(meta_modifier)
    elements.add_child(meta_object)
    hash_dict = untldoc.untl_to_hash_dict(elements, meaningful_meta)
    assert hash_dict == expected_hash_dict
def test_FormGenerator_hidden_is_alone(_):
    """Test Meta with Hidden qualifier is handled.

     A Meta element with qualifier of "hidden" gets a separate group
     from other Meta elements.
    """
    system = us.Meta(content='DC', qualifier='system')
    hidden = us.Meta(content='True', qualifier='hidden')
    children = [system, hidden]
    form_elements = us.FormGenerator(children=children,
                                     sort_order=['meta', 'hidden'])
    assert len(form_elements.element_groups) == 2
    assert isinstance(form_elements.element_groups[0], FormGroup)
    assert isinstance(form_elements.element_groups[1], HiddenGroup)
    assert not form_elements.adjustable_items
def test_FormGenerator_adjustable_items(_):
    """FormGroup types with data for adjusting form with JS are handled."""
    access = us.Rights(content='public', qualifier='access')
    hidden = us.Meta(content='True', qualifier='hidden')
    children = [access, hidden]
    sort_order = ['rights', 'hidden']
    fg = us.FormGenerator(children=children,
                          sort_order=sort_order)
    assert 'access' in fg.adjustable_items
def test_Metadata_is_hidden_with_no_meta_hidden_element(capsys):
    metadata = us.Metadata()
    metadata.children = [us.Meta(content='DC', qualifier='system')]
    assert metadata.is_hidden is False
    captured = capsys.readouterr()
    assert captured.err == 'A hidden meta element does not exist.'

@patch('pyuntl.untl_structure.get_vocabularies', return_value=VOCAB)
def test_generate_form_data(_):
    """Test this returns a FormGenerator object."""
    metadata = us.Metadata()
    assert not metadata.children
    fg = metadata.generate_form_data(sort_order=UNTL_PTH_ORDER)
    assert isinstance(fg, us.FormGenerator)
    # Check missing children were added.
    assert len(metadata.children) == len(metadata.contained_children)


@pytest.mark.parametrize('test_input_content, test_output',
                         [
                             ([us.Meta(content='DC', qualifier='system'),
                               us.Meta(content='True', qualifier='hidden')],
                              True),
                             ([us.Meta(content='DC', qualifier='system'),
                               us.Meta(content='False', qualifier='hidden')],
                              False),
                         ])
def test_Metadata_is_hidden(test_input_content, test_output):
    """Check if a UNTL element is hidden."""
    metadata = us.Metadata()
    metadata.children = test_input_content
    assert metadata.is_hidden is test_output


def test_Metadata_is_hidden_with_no_meta_hidden_element(capsys):
    metadata = us.Metadata()