Ejemplo n.º 1
0
def test_should_preload_info(qtbot):
    with requests_mock.Mocker() as m:
        url = 'http://localhost:8080/cc.xml'
        m.get(url, text=fake_content())
        conf = ConfigBuilder().server(url, {
            "excludes/%s" % url: ['cleanup-artifacts-B'],
            "timezone/%s" % url: 'US/Eastern',
        }).build()

        dialog = ServerConfigurationDialog(url, conf)
        dialog.show()
        qtbot.addWidget(dialog)
        qtbot.mouseClick(dialog.ui.loadUrlButton, QtCore.Qt.LeftButton)

        qtbot.waitUntil(lambda: dialog.ui.projectsList.model() is not None)
        model = dialog.ui.projectsList.model()

        assert model.item(0, 0).hasChildren()
        assert model.item(0, 0).child(0, 0).isCheckable()
        assert model.item(0, 0).child(0, 0).text() == "cleanup-artifacts-B"
        assert model.item(0, 0).child(0, 0).data(Qt.CheckStateRole) == Qt.Unchecked

        def timezone():
            assert dialog.ui.timezoneList.count() > 100
            assert dialog.ui.timezoneList.currentText() == 'US/Eastern'

        qtbot.waitUntil(timezone)
Ejemplo n.º 2
0
def test_should_preload_info(qtbot):
    file_path = os.path.realpath(
        os.path.dirname(os.path.abspath(__file__)) +
        "../../../data/cctray.xml")
    url = "file://" + file_path
    conf = ConfigBuilder().server(
        url, {
            "excludes/%s" % url: ['cleanup-artifacts-B'],
            "timezone/%s" % url: 'US/Eastern',
        }).build()

    dialog = ServerConfigurationDialog(url, conf)
    dialog.show()
    qtbot.addWidget(dialog)
    qtbot.mouseClick(dialog.ui.loadUrlButton, QtCore.Qt.LeftButton)

    qtbot.waitUntil(lambda: dialog.ui.projectsList.model() is not None)
    model = dialog.ui.projectsList.model()

    assert model.item(0, 0).hasChildren()
    assert model.item(0, 0).child(0, 0).isCheckable()
    assert model.item(0, 0).child(0, 0).text() == "cleanup-artifacts-B"
    assert model.item(0, 0).child(0, 0).data(Qt.CheckStateRole) == Qt.Unchecked

    def timezone():
        assert dialog.ui.timezoneList.count() > 100
        assert dialog.ui.timezoneList.currentText() == 'US/Eastern'

    qtbot.waitUntil(timezone)
Ejemplo n.º 3
0
def test_should_save_restore_config(qtbot):
    with requests_mock.Mocker() as m:
        url = 'http://localhost:8080/cc.xml'
        m.get(url, text=fake_content())
        conf = ConfigBuilder().server(url).build()
        dialog = ServerConfigurationDialog(url, conf)
        dialog.show()
        qtbot.addWidget(dialog)
        qtbot.mouseClick(dialog.ui.loadUrlButton, QtCore.Qt.LeftButton)

        qtbot.waitUntil(lambda: dialog.ui.projectsList.model() is not None)
        server_config = dialog.get_server_config()

        conf.save_server_config(server_config)
        dialog = ServerConfigurationDialog(url, conf)
        dialog.show()
        qtbot.addWidget(dialog)
def test_should_return_notifications(mocker):
    old_projects = [
        ProjectBuilder({
            'name': 'proj1',
            'lastBuildStatus': 'Success',
            'activity': 'Sleeping',
            'url': 'someurl',
            'lastBuildLabel': '1',
            'lastBuildTime': '2009-05-29T13:54:07'
        }).build(),
        ProjectBuilder({
            'name': 'Successbuild',
            'lastBuildStatus': 'Failure',
            'activity': 'Sleeping',
            'url': 'someurl',
            'lastBuildLabel': '10',
            'lastBuildTime': '2009-05-29T13:54:37'
        }).build()
    ]
    new_projects = [
        ProjectBuilder({
            'name': 'proj1',
            'lastBuildStatus': 'Failure',
            'activity': 'Sleeping',
            'url': 'someurl',
            'lastBuildLabel': '2',
            'lastBuildTime': '2009-05-29T13:54:07'
        }).build(),
        ProjectBuilder({
            'name': 'Successbuild',
            'lastBuildStatus': 'Success',
            'activity': 'Sleeping',
            'url': 'someurl',
            'lastBuildLabel': '11',
            'lastBuildTime': '2009-05-29T13:54:47'
        }).build()
    ]
    old = OverallIntegrationStatus(
        [ContinuousIntegrationServer('url', old_projects)])
    new = OverallIntegrationStatus(
        [ContinuousIntegrationServer('url', new_projects)])

    class NotificationFake(object):
        def __init__(self):
            pass

        def show_message(self, **kwargs):
            print kwargs

    m = mocker.patch.object(NotificationFake, 'show_message')

    notification = ProjectStatusNotification(ConfigBuilder().build(), old, new,
                                             NotificationFake())
    notification.show_notifications()

    m.assert_any_call('Broken builds', 'proj1')
    m.assert_any_call('Fixed builds', 'Successbuild')
Ejemplo n.º 5
0
def test_should_show_configured_urls(qtbot):
    file_path = os.path.realpath(
        os.path.dirname(os.path.abspath(__file__)) +
        "../../../data/cctray.xml")
    conf = ConfigBuilder().server("file://" + file_path).build()
    dialog = PreferencesDialog(conf)
    qtbot.addWidget(dialog)
    assert [str(s) for s in dialog.ui.cctrayPathList.model().stringList()
            ] == ["file://" + file_path]
Ejemplo n.º 6
0
def test_should_return_preferences_on_accept(qtbot):
    conf = ConfigBuilder().build()
    dialog = PreferencesDialog(conf)
    qtbot.addWidget(dialog)

    def close_dialog():
        button = dialog.ui.buttonBox.button(QDialogButtonBox.Ok)
        qtbot.mouseClick(button, QtCore.Qt.LeftButton)

    QtCore.QTimer.singleShot(100, close_dialog)
    preferences = dialog.open()

    qtbot.waitUntil(lambda: preferences is not None)
Ejemplo n.º 7
0
def test_should_fail_for_bad_url(qtbot, mocker):
    url = "file:///badpath"
    conf = ConfigBuilder().server(url).build()
    dialog = ServerConfigurationDialog(url, conf)
    dialog.show()
    qtbot.addWidget(dialog)
    m = mocker.patch.object(QMessageBox, 'critical',
                            return_value=QMessageBox.No)

    qtbot.mouseClick(dialog.ui.loadUrlButton, QtCore.Qt.LeftButton)

    def alert_shown():
        m.assert_called_once_with(dialog, ANY, ANY)

    qtbot.wait_until(alert_shown)
Ejemplo n.º 8
0
def test_should_update_tooltip_on_poll(qtbot):
    conf = ConfigBuilder().build()
    widget = AppUi(QtWidgets.QWidget(), conf, BuildIcons())
    qtbot.addWidget(widget)
    project1 = ProjectBuilder({
        'name': 'a',
        'lastBuildStatus': 'Success',
        'activity': 'Sleeping',
        'lastBuildTime': '2016-09-17 11:31:12'
    }).build()
    servers = [ContinuousIntegrationServer('someurl', [project1])]

    widget.update_projects(OverallIntegrationStatus(servers))

    assert re.compile("Last checked: \d{4}-\d\d-\d\d \d\d:\d\d:\d\d").match(
        str(widget.tray.toolTip())) is not None
Ejemplo n.º 9
0
def test_should_show_configure_notifications(qtbot):
    file_path = os.path.realpath(
        os.path.dirname(os.path.abspath(__file__)) +
        "../../../data/cctray.xml")
    conf = ConfigBuilder().server("file://" + file_path).build()
    dialog = PreferencesDialog(conf)
    qtbot.addWidget(dialog)
    dialog.show()
    dialog.ui.tabWidget.setCurrentIndex(1)
    assert dialog.ui.connectivityIssuesCheckbox.isChecked()
    assert dialog.ui.fixedBuildsCheckbox.isChecked()
    assert dialog.ui.brokenBuildsCheckbox.isChecked()
    assert not dialog.ui.successfulBuildsCheckbox.isChecked()
    assert not dialog.ui.scriptCheckbox.isChecked()
    assert dialog.ui.scriptLineEdit.text(
    ) == 'echo #status# #projects# >> /tmp/buildnotify.log'
Ejemplo n.º 10
0
def test_should_exclude_projects(qtbot):
    with requests_mock.Mocker() as m:
        url = 'http://localhost:8080/cc.xml'
        m.get(url, text=fake_content())
        conf = ConfigBuilder().server(url).build()
        dialog = ServerConfigurationDialog(url, conf)
        dialog.show()
        qtbot.addWidget(dialog)
        qtbot.mouseClick(dialog.ui.loadUrlButton, QtCore.Qt.LeftButton)

        qtbot.waitUntil(lambda: dialog.ui.projectsList.model() is not None)
        model = dialog.ui.projectsList.model()

        model.item(0, 0).child(0, 0).setCheckState(QtCore.Qt.Unchecked)

        server_config = dialog.get_server_config()
        assert [str(s) for s in server_config.excluded_projects] == ['cleanup-artifacts-B']
Ejemplo n.º 11
0
def test_should_disable_authentication_if_keystore_is_unavailable(qtbot, mocker):
    m = mocker.patch.object(Keystore, 'isAvailable',
                            return_value=False)
    with requests_mock.Mocker() as r:
        url = 'http://localhost:8080/cc.xml'
        r.get(url, text=fake_content())

        conf = ConfigBuilder().server(url).build()
        dialog = ServerConfigurationDialog(url, conf)
        dialog.show()
        qtbot.addWidget(dialog)

        def alert_shown():
            assert not dialog.ui.username.isEnabled()
            assert not dialog.ui.password.isEnabled()
            assert dialog.ui.authenticationSettings.title() == 'Authentication (keyring dependency missing)'

        qtbot.wait_until(alert_shown)
Ejemplo n.º 12
0
def test_should_show_configured_urls(qtbot):
    with requests_mock.Mocker() as m:
        url = 'http://localhost:8080/cc.xml'
        m.get(url, text=fake_content())
        conf = ConfigBuilder().server(url).build()
        dialog = ServerConfigurationDialog(url, conf)
        dialog.show()
        qtbot.addWidget(dialog)
        qtbot.mouseClick(dialog.ui.loadUrlButton, QtCore.Qt.LeftButton)

        qtbot.waitUntil(lambda: dialog.ui.projectsList.model() is not None)
        model = dialog.ui.projectsList.model()
        assert model.item(0, 0).hasChildren()
        assert model.item(0, 0).child(0, 0).isCheckable()
        assert model.item(0, 0).child(0, 0).data(Qt.CheckStateRole) == Qt.Checked
        assert model.item(0, 0).child(0, 0).text() == "cleanup-artifacts-B"

        assert dialog.ui.timezoneList.currentText() == 'None'
Ejemplo n.º 13
0
def test_should_show_configured_urls(qtbot):
    file_path = os.path.realpath(
        os.path.dirname(os.path.abspath(__file__)) +
        "../../../data/cctray.xml")
    url = "file://" + file_path
    conf = ConfigBuilder().server(url).build()
    dialog = ServerConfigurationDialog(url, conf)
    dialog.show()
    qtbot.addWidget(dialog)
    qtbot.mouseClick(dialog.ui.loadUrlButton, QtCore.Qt.LeftButton)

    qtbot.waitUntil(lambda: dialog.ui.projectsList.model() is not None)
    model = dialog.ui.projectsList.model()
    assert model.item(0, 0).hasChildren()
    assert model.item(0, 0).child(0, 0).isCheckable()
    assert model.item(0, 0).child(0, 0).data(Qt.CheckStateRole) == Qt.Checked
    assert model.item(0, 0).child(0, 0).text() == "cleanup-artifacts-B"

    assert dialog.ui.timezoneList.currentText() == 'None'
Ejemplo n.º 14
0
def test_should_exclude_projects(qtbot):
    file_path = os.path.realpath(
        os.path.dirname(os.path.abspath(__file__)) +
        "../../../data/cctray.xml")
    url = "file://" + file_path
    conf = ConfigBuilder().server(url).build()
    dialog = ServerConfigurationDialog(url, conf)
    dialog.show()
    qtbot.addWidget(dialog)
    qtbot.mouseClick(dialog.ui.loadUrlButton, QtCore.Qt.LeftButton)

    qtbot.waitUntil(lambda: dialog.ui.projectsList.model() is not None)
    model = dialog.ui.projectsList.model()

    model.item(0, 0).child(0, 0).setCheckState(QtCore.Qt.Unchecked)

    server_config = dialog.get_server_config()
    assert [str(s) for s in server_config.excluded_projects
            ] == ['cleanup-artifacts-B']
Ejemplo n.º 15
0
def test_should_remove_configured_servers(qtbot):
    file_path = os.path.realpath(
        os.path.dirname(os.path.abspath(__file__)) +
        "../../../data/cctray.xml")
    conf = ConfigBuilder().server("file://" + file_path).build()
    dialog = PreferencesDialog(conf)
    qtbot.addWidget(dialog)
    dialog.show()

    index = dialog.ui.cctrayPathList.model().index(0, 0)
    dialog.ui.cctrayPathList.selectionModel().select(
        index, QItemSelectionModel.Select)
    dialog.ui.cctrayPathList.setCurrentIndex(index)
    dialog.item_selection_changed(True)

    qtbot.mouseClick(dialog.ui.removeButton, Qt.LeftButton)

    assert [str(s)
            for s in dialog.ui.cctrayPathList.model().stringList()] == []
Ejemplo n.º 16
0
def test_should_disable_authentication_if_keystore_is_unavailable(
        qtbot, mocker):
    file_path = os.path.realpath(
        os.path.dirname(os.path.abspath(__file__)) +
        "../../../data/cctray.xml")
    m = mocker.patch.object(Keystore, 'isAvailable', return_value=False)

    url = "file://" + file_path
    conf = ConfigBuilder().server(url).build()
    dialog = ServerConfigurationDialog(url, conf)
    dialog.show()
    qtbot.addWidget(dialog)

    def alert_shown():
        assert not dialog.ui.username.isEnabled()
        assert not dialog.ui.password.isEnabled()
        assert dialog.ui.authenticationSettings.title(
        ) == 'Authentication (keyring dependency missing)'

    qtbot.wait_until(alert_shown)
Ejemplo n.º 17
0
def test_should_prefill_server_config(qtbot, mocker):
    file_path = os.path.realpath(
        os.path.dirname(os.path.abspath(__file__)) +
        "../../../data/cctray.xml")
    conf = ConfigBuilder().server("file://" + file_path).build()
    dialog = PreferencesDialog(conf)
    qtbot.addWidget(dialog)
    dialog.show()

    index = dialog.ui.cctrayPathList.model().index(0, 0)
    dialog.ui.cctrayPathList.selectionModel().select(
        index, QItemSelectionModel.Select)
    dialog.ui.cctrayPathList.setCurrentIndex(index)
    dialog.item_selection_changed(True)

    m = mocker.patch.object(ServerConfigurationDialog, 'open')

    qtbot.mouseClick(dialog.ui.configureProjectButton, Qt.LeftButton)

    qtbot.waitUntil(lambda: m.assert_any_call())
Ejemplo n.º 18
0
def test_should_consolidate_build_status(qtbot):
    keyring.set_keyring(FakeKeyring())
    parent = QWidget()
    file_path = os.path.realpath(
        os.path.dirname(os.path.abspath(__file__)) +
        "../../../data/cctray.xml")
    conf = ConfigBuilder().server("file://" + file_path).build()
    b = BuildNotify(parent, conf, 10)
    qtbot.addWidget(b.app)
    parent.show()

    qtbot.waitUntil(lambda: hasattr(b, 'app_ui'))

    def projects_loaded():
        assert len([str(a.text())
                    for a in b.app_ui.app_menu.menu.actions()]) == 11

    if QSystemTrayIcon.isSystemTrayAvailable():
        qtbot.waitUntil(lambda: re.compile("Last checked.*").match(
            b.app_ui.tray.toolTip()) is not None,
                        timeout=5000)
        qtbot.waitUntil(projects_loaded)
Ejemplo n.º 19
0
def test_should_consolidate_build_status(qtbot):
    with requests_mock.Mocker() as m:
        url = 'http://localhost:8080/cc.xml'
        m.get(url, text=fake_content())
        keyring.set_keyring(FakeKeyring())
        parent = QWidget()
        conf = ConfigBuilder().server(url).build()
        b = BuildNotify(parent, conf, 10)
        qtbot.addWidget(b.app)
        parent.show()

        qtbot.waitUntil(lambda: hasattr(b, 'app_ui'))

        def projects_loaded():
            assert len([
                str(a.text()) for a in b.app_ui.app_menu.menu.actions()
            ]) == 11

        if QSystemTrayIcon.isSystemTrayAvailable():
            qtbot.waitUntil(lambda: re.compile("Last checked.*").match(
                b.app_ui.tray.toolTip()) is not None,
                            timeout=5000)
            qtbot.waitUntil(projects_loaded)
Ejemplo n.º 20
0
def test_should_fetch_projects(qtbot):
    conf = ConfigBuilder().build()
    populator = ProjectsPopulator(conf)
    with qtbot.waitSignal(populator.updated_projects, timeout=1000):
        populator.process()