Skip to content
This repository has been archived by the owner on May 15, 2020. It is now read-only.

Commit

Permalink
OPT: allow dot in metadata key
Browse files Browse the repository at this point in the history
  • Loading branch information
rodgomes committed Feb 3, 2020
1 parent 371f6fe commit 07409de
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions katka/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ class ApplicationMetadataViewSet(AuditViewSet):
model = ApplicationMetadata
serializer_class = ApplicationMetadataSerializer
lookup_field = "key"
lookup_value_regex = r"[^/]+"

def get_queryset(self):
kwargs = {
Expand Down
9 changes: 9 additions & 0 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,15 @@ def my_metadata(my_application):
return meta


@pytest.fixture
def my_metadata_with_dot_in_key(my_application):
meta = models.ApplicationMetadata(key="rfc.ci", value="the-team", application=my_application)
with username_on_model(models.ApplicationMetadata, "initial"):
meta.save()

return meta


@pytest.fixture
def deactivated_metadata(deactivated_application):
metadata = models.ApplicationMetadata(key="ci", value="the-team-2", application=deactivated_application)
Expand Down
24 changes: 24 additions & 0 deletions tests/integration/test_application_metadata_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ def test_authenticated(self, client, logged_in_user, application, metadata):
assert metadata["value"] == "the-team"
assert UUID(metadata["application"]) == application.public_identifier

def test_get_key_with_dot(self, client, logged_in_user, application, my_metadata_with_dot_in_key):
url = f"/applications/{application.public_identifier}/metadata/{my_metadata_with_dot_in_key.key}/"
response = client.get(url)
assert response.status_code == 200
metadata = response.json()
assert metadata["key"] == "rfc.ci"
assert metadata["value"] == "the-team"
assert UUID(metadata["application"]) == application.public_identifier

def test_non_existent_application(self, client, logged_in_user, application, metadata):
url = f"/applications/00000000-0000-0000-0000-000000000000/metadata/{metadata.key}/"
response = client.get(url)
Expand Down Expand Up @@ -68,6 +77,13 @@ def test_authenticated(self, client, logged_in_user, application, metadata):
s = models.ApplicationMetadata.objects.get(key=metadata.key, application=application)
assert s.deleted is True

def test_delete_key_with_dot(self, client, logged_in_user, application, my_metadata_with_dot_in_key):
url = f"/applications/{application.public_identifier}/metadata/{my_metadata_with_dot_in_key.key}/"
response = client.delete(url)
assert response.status_code == 204
s = models.ApplicationMetadata.objects.get(key=my_metadata_with_dot_in_key.key, application=application)
assert s.deleted is True

def test_non_existent(self, client, logged_in_user, application, metadata):
before_count = models.ApplicationMetadata.objects.count()
url = f"/applications/00000000-0000-0000-0000-000000000000/metadata/{metadata.key}/"
Expand Down Expand Up @@ -138,6 +154,14 @@ def test_not_my_metadata(self, client, logged_in_user, not_my_application, not_m
s = models.ApplicationMetadata.objects.get(key=not_my_metadata.key, application=not_my_application)
assert s.value == "the-team-not-mine"

def test_update_key_with_dot(self, client, logged_in_user, application, my_metadata_with_dot_in_key):
url = f"/applications/{application.public_identifier}/metadata/{my_metadata_with_dot_in_key.key}/"
data = {"key": my_metadata_with_dot_in_key.key, "value": "new value"}
response = client.put(url, data, content_type="application/json")
assert response.status_code == 200
s = models.ApplicationMetadata.objects.get(key=my_metadata_with_dot_in_key.key, application=application)
assert s.value == "new value"


@pytest.mark.django_db
class TestApplicationMetadataPartialUpdate:
Expand Down

0 comments on commit 07409de

Please sign in to comment.