Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Set tag to get or create #4790

Merged
merged 2 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/features/feature_external_resources/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def execute_after_save_actions(self):
repository_name=repo,
)
if github_repo.tagging_enabled:
github_tag = Tag.objects.get(
github_tag, _ = Tag.objects.get_or_create(
label=tag_by_type_and_state[self.type][state],
project=self.feature.project,
is_system_tag=True,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from integrations.github.constants import GITHUB_API_URL, GITHUB_API_VERSION
from integrations.github.models import GithubConfiguration, GitHubRepository
from projects.models import Project
from projects.tags.models import Tag
from segments.models import Segment
from tests.types import WithEnvironmentPermissionsCallable
from users.models import FFAdminUser
Expand Down Expand Up @@ -77,6 +78,7 @@ def test_create_feature_external_resource(
post_request_mock: MagicMock,
mock_github_client_generate_token: MagicMock,
) -> None:

# Given
repository_owner_name = (
f"{github_repository.repository_owner}/{github_repository.repository_name}"
Expand Down Expand Up @@ -181,6 +183,49 @@ def test_create_feature_external_resource(
)


@responses.activate
def test_create_feature_external_resource_missing_tags(
admin_client_new: APIClient,
feature_with_value: Feature,
segment_override_for_feature_with_value: FeatureState,
environment: Environment,
project: Project,
github_configuration: GithubConfiguration,
github_repository: GitHubRepository,
post_request_mock: MagicMock,
mock_github_client_generate_token: MagicMock,
) -> None:

# Given
Tag.objects.all().delete()
repository_owner_name = (
f"{github_repository.repository_owner}/{github_repository.repository_name}"
)
feature_external_resource_data = {
"type": "GITHUB_ISSUE",
"url": f"https://github.com/{repository_owner_name}/issues/35",
"feature": feature_with_value.id,
"metadata": {"state": "open"},
}

url = reverse(
"api-v1:projects:feature-external-resources-list",
kwargs={"project_pk": project.id, "feature_pk": feature_with_value.id},
)

# When
response = admin_client_new.post(
url, data=feature_external_resource_data, format="json"
)

# Then
assert response.status_code == status.HTTP_201_CREATED
assert Tag.objects.count() == 1
tag = Tag.objects.first()
assert tag.project == project
assert tag.label == "Issue Open"


def test_cannot_create_feature_external_resource_with_an_invalid_gh_url(
admin_client_new: APIClient,
feature: Feature,
Expand Down
Loading