def test_FormGenerator(_):
    """Test same UNTLElement subclasses are grouped together.

    Official and series titles should be in same group. A hidden
    group should be created if it doesn't exist.
    """
    creator = us.Creator(qualifier='')
    official_title = us.Title(content='A Title', qualifier='officialtitle')
    series_title = us.Title(content='Series', qualifier='seriestitle')
    children = [official_title, series_title, creator]
    form_elements = us.FormGenerator(children=children,
                                     sort_order=['title', 'creator', 'hidden'])
    # Check there is a title group with both official and series elements
    # a group for the creator, and a separate hidden group was created.
    assert len(form_elements.element_groups) == 3
    title_group = form_elements.element_groups[0].group_list
    assert len(title_group) == 2
    for title in title_group:
        assert isinstance(title, us.Title)
    creator_group = form_elements.element_groups[1].group_list
    assert len(creator_group) == 1
    assert isinstance(creator_group[0], us.Creator)
    hidden_group = form_elements.element_groups[2].group_list
    assert len(hidden_group) == 1
    assert isinstance(hidden_group[0], us.Meta)
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_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_fails_without_vocab_service(mock_get_vocabularies):
    """If vocabularies URL can't be reached, the form elements will raise an exception."""
    with pytest.raises(us.UNTLStructureException):
        us.FormGenerator(children=[],
                         sort_order=[])
    mock_get_vocabularies.assert_called_once()
def test_FormGenerator_get_vocabularies(mock_get_vocabularies):
    """Tests the get_vocabularies method just uses the get_vocabularies function."""
    us.FormGenerator(children=[], sort_order=['hidden'])
    mock_get_vocabularies.assert_called_once()