Skip to content
Snippets Groups Projects
Commit 07bab620 authored by Nico's avatar Nico
Browse files

Re-enable pytest in GitLab CI

parent 1c32121f
No related branches found
No related tags found
1 merge request!35Re-enable tests on GitLab CI; delete tests of private methods
Pipeline #4415 passed
......@@ -2,10 +2,11 @@
# SPDX-License-Identifier: AGPL-3.0-only
# License-Filename: LICENSE.md
image: debian:buster
image: debian:buster-backports
before_script:
- apt update && apt install --no-install-recommends -y gir1.2-gtk-3.0 python3-gi python3-pip python3-setuptools
- apt install --no-install-recommends -y -t buster-backports libhandy-0.0-dev
- pip3 install -r requirements-dev.txt
stages:
......@@ -23,4 +24,3 @@ pytest:
stage: test
coverage: '/TOTAL.*\s+(\d+%)$/'
script: tools/tests/test-pytest.sh
when: manual
......@@ -37,7 +37,7 @@ def test_do_activate(mocker):
_setup_window_mock.assert_called_once()
def test_quit(mocker):
def test_do_shutdown(mocker):
api_mock = mocker.patch("briar_wrapper.api.Api")
api_stop_mock = mocker.patch("briar_wrapper.api.Api.stop")
window_mock = mocker.patch("briar_gtk.window.Window")
......@@ -54,95 +54,3 @@ def test_quit(mocker):
api_stop_mock.assert_called_once()
window_hide_mock.assert_called_once()
do_shutdown_mock.assert_called_once()
def test_set_application_name(mocker):
set_application_name_mock = mocker.patch(
"gi.repository.GLib.set_application_name")
set_prgname_mock = mocker.patch("gi.repository.GLib.set_prgname")
name_mock = "Mock"
Application._set_application_name(name_mock)
set_application_name_mock.assert_called_once_with(name_mock)
set_prgname_mock.assert_called_once_with(name_mock)
def test_set_application_name_implicit(mocker):
set_application_name_mock = mocker.patch(
"gi.repository.GLib.set_application_name")
set_prgname_mock = mocker.patch("gi.repository.GLib.set_prgname")
Application()
set_application_name_mock.assert_called_once_with(APPLICATION_NAME)
set_prgname_mock.assert_called_once_with(APPLICATION_NAME)
def test_setup_styling(mocker):
new_for_uri_mock = mocker.patch("gi.repository.Gio.File.new_for_uri")
load_from_file_mock = mocker.patch(
"gi.repository.Gtk.CssProvider.load_from_file")
get_default_mock = mocker.patch("gi.repository.Gdk.Screen.get_default")
add_provider_for_screen_mock = mocker.patch(
"gi.repository.Gtk.StyleContext.add_provider_for_screen")
Application._setup_styling(APPLICATION_STYLING_PATH)
new_for_uri_mock.assert_called_with(APPLICATION_STYLING_PATH)
load_from_file_mock.assert_called_once()
get_default_mock.assert_called_once()
add_provider_for_screen_mock.assert_called_once()
def test_setup_api(mocker):
application = Application()
assert not hasattr(application, "api")
application._setup_api()
assert isinstance(application.api, Api)
assert application.api._command == ["java", "-jar", BRIAR_HEADLESS_JAR]
def test_setup_window(mocker):
mocker.patch("briar_gtk.window.Window.__init__").return_value = None
window_show_mock = mocker.patch("briar_gtk.window.Window.show")
window_present_mock = mocker.patch("briar_gtk.window.Window.present")
Application()._setup_window()
window_show_mock.assert_called_once()
window_present_mock.assert_called_once()
def test_setup_window_has_attribute(mocker):
mocker.patch("briar_gtk.window.Window.__init__").return_value = None
window_mock = Mock()
application = Application()
application.window = window_mock
application._setup_window()
window_mock.show.assert_not_called()
window_mock.present.assert_called_once()
def test_setup_window_has_none_attribute(mocker):
mocker.patch("briar_gtk.window.Window.__init__").return_value = None
window_show_mock = mocker.patch("briar_gtk.window.Window.show")
window_present_mock = mocker.patch("briar_gtk.window.Window.present")
application = Application()
application._setup_window()
window_show_mock.assert_called_once()
window_present_mock.assert_called_once()
@pytest.fixture(autouse=True)
def glib_set_application_name(mocker):
mocker.patch("gi.repository.GLib.set_application_name")
# Copyright (c) 2019 Nico Alt
# SPDX-License-Identifier: AGPL-3.0-only
# License-Filename: LICENSE.md
from random import choice
from string import ascii_letters, digits
from unittest import mock
import pytest
# pylint: disable=redefined-outer-name
@pytest.fixture
def api(auth_token):
api = mock.Mock()
api.auth_token = auth_token
return api
@pytest.fixture
def auth_token():
return ''.join(choice(ascii_letters + digits) for i in range(33))
@pytest.fixture
def request_headers(auth_token):
request_headers = {
"Authorization": 'Bearer %s' % auth_token
}
return request_headers
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment