Skip to content

Commit 090ed9a

Browse files
committed
test: application statistics
1 parent c01eb90 commit 090ed9a

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed

docs/gl_objects/statistics.rst

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
##########
2+
Statistics
3+
##########
4+
5+
Reference
6+
---------
7+
8+
* v4 API:
9+
10+
+ :class:`gitlab.v4.objects.ApplicationStatistics`
11+
+ :class:`gitlab.v4.objects.ApplicationStatisticsManager`
12+
+ :attr:`gitlab.Gitlab.statistics`
13+
14+
* GitLab API: https://docs.gitlab.com/ee/api/statistics.html
15+
16+
Examples
17+
--------
18+
19+
Get the statistics::
20+
21+
statistics = gl.statistics.get()
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""
2+
GitLab API: https://docs.gitlab.com/ee/api/statistics.html
3+
"""
4+
5+
6+
def test_get_statistics(gl, resp_application_statistics):
7+
gl.projects.create({"name": "admin_project"})
8+
gl.users.create(
9+
{
10+
"email": "user@test.com",
11+
"username": "user",
12+
"name": "user",
13+
"password": "user_pass",
14+
}
15+
)
16+
gl.groups.create({"name": "gitlab-test-group1", "path": "gitlab-test-group1"})
17+
gl.snippets.create(
18+
{"title": "snippet1", "file_name": "snippet1.py", "content": "import gitlab"}
19+
)
20+
21+
statistics = gl.statistics.get()
22+
assert statistics.snippets == 1
23+
assert statistics.users == 1
24+
assert statistics.groups == 1
25+
assert statistics.projects == 1

tests/unit/objects/test_statistics.py

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
"""
2+
GitLab API: https://docs.gitlab.com/ee/api/statistics.html
3+
"""
4+
5+
import pytest
6+
import responses
7+
8+
content = {
9+
"forks": "10",
10+
"issues": "76",
11+
"merge_requests": "27",
12+
"notes": "954",
13+
"snippets": "50",
14+
"ssh_keys": "10",
15+
"milestones": "40",
16+
"users": "50",
17+
"groups": "10",
18+
"projects": "20",
19+
"active_users": "50",
20+
}
21+
22+
23+
@pytest.fixture
24+
def resp_application_statistics():
25+
26+
with responses.RequestsMock(assert_all_requests_are_fired=False) as rsps:
27+
rsps.add(
28+
method=responses.GET,
29+
url="http://localhost/api/v4/application/statistics",
30+
json=content,
31+
content_type="application/json",
32+
status=200,
33+
)
34+
35+
yield rsps
36+
37+
38+
def test_get_statistics(gl, resp_application_statistics):
39+
statistics = gl.statistics.get()
40+
assert statistics.forks == content["forks"]
41+
assert statistics.merge_requests == content["merge_requests"]
42+
assert statistics.notes == content["notes"]
43+
assert statistics.snippets == content["snippets"]
44+
assert statistics.ssh_keys == content["ssh_keys"]
45+
assert statistics.milestones == content["milestones"]
46+
assert statistics.users == content["users"]
47+
assert statistics.groups == content["groups"]
48+
assert statistics.projects == content["projects"]
49+
assert statistics.active_users == content["active_users"]

0 commit comments

Comments
 (0)