Skip to content

Commit 77a0b8e

Browse files
authored
AAP-41454 - [API] Make project scm_url editable in the patch API (#1315)
The URL attribute in the project is allowed to be set in the body to patch a project. ATF tests are added to change the URL of an existing project https://issues.redhat.com/browse/AAP-41454
1 parent e6491d5 commit 77a0b8e

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

src/aap_eda/api/serializers/project.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,12 @@ class ProjectUpdateRequestSerializer(serializers.ModelSerializer):
190190
allow_null=True,
191191
help_text="Proxy server for http or https connection",
192192
)
193+
url = serializers.CharField(
194+
required=False,
195+
allow_blank=True,
196+
allow_null=True,
197+
help_text="Source control repository URL.",
198+
)
193199

194200
class Meta:
195201
model = models.Project
@@ -203,6 +209,7 @@ class Meta:
203209
"scm_refspec",
204210
"verify_ssl",
205211
"proxy",
212+
"url",
206213
]
207214

208215
def validate(self, data):

src/aap_eda/api/views/project.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ def partial_update(self, request, pk):
211211

212212
update_fields = []
213213
old_data = model_to_dict(project)
214+
214215
for key, value in serializer.validated_data.items():
215216
setattr(project, key, value)
216217
update_fields.append(key)

tests/integration/api/test_project.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,27 @@ def test_partial_update_project_bad_proxy(
790790
)
791791

792792

793+
@pytest.mark.django_db
794+
def test_partial_update_project_url(
795+
new_project: models.Project,
796+
admin_client: APIClient,
797+
):
798+
original_url = new_project.url
799+
new_url = "https://git.example.com/foo-bar"
800+
801+
response = admin_client.patch(
802+
f"{api_url_v1}/projects/{new_project.id}/",
803+
data={"url": new_url},
804+
)
805+
806+
assert response.status_code == status.HTTP_200_OK
807+
assert response.json()["url"] == new_url
808+
809+
new_project.refresh_from_db()
810+
assert new_project.url == new_url
811+
assert new_project.url != original_url
812+
813+
793814
@pytest.mark.django_db
794815
def test_delete_project(
795816
new_project: models.Project,

0 commit comments

Comments
 (0)