def test_rename_view(jenkins_env):
    jk = Jenkins(jenkins_env["url"], (jenkins_env["admin_user"], jenkins_env["admin_token"]))
    original_view_name = "test_rename_view"
    v = jk.create_view(original_view_name, SectionedView)
    try:
        expected_section_name = "MyNewSection"
        v.add_section("hudson.plugins.sectioned_view.TextSection", expected_section_name)

        expected_view_name = "test_rename_view2"
        v.rename(expected_view_name)
        assert jk.find_view(original_view_name) is None
    finally:
        tmp = jk.find_view(original_view_name)
        if tmp:
            tmp.delete()

    with clean_view(v):
        assert v.name == expected_view_name

        tmp_view = jk.find_view(expected_view_name)
        assert tmp_view is not None
        assert tmp_view.name == expected_view_name

        result = tmp_view.sections

        assert result is not None
        assert isinstance(result, list)
        assert len(result) == 1
        assert result[0].name == expected_section_name
Esempio n. 2
0
def test_create_view(jenkins_env):
    jk = Jenkins(jenkins_env["url"],
                 (jenkins_env["admin_user"], jenkins_env["admin_token"]))
    vw = jk.create_view("test_create_view", ListView)
    with clean_view(vw):
        assert vw is not None
        assert vw.name == "test_create_view"
Esempio n. 3
0
def test_get_jobs_no_jobs(jenkins_env):
    jk = Jenkins(jenkins_env["url"], (jenkins_env["admin_user"], jenkins_env["admin_token"]))
    vw = jk.create_view("test_get_jobs_no_jobs_views", ListView)
    with clean_view(vw):
        jobs = vw.jobs
        assert isinstance(jobs, list)
        assert len(jobs) == 0
Esempio n. 4
0
def test_clone_view(jenkins_env):
    jk = Jenkins(jenkins_env["url"],
                 (jenkins_env["admin_user"], jenkins_env["admin_token"]))
    original_view_name = "test_clone_view"
    vw1 = jk.create_view(original_view_name, SectionedView)

    with clean_view(vw1):
        expected_section_name = "MyNewSection"
        vw1.add_section("hudson.plugins.sectioned_view.TextSection",
                        expected_section_name)

        expected_view_name = "test_clone_view2"
        vw2 = vw1.clone(expected_view_name)
        assert vw2 is not None
        with clean_view(vw2):

            tmp_view = jk.find_view(expected_view_name)
            assert tmp_view is not None
            assert tmp_view.name == expected_view_name

            result = tmp_view.sections

            assert result is not None
            assert isinstance(result, list)
            assert len(result) == 1
            assert result[0].name == expected_section_name
Esempio n. 5
0
def test_rename_view(jenkins_env):
    jk = Jenkins(jenkins_env["url"],
                 (jenkins_env["admin_user"], jenkins_env["admin_token"]))
    original_view_name = "test_rename_view"
    v = jk.create_view(original_view_name, SectionedView)
    try:
        expected_section_name = "MyNewSection"
        v.add_section("hudson.plugins.sectioned_view.TextSection",
                      expected_section_name)

        expected_view_name = "test_rename_view2"
        v.rename(expected_view_name)
        assert jk.find_view(original_view_name) is None
    finally:
        tmp = jk.find_view(original_view_name)
        if tmp:
            tmp.delete()

    with clean_view(v):
        assert v.name == expected_view_name

        tmp_view = jk.find_view(expected_view_name)
        assert tmp_view is not None
        assert tmp_view.name == expected_view_name

        result = tmp_view.sections

        assert result is not None
        assert isinstance(result, list)
        assert len(result) == 1
        assert result[0].name == expected_section_name
Esempio n. 6
0
def test_delete_view(jenkins_env):
    jk = Jenkins(jenkins_env["url"],
                 (jenkins_env["admin_user"], jenkins_env["admin_token"]))
    expected_view_name = "test_delete_view"
    vw = jk.create_view(expected_view_name, ListView)
    vw.delete()
    assert jk.find_view(expected_view_name) is None
Esempio n. 7
0
def test_get_name(jenkins_env):
    jk = Jenkins(jenkins_env["url"],
                 (jenkins_env["admin_user"], jenkins_env["admin_token"]))
    expected_name = "test_get_name_view"
    vw = jk.create_view(expected_name, ListView)
    with clean_view(vw):
        assert vw.name == expected_name
Esempio n. 8
0
def test_find_multiple_nested_sub_views(jenkins_env):
    jk = Jenkins(jenkins_env["url"], (jenkins_env["admin_user"], jenkins_env["admin_token"]))
    parent1 = jk.create_view("test_find_multiple_nested_sub_views_parent1", NestedView)
    with clean_view(parent1):
        parent2 = parent1.create_view("test_find_multiple_nested_sub_views_parent2", NestedView)
        with clean_view(parent2):
            expected_view_name = "test_find_multiple_nested_sub_views_child"

            # Views in Jenkins must be unique within the same parent view, but
            # nested views may contain sub-views with the same name as their
            # ancestors / siblings. So we create 2 views with the same name in
            # each of our parent views to make sure they get resolved correctly
            child1 = parent1.create_view(expected_view_name, ListView)
            assert child1 is not None
            with clean_view(child1):
                child2 = parent2.create_view(expected_view_name, ListView)
                assert child2 is not None
                with clean_view(child2):

                    results = parent1.find_all_views(expected_view_name)
                    assert results is not None
                    assert isinstance(results, list)
                    assert len(results) == 2
                    assert results[0].name == expected_view_name
                    assert results[1].name == expected_view_name
def test_list_section_no_regex(jenkins_env):
    jk = Jenkins(jenkins_env["url"], (jenkins_env["admin_user"], jenkins_env["admin_token"]))
    v = jk.create_view("test_list_section_no_regex", SectionedView)
    with clean_view(v):
        v.add_section("hudson.plugins.sectioned_view.ListViewSection", "MyNewSection")

        section = v.sections[0]
        assert section.include_regex == ""
Esempio n. 10
0
def test_get_jobs_no_jobs(jenkins_env):
    jk = Jenkins(jenkins_env["url"],
                 (jenkins_env["admin_user"], jenkins_env["admin_token"]))
    vw = jk.create_view("test_get_jobs_no_jobs_views", ListView)
    with clean_view(vw):
        jobs = vw.jobs
        assert isinstance(jobs, list)
        assert len(jobs) == 0
Esempio n. 11
0
def test_create_parent_nested_view(jenkins_env):
    jk = Jenkins(jenkins_env["url"], (jenkins_env["admin_user"], jenkins_env["admin_token"]))
    expected_view_name = "test_create_parent_nested_view"
    v = jk.create_view(expected_view_name, NestedView)
    assert v is not None
    with clean_view(v):
        assert isinstance(v, NestedView)
        assert v.name == expected_view_name
Esempio n. 12
0
def test_create_status_view(jenkins_env):
    jk = Jenkins(jenkins_env["url"], (jenkins_env["admin_user"], jenkins_env["admin_token"]))
    expected_view_name = "test_create_status_view"
    v = jk.create_view(expected_view_name, StatusView)
    assert v is not None
    with clean_view(v):
        assert isinstance(v, StatusView)
        assert v.name == expected_view_name
Esempio n. 13
0
def test_find_non_existent_view(jenkins_env):
    jk = Jenkins(jenkins_env["url"], (jenkins_env["admin_user"], jenkins_env["admin_token"]))
    parent = jk.create_view("test_find_non_existent_view", NestedView)
    with clean_view(parent):
        result = parent.find_view("FindViewDoesNotExist")
        assert result is not None
        assert isinstance(result, list)
        assert len(result) == 0
Esempio n. 14
0
def test_nested_views_empty(jenkins_env):
    jk = Jenkins(jenkins_env["url"], (jenkins_env["admin_user"], jenkins_env["admin_token"]))
    parent = jk.create_view("test_all_nested_views_empty", NestedView)
    with clean_view(parent):
        result = parent.views
        assert result is not None
        assert isinstance(result, list)
        assert len(result) == 0
Esempio n. 15
0
def test_create_sub_view(jenkins_env):
    jk = Jenkins(jenkins_env["url"], (jenkins_env["admin_user"], jenkins_env["admin_token"]))
    parent = jk.create_view("test_create_sub_view", NestedView)
    with clean_view(parent):
        expected_view_name = "test_create_sub_view1"
        child = parent.create_view(expected_view_name, ListView)
        assert child is not None
        with clean_view(child):
            assert child.name == expected_view_name
def test_get_sections_empty(jenkins_env):
    jk = Jenkins(jenkins_env["url"], (jenkins_env["admin_user"], jenkins_env["admin_token"]))
    expected_view_name = "test_get_sections_empty"
    v = jk.create_view(expected_view_name, SectionedView)
    with clean_view(v):
        result = v.sections

        assert result is not None
        assert isinstance(result, list)
        assert len(result) == 0
Esempio n. 17
0
def test_clone_view(jenkins_env):
    jk = Jenkins(jenkins_env["url"], (jenkins_env["admin_user"], jenkins_env["admin_token"]))
    vw = jk.create_view("test_clone_view1", ListView)
    with clean_view(vw):
        expected_name = "test_clone_view2"
        vw2 = vw.clone(expected_name)
        assert vw2 is not None
        with clean_view(vw2):
            assert vw2.name == expected_name
            assert isinstance(vw2, type(vw))
Esempio n. 18
0
def test_list_section_no_regex(jenkins_env):
    jk = Jenkins(jenkins_env["url"],
                 (jenkins_env["admin_user"], jenkins_env["admin_token"]))
    v = jk.create_view("test_list_section_no_regex", SectionedView)
    with clean_view(v):
        v.add_section("hudson.plugins.sectioned_view.ListViewSection",
                      "MyNewSection")

        section = v.sections[0]
        assert section.include_regex == ""
Esempio n. 19
0
def test_clone_view(jenkins_env):
    jk = Jenkins(jenkins_env["url"],
                 (jenkins_env["admin_user"], jenkins_env["admin_token"]))
    vw = jk.create_view("test_clone_view1", ListView)
    with clean_view(vw):
        expected_name = "test_clone_view2"
        vw2 = vw.clone(expected_name)
        assert vw2 is not None
        with clean_view(vw2):
            assert vw2.name == expected_name
            assert isinstance(vw2, type(vw))
Esempio n. 20
0
def test_get_sections_empty(jenkins_env):
    jk = Jenkins(jenkins_env["url"],
                 (jenkins_env["admin_user"], jenkins_env["admin_token"]))
    expected_view_name = "test_get_sections_empty"
    v = jk.create_view(expected_view_name, SectionedView)
    with clean_view(v):
        result = v.sections

        assert result is not None
        assert isinstance(result, list)
        assert len(result) == 0
Esempio n. 21
0
 def test_create_view(self):
     new_view_url = "http://localhost:8080/view/MyView"
     new_view_name = "MyView"
     new_view_dataio = MagicMock()
     new_view_dataio.get_api_data.return_value = {'name':new_view_name}
     new_view_dataio.config_xml = "<hudson.model.ListView/>"
     self.mock_jenkins_data_io.get_api_data.return_value['views'].append({'url':new_view_url,'name':new_view_name})
     self.clone_map[new_view_url] = new_view_dataio
     j = Jenkins(self.mock_jenkins_data_io)
     v = j.create_view(new_view_name, "ListView")
     
     self.assertEqual(v.name, new_view_name)
Esempio n. 22
0
def test_find_sub_view(jenkins_env):
    jk = Jenkins(jenkins_env["url"], (jenkins_env["admin_user"], jenkins_env["admin_token"]))
    parent = jk.create_view("test_find_sub_view", NestedView)
    with clean_view(parent):
        expected_view_name = "test_find_sub_view1"
        child = parent.create_view(expected_view_name, ListView)
        assert child is not None
        with clean_view(child):
            result = parent.find_view(expected_view_name)
            assert result is not None
            assert isinstance(result, list)
            assert len(result) == 1
            assert result[0].name == child.name
Esempio n. 23
0
def test_get_multiple_views(jenkins_env):
    jk = Jenkins(jenkins_env["url"], (jenkins_env["admin_user"], jenkins_env["admin_token"]))
    test_view_name = "test_get_multiple_views_view"
    vw = jk.create_view(test_view_name, ListView)
    with clean_view(vw):
        v = jk.views

        assert v is not None
        assert isinstance(v, list)
        assert len(v) == 2
        assert v[0].name in ["all", test_view_name]
        assert v[1].name in ["all", test_view_name]
        assert v[0].name != v[1].name
def test_add_text_section(jenkins_env):
    jk = Jenkins(jenkins_env["url"], (jenkins_env["admin_user"], jenkins_env["admin_token"]))
    v = jk.create_view("test_add_text_section", SectionedView)
    with clean_view(v):
        expected_name = "MyNewSection"
        v.add_section("hudson.plugins.sectioned_view.TextSection", expected_name)

        result = v.sections

        assert result is not None
        assert isinstance(result, list)
        assert len(result) == 1
        assert result[0].name == expected_name
Esempio n. 25
0
def test_clone_sub_view(jenkins_env):
    jk = Jenkins(jenkins_env["url"], (jenkins_env["admin_user"], jenkins_env["admin_token"]))
    parent = jk.create_view("test_clone_sub_view_parent", NestedView)
    with clean_view(parent):
        child1 = parent.create_view("test_clone_sub_view_child1", ListView)

        with clean_view(child1):
            expected_view_name = "test_clone_sub_view_child2"
            child2 = child1.clone(expected_view_name)
            assert child2 is not None
            with clean_view(child2):
                assert parent.find_view(expected_view_name)
                assert child2.name == expected_view_name
                assert isinstance(child2, type(child1))
Esempio n. 26
0
def test_get_multiple_views(jenkins_env):
    jk = Jenkins(jenkins_env["url"],
                 (jenkins_env["admin_user"], jenkins_env["admin_token"]))
    test_view_name = "test_get_multiple_views_view"
    vw = jk.create_view(test_view_name, ListView)
    with clean_view(vw):
        v = jk.views

        assert v is not None
        assert isinstance(v, list)
        assert len(v) == 2
        assert v[0].name in ["all", test_view_name]
        assert v[1].name in ["all", test_view_name]
        assert v[0].name != v[1].name
Esempio n. 27
0
def test_add_text_section(jenkins_env):
    jk = Jenkins(jenkins_env["url"],
                 (jenkins_env["admin_user"], jenkins_env["admin_token"]))
    v = jk.create_view("test_add_text_section", SectionedView)
    with clean_view(v):
        expected_name = "MyNewSection"
        v.add_section("hudson.plugins.sectioned_view.TextSection",
                      expected_name)

        result = v.sections

        assert result is not None
        assert isinstance(result, list)
        assert len(result) == 1
        assert result[0].name == expected_name
Esempio n. 28
0
def test_all_views_nested_sub_view(jenkins_env):
    jk = Jenkins(jenkins_env["url"], (jenkins_env["admin_user"], jenkins_env["admin_token"]))
    parent = jk.create_view("test_all_views_nested_sub_view_parent", NestedView)
    with clean_view(parent):
        expected_view_name1 = "test_all_views_nested_sub_view_child1"
        child1 = parent.create_view(expected_view_name1, NestedView)

        with clean_view(child1):
            expected_view_name2 = "test_all_views_nested_sub_view_child2"
            child2 = child1.create_view(expected_view_name2, ListView)
            assert child2 is not None
            with clean_view(child2):
                results = parent.all_views
                assert results is not None
                assert isinstance(results, list)
                assert len(results) == 2
                assert results[0].name in [expected_view_name1, expected_view_name2]
                assert results[1].name in [expected_view_name1, expected_view_name2]
Esempio n. 29
0
def test_rename_view(jenkins_env):
    jk = Jenkins(jenkins_env["url"], (jenkins_env["admin_user"], jenkins_env["admin_token"]))
    original_view_name = "test_rename_view1"
    vw = jk.create_view(original_view_name, ListView)
    try:
        expected_name = "test_rename_view2"
        vw.rename(expected_name)
        assert jk.find_view(original_view_name) is None
    finally:
        tmp = jk.find_view(original_view_name)
        if tmp:
            tmp.delete()

    with clean_view(vw):
        assert vw.name == expected_name

        tmp_view = jk.find_view(expected_name)
        assert tmp_view is not None
        assert tmp_view.name == expected_name
Esempio n. 30
0
def test_rename_view(jenkins_env):
    jk = Jenkins(jenkins_env["url"],
                 (jenkins_env["admin_user"], jenkins_env["admin_token"]))
    original_view_name = "test_rename_view1"
    vw = jk.create_view(original_view_name, ListView)
    try:
        expected_name = "test_rename_view2"
        vw.rename(expected_name)
        assert jk.find_view(original_view_name) is None
    finally:
        tmp = jk.find_view(original_view_name)
        if tmp:
            tmp.delete()

    with clean_view(vw):
        assert vw.name == expected_name

        tmp_view = jk.find_view(expected_name)
        assert tmp_view is not None
        assert tmp_view.name == expected_name
Esempio n. 31
0
def test_rename_view(jenkins_env):
    jk = Jenkins(jenkins_env["url"], (jenkins_env["admin_user"], jenkins_env["admin_token"]))
    parent_view_name = "test_rename_view1"
    parent = jk.create_view(parent_view_name, NestedView)
    with clean_view(parent):
        original_view_name = "test_rename_sub_view_child1"
        vw = parent.create_view(original_view_name, ListView)
        assert vw is not None
        try:
            expected_name = "test_rename_sub_view_child2"
            vw.rename(expected_name)
            assert len(parent.find_view(original_view_name)) == 0
        finally:
            tmp = parent.find_view(original_view_name)
            if tmp:
                tmp[0].delete()

        with clean_view(vw):
            assert vw.name == expected_name

            tmp_view = parent.find_view(expected_name)
            assert len(tmp_view) == 1
            assert tmp_view[0].name == expected_name
def test_clone_view(jenkins_env):
    jk = Jenkins(jenkins_env["url"], (jenkins_env["admin_user"], jenkins_env["admin_token"]))
    original_view_name = "test_clone_view"
    vw1 = jk.create_view(original_view_name, SectionedView)

    with clean_view(vw1):
        expected_section_name = "MyNewSection"
        vw1.add_section("hudson.plugins.sectioned_view.TextSection", expected_section_name)

        expected_view_name = "test_clone_view2"
        vw2 = vw1.clone(expected_view_name)
        assert vw2 is not None
        with clean_view(vw2):

            tmp_view = jk.find_view(expected_view_name)
            assert tmp_view is not None
            assert tmp_view.name == expected_view_name

            result = tmp_view.sections

            assert result is not None
            assert isinstance(result, list)
            assert len(result) == 1
            assert result[0].name == expected_section_name
Esempio n. 33
0
def test_delete_view(jenkins_env):
    jk = Jenkins(jenkins_env["url"], (jenkins_env["admin_user"], jenkins_env["admin_token"]))
    expected_view_name = "test_delete_view"
    vw = jk.create_view(expected_view_name, ListView)
    vw.delete()
    assert jk.find_view(expected_view_name) is None
Esempio n. 34
0
def test_get_name(jenkins_env):
    jk = Jenkins(jenkins_env["url"], (jenkins_env["admin_user"], jenkins_env["admin_token"]))
    expected_name = "test_get_name_view"
    vw = jk.create_view(expected_name, ListView)
    with clean_view(vw):
        assert vw.name == expected_name
Esempio n. 35
0
def test_create_view(jenkins_env):
    jk = Jenkins(jenkins_env["url"], (jenkins_env["admin_user"], jenkins_env["admin_token"]))
    vw = jk.create_view("test_create_view", ListView)
    with clean_view(vw):
        assert vw is not None
        assert vw.name == "test_create_view"