Skip to content

Commit 8760efc

Browse files
committed
test: added tests for statistics
1 parent 8c84cbf commit 8760efc

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

gitlab/tests/test_gitlab.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,62 @@ def resp_get_environment(url, request):
553553
self.assertEqual(environment.last_deployment, "sometime")
554554
self.assertEqual(environment.name, "environment_name")
555555

556+
def test_project_additional_statistics(self):
557+
@urlmatch(
558+
scheme="http", netloc="localhost", path="/api/v4/projects/1$", method="get"
559+
)
560+
def resp_get_project(url, request):
561+
headers = {"content-type": "application/json"}
562+
content = '{"name": "name", "id": 1}'.encode("utf-8")
563+
return response(200, content, headers, None, 5, request)
564+
565+
@urlmatch(
566+
scheme="http",
567+
netloc="localhost",
568+
path="/api/v4/projects/1/statistics",
569+
method="get",
570+
)
571+
def resp_get_environment(url, request):
572+
headers = {"content-type": "application/json"}
573+
content = """{"fetches": {"total": 50, "days": [{"count": 10, "date": "2018-01-10"}]}}""".encode(
574+
"utf-8"
575+
)
576+
return response(200, content, headers, None, 5, request)
577+
578+
with HTTMock(resp_get_project, resp_get_environment):
579+
project = self.gl.projects.get(1)
580+
statistics = project.additionalstatistics.get()
581+
self.assertIsInstance(statistics, ProjectAdditionalStatistics)
582+
self.assertEqual(statistics.fetches["total"], 50)
583+
584+
def test_project_issues_statistics(self):
585+
@urlmatch(
586+
scheme="http", netloc="localhost", path="/api/v4/projects/1$", method="get"
587+
)
588+
def resp_get_project(url, request):
589+
headers = {"content-type": "application/json"}
590+
content = '{"name": "name", "id": 1}'.encode("utf-8")
591+
return response(200, content, headers, None, 5, request)
592+
593+
@urlmatch(
594+
scheme="http",
595+
netloc="localhost",
596+
path="/api/v4/projects/1/issues_statistics",
597+
method="get",
598+
)
599+
def resp_get_environment(url, request):
600+
headers = {"content-type": "application/json"}
601+
content = """{"statistics": {"counts": {"all": 20, "closed": 5, "opened": 15}}}""".encode(
602+
"utf-8"
603+
)
604+
return response(200, content, headers, None, 5, request)
605+
606+
with HTTMock(resp_get_project, resp_get_environment):
607+
project = self.gl.projects.get(1)
608+
statistics = project.issuesstatistics.get()
609+
self.assertIsInstance(statistics, ProjectIssuesStatistics)
610+
self.assertEqual(statistics.statistics["counts"]["all"], 20)
611+
556612
def test_groups(self):
557613
@urlmatch(
558614
scheme="http", netloc="localhost", path="/api/v4/groups/1", method="get"

0 commit comments

Comments
 (0)