Skip to content

Commit

Permalink
Refactor GitLab unit tests to prepare for #10426.
Browse files Browse the repository at this point in the history
  • Loading branch information
fniessink committed Feb 13, 2025
1 parent 0b290fb commit 3832f7d
Showing 1 changed file with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
"""Unit tests for the GitLab CI-pipeline duration collector."""

from datetime import datetime
from typing import Final
from unittest.mock import Mock, patch

from dateutil.tz import tzutc

from .base import GitLabTestCase


class FakeResponse:
"""Fake GitLab response."""

links: Final[dict] = {}

def __init__(self, fake_json) -> None:
self.fake_json = fake_json

async def json(self):
"""Return the fake JSON."""
return self.fake_json


class GitLabPipelineDurationTest(GitLabTestCase):
"""Unit tests for the CI-pipeline duration metric."""

Expand Down Expand Up @@ -48,10 +62,9 @@ def setUp(self) -> None:
async def collect(self):
"""Override to pass the GitLab pipeline JSON responses."""
return await super().collect(
get_request_json_side_effect=[
self.pipeline_json, # To fetch all pipelines
self.pipeline_detail_json, # To get the pipeline data for the most recent pipeline
self.pipeline_detail_json, # To get the pipeline landing URL for the most recent pipeline
get_request_side_effect=[
FakeResponse(self.pipeline_json), # To fetch all pipelines
FakeResponse(self.pipeline_detail_json), # To get the pipeline detauls for the most recent pipeline
]
)

Expand Down

0 comments on commit 3832f7d

Please sign in to comment.