Skip to content

Commit 4270a20

Browse files
committed
Add tests for uncovered methods
1 parent 2589505 commit 4270a20

2 files changed

Lines changed: 89 additions & 0 deletions

File tree

api/tests/unit/features/release_pipeline/core/conftest.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import pytest
22

3+
from environments.models import Environment
34
from features.release_pipelines.core.models import (
5+
PipelineStage,
6+
PipelineStageAction,
7+
PipelineStageTrigger,
48
ReleasePipeline,
9+
StageActionType,
10+
StageTriggerType,
511
)
612
from projects.models import Project
713

@@ -13,3 +19,34 @@ def release_pipeline(project: Project) -> ReleasePipeline:
1319
project=project,
1420
)
1521
return release_pipeline # type: ignore[no-any-return]
22+
23+
24+
@pytest.fixture()
25+
def pipeline_stage_enable_feature_on_enter(
26+
release_pipeline: ReleasePipeline,
27+
environment: Environment,
28+
environment_v2_versioning: Environment,
29+
) -> PipelineStage:
30+
# Given
31+
pipeline_stage = PipelineStage.objects.create(
32+
name="Stage zero",
33+
pipeline=release_pipeline,
34+
order=0,
35+
environment=environment,
36+
)
37+
(
38+
PipelineStageTrigger.objects.create(
39+
trigger_type=StageTriggerType.ON_ENTER.value, stage=pipeline_stage
40+
),
41+
)
42+
PipelineStageAction.objects.create(
43+
action_type=StageActionType.TOGGLE_FEATURE.value,
44+
action_body={"enabled": True},
45+
stage=pipeline_stage,
46+
)
47+
PipelineStageAction.objects.create(
48+
action_type=StageActionType.UPDATE_FEATURE_VALUE.value,
49+
action_body={"string_value": "stage_zero_value", "type": "unicode"},
50+
stage=pipeline_stage,
51+
)
52+
return pipeline_stage

api/tests/unit/features/release_pipeline/core/test_unit_release_pipeline_models.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import pytest
2+
from django.utils import timezone
23

34
from audit.constants import (
45
RELEASE_PIPELINE_CREATED_MESSAGE,
56
RELEASE_PIPELINE_DELETED_MESSAGE,
67
)
78
from environments.models import Environment
9+
from features.models import EnvironmentFeatureVersion, Feature
810
from features.release_pipelines.core.exceptions import InvalidPipelineStateError
911
from features.release_pipelines.core.models import (
1012
PipelineStage,
@@ -138,6 +140,28 @@ def test_release_pipeline_get_delete_log_message(
138140
assert release_pipeline.get_delete_log_message(release_pipeline) == expected_message
139141

140142

143+
def test_release_pipeline_unpublish(
144+
release_pipeline: ReleasePipeline, admin_user: FFAdminUser
145+
) -> None:
146+
# Given - the pipeline is already published
147+
release_pipeline.publish(admin_user)
148+
149+
# When
150+
release_pipeline.unpublish(admin_user)
151+
152+
# Then
153+
assert release_pipeline.published_at is None
154+
assert release_pipeline.published_by is None
155+
156+
157+
def test_should_raise_error_when_unpublishing_unpublished_pipeline(
158+
release_pipeline: ReleasePipeline, admin_user: FFAdminUser
159+
) -> None:
160+
# When/ Then
161+
with pytest.raises(InvalidPipelineStateError, match="Pipeline is not published."):
162+
release_pipeline.unpublish(admin_user)
163+
164+
141165
def test_clone_release_pipeline(
142166
release_pipeline: ReleasePipeline,
143167
environment: Environment,
@@ -241,3 +265,31 @@ def test_clone_release_pipeline(
241265

242266
# source action still points to the original stage
243267
assert source_action.stage == source_stage
268+
269+
270+
def test_release_pipeline_has_feature_in_flight(
271+
release_pipeline: ReleasePipeline,
272+
environment: Environment,
273+
pipeline_stage_enable_feature_on_enter: PipelineStage,
274+
admin_user: FFAdminUser,
275+
feature: Feature,
276+
) -> None:
277+
# Given an unpublished environment feature version
278+
feature = release_pipeline.project.features.first()
279+
environment_version = EnvironmentFeatureVersion.objects.create(
280+
feature=feature,
281+
environment=environment,
282+
pipeline_stage=pipeline_stage_enable_feature_on_enter,
283+
published_at=None,
284+
)
285+
286+
# Then
287+
assert release_pipeline.has_feature_in_flight() is True
288+
289+
# Next, publish the environment feature version
290+
environment_version.published_at = timezone.now()
291+
environment_version.published_by = admin_user
292+
environment_version.save()
293+
294+
# Then
295+
assert release_pipeline.has_feature_in_flight() is False

0 commit comments

Comments
 (0)