• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

uwefladrich / scriptengine-tasks-ecearth / 14519603486

17 Apr 2025 03:46PM UTC coverage: 96.774% (-0.4%) from 97.128%
14519603486

Pull #95

github

valentinaschueller
Update documentation for Gitlab task
Pull Request #95: Gitlab presentation task

127 of 139 new or added lines in 2 files covered. (91.37%)

2190 of 2263 relevant lines covered (96.77%)

0.97 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.11
/tests/test_gitlab.py
1
"""Tests for monitoring/gitlab.py"""
2

3
from unittest.mock import Mock, patch
1✔
4

5
import gitlab
1✔
6
import jinja2.exceptions
1✔
7
import pytest
1✔
8
import scriptengine.exceptions
1✔
9

10
from monitoring.gitlab import Gitlab, create_anchor
1✔
11

12

13
def test_gitlab_presentation_list(tmp_path):
1✔
14
    init = {
1✔
15
        "src": str(tmp_path),
16
        "local_dst": str(tmp_path),
17
        "template": str(tmp_path / "gitlab.txt.j2"),
18
        "subject": "Test Issue",
19
        "api_key": "Invalid Key",
20
    }
21
    redmine_task = Gitlab(init)
1✔
22
    test_sources = ["path.txt", {"path": "path.txt"}, "path.yml"]
1✔
23
    with patch.object(redmine_task, "log_warning") as mock:
1✔
24
        result = redmine_task.get_presentation_list(test_sources, str(tmp_path))
1✔
25
    mock.assert_called_with("Can not present diagnostic: File not found: path.yml")
1✔
26
    assert result == []
1✔
27

28

29
def test_gitlab_connection_error(tmp_path):
1✔
30
    init = {
1✔
31
        "src": str(tmp_path),
32
        "local_dst": str(tmp_path),
33
        "template": str(tmp_path / "gitlab.txt.j2"),
34
        "subject": "Test Issue",
35
        "api_key": "Invalid Key",
36
    }
37
    gitlab_task = Gitlab(init)
1✔
38
    gitlab_instance = gitlab.Gitlab(
1✔
39
        "https://www.invalid.url", private_token=init["api_key"]
40
    )
41
    pytest.raises(
1✔
42
        scriptengine.exceptions.ScriptEngineTaskRunError,
43
        gitlab_task.get_project_and_issue,
44
        gitlab_instance,
45
        init["subject"],
46
    )
47

48

49
def test_gitlab_auth_error(tmp_path):
1✔
50
    init = {
1✔
51
        "src": str(tmp_path),
52
        "local_dst": str(tmp_path),
53
        "template": str(tmp_path / "gitlab.txt.j2"),
54
        "subject": "Test Issue",
55
        "api_key": "Invalid Key",
56
    }
57
    gitlab_task = Gitlab(init)
1✔
58
    gitlab_instance = gitlab.Gitlab(
1✔
59
        "https://gitlab.lrz.de/", private_token=init["api_key"]
60
    )
61
    pytest.raises(
1✔
62
        scriptengine.exceptions.ScriptEngineTaskRunError,
63
        gitlab_task.get_project_and_issue,
64
        gitlab_instance,
65
        init["subject"],
66
    )
67

68

69
def test_gitlab_get_template(tmp_path):
1✔
70
    init = {
1✔
71
        "src": str(tmp_path),
72
        "local_dst": str(tmp_path),
73
        "template": str(tmp_path / "gitlab.txt.j2"),
74
        "subject": "Test Issue",
75
        "api_key": "Invalid Key",
76
    }
77
    gitlab_task = Gitlab(init)
1✔
78
    with pytest.raises(jinja2.exceptions.TemplateNotFound):
1✔
79
        gitlab_task.get_template(init, init["template"])
1✔
80

81

82
class MockTemplateOrIssue:
1✔
83
    def __init__(self):
1✔
84
        self.globals = {}
1✔
85
        self.web_url = ""
1✔
86

87
    def render(self, **kwargs):
1✔
88
        return str(kwargs)
1✔
89

90
    def save(self):
1✔
91
        return None
1✔
92

93
    def upload(self, file_name, filepath=""):
1✔
NEW
94
        return f"![{file_name}]({filepath})"
×
95

96

97
def test_gitlab_run(tmp_path):
1✔
98
    init = {
1✔
99
        "src": str(tmp_path),
100
        "local_dst": str(tmp_path),
101
        "template": str(tmp_path / "redmine.txt.j2"),
102
        "subject": "Test Issue",
103
        "api_key": "Invalid Key",
104
    }
105
    gitlab_task = Gitlab(init)
1✔
106
    gitlab_task.get_presentation_list = Mock(return_value=[])
1✔
107
    mock_object = MockTemplateOrIssue()
1✔
108
    gitlab_task.get_template = Mock(return_value=mock_object)
1✔
109
    gitlab_task.get_project_and_issue = Mock(return_value=(mock_object, mock_object))
1✔
110
    with patch.object(gitlab_task, "log_debug") as mock:
1✔
111
        gitlab_task.run(init)
1✔
112
    mock.assert_called_with("Saving issue.")
1✔
113

114

115
def test_create_anchor():
1✔
116
    test_string = "Precipitation - Evaporation (Annual Mean Climatology)"
1✔
117
    gitlab_anchor = "precipitation-evaporation-annual-mean-climatology"
1✔
118
    assert create_anchor(test_string) == gitlab_anchor
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc