Updated gitlab module to have state of warning when there is at least 1 notification, just like the github module
This commit is contained in:
parent
1dd39a4e43
commit
a6de61b751
2 changed files with 46 additions and 9 deletions
|
@ -1,13 +1,12 @@
|
|||
import pytest
|
||||
from unittest import TestCase, mock
|
||||
|
||||
import pytest
|
||||
from requests import Session
|
||||
|
||||
import core.config
|
||||
import core.widget
|
||||
import modules.contrib.gitlab
|
||||
|
||||
from requests import Session
|
||||
from requests.models import Response
|
||||
|
||||
pytest.importorskip("requests")
|
||||
|
||||
|
||||
|
@ -15,6 +14,7 @@ def build_gitlab_module(actions=""):
|
|||
config = core.config.Config(["-p", "gitlab.actions={}".format(actions)])
|
||||
return modules.contrib.gitlab.Module(config=config, theme=None)
|
||||
|
||||
|
||||
def mock_todo_api_response():
|
||||
res = mock.Mock()
|
||||
res.json = lambda: [
|
||||
|
@ -25,6 +25,7 @@ def mock_todo_api_response():
|
|||
res.status_code = 200
|
||||
return res
|
||||
|
||||
|
||||
class TestGitlabUnit(TestCase):
|
||||
def test_load_module(self):
|
||||
__import__("modules.contrib.gitlab")
|
||||
|
@ -40,3 +41,30 @@ class TestGitlabUnit(TestCase):
|
|||
module = build_gitlab_module(actions="approval_required")
|
||||
module.update()
|
||||
assert module.widgets()[0].full_text() == "1"
|
||||
|
||||
@mock.patch.object(Session, "get", return_value=mock_todo_api_response())
|
||||
def test_state_warning(self, _):
|
||||
module = build_gitlab_module(actions="approval_required")
|
||||
module.update()
|
||||
|
||||
assert module.state(None) == ["warning"]
|
||||
|
||||
@mock.patch.object(Session, "get", return_value=mock_todo_api_response())
|
||||
def test_state_normal(self, _):
|
||||
module = build_gitlab_module(actions="empty_filter")
|
||||
module.update()
|
||||
|
||||
assert module.state(None) == []
|
||||
|
||||
@mock.patch.object(Session, "get", return_value=mock_todo_api_response())
|
||||
def test_state_normal_before_update(self, _):
|
||||
module = build_gitlab_module(actions="approval_required")
|
||||
|
||||
assert module.state(None) == []
|
||||
|
||||
@mock.patch.object(Session, "get", side_effect=Exception("Something went wrong"))
|
||||
def test_state_normal_if_na(self, _):
|
||||
module = build_gitlab_module(actions="approval_required")
|
||||
module.update()
|
||||
|
||||
assert module.state(None) == []
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue