Commit 397cf6c2 authored by Nico Alt's avatar Nico Alt

Add unit tests for Briar's Application

parent 09eafd1c
Pipeline #3690 passed with stage
in 3 minutes and 4 seconds
......@@ -7,4 +7,5 @@ pycodestyle>=2.5.0
pylint>=2.3.1
pytest>=4.6.2
pytest-cov>=2.7.1
pytest-mock>=1.11.0
requests_mock>=1.6.0
......@@ -18,7 +18,7 @@ from briar.gtk.window import Window
class Application(Gtk.Application):
def __init__(self):
Application._set_application_name()
Application._set_application_name(APPLICATION_NAME)
super().__init__(application_id=APPLICATION_ID)
# pylint: disable=arguments-differ
......@@ -38,9 +38,9 @@ class Application(Gtk.Application):
Gio.Application.quit(self)
@staticmethod
def _set_application_name():
GLib.set_application_name(APPLICATION_NAME)
GLib.set_prgname(APPLICATION_NAME)
def _set_application_name(name):
GLib.set_application_name(name)
GLib.set_prgname(name)
@staticmethod
def _setup_styling():
......
# Copyright (c) 2019 Nico Alt
# SPDX-License-Identifier: AGPL-3.0-only
# License-Filename: LICENSE.md
import gi
import briar
from briar.api.api import Api
from briar.gtk.application import Application
from briar.gtk.define import APPLICATION_NAME, BRIAR_HEADLESS_JAR
from briar.gtk.window import Window
def test_do_startup(mocker):
do_startup_mock = mocker.patch("gi.repository.Gtk.Application.do_startup")
_setup_styling_mock = mocker.patch(
"briar.gtk.application.Application._setup_styling")
_setup_api_mock = mocker.patch(
"briar.gtk.application.Application._setup_api")
Application().do_startup()
do_startup_mock.assert_called_once()
_setup_styling_mock.assert_called_once()
_setup_api_mock.assert_called_once()
def test_do_activate(mocker):
_setup_window_mock = mocker.patch(
"briar.gtk.application.Application._setup_window")
Application().do_activate()
_setup_window_mock.assert_called_once()
def test_quit(mocker):
api_mock = mocker.patch("briar.api.api.Api")
api_stop_mock = mocker.patch("briar.api.api.Api.stop")
window_mock = mocker.patch("briar.gtk.window.Window")
window_hide_mock = mocker.patch("briar.gtk.window.Window.hide")
quit_mock = mocker.patch("gi.repository.Gio.Application.quit")
application = Application()
application.api = api_mock
application.window = window_mock
application.quit()
api_stop_mock.assert_called_once()
window_hide_mock.assert_called_once()
quit_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)
# TODO: How to assert that Api got initialized?
def disabled_test_setup_api(mocker):
api_mock = mocker.patch("briar.api.api.Api")
application = Application()
application._setup_api()
api_mock.assert_called_once_with(BRIAR_HEADLESS_JAR)
assert application.api == api_mock
# TODO: How to mock Window?
def disabled_test_setup_window(mocker):
window_mock = mocker.patch("briar.gtk.window.Window")
window_show_mock = mocker.patch("briar.gtk.window.Window.show")
Application()._setup_window()
window_show_mock.assert_called_once()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment