Skip to content

Commit

Permalink
Adjust FileContentSerializer to upstream change
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Dellweg committed Sep 12, 2019
1 parent b348e97 commit 4f3ac9f
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGES/5428.removal
@@ -0,0 +1 @@
Adjust FileContentSerializer to upstream change.
2 changes: 1 addition & 1 deletion docs/_static/api.json

Large diffs are not rendered by default.

19 changes: 3 additions & 16 deletions pulp_file/app/serializers.py
Expand Up @@ -10,7 +10,6 @@
PublicationSerializer,
RemoteSerializer,
SingleArtifactContentSerializer,
relative_path_validator,
)

from .models import FileContent, FileDistribution, FileRemote, FilePublication
Expand All @@ -21,19 +20,11 @@ class FileContentSerializer(SingleArtifactContentSerializer, ContentChecksumSeri
Serializer for File Content.
"""

relative_path = serializers.CharField(
help_text=_(
"Relative location of the file within the repository. " "Example: `path/to/file.txt`"
),
validators=[relative_path_validator],
)

def validate(self, data):
"""Validate the FileContent data."""
data = super().validate(data)

data["digest"] = data["_artifact"].sha256
data["_relative_path"] = data["relative_path"]
data["digest"] = data["artifact"].sha256

content = FileContent.objects.filter(
digest=data["digest"], relative_path=data["relative_path"]
Expand All @@ -44,17 +35,13 @@ def validate(self, data):
_(
"There is already a file content with relative path '{path}' and artifact "
"'{artifact}'."
).format(path=data["relative_path"], artifact=self.initial_data["_artifact"])
).format(path=data["relative_path"], artifact=self.initial_data["artifact"])
)

return data

class Meta:
fields = (
tuple(set(SingleArtifactContentSerializer.Meta.fields) - {"_relative_path"})
+ ContentChecksumSerializer.Meta.fields
+ ("relative_path",)
)
fields = SingleArtifactContentSerializer.Meta.fields + ContentChecksumSerializer.Meta.fields
model = FileContent


Expand Down
2 changes: 1 addition & 1 deletion pulp_file/tests/functional/utils.py
Expand Up @@ -57,7 +57,7 @@ def gen_file_content_attrs(artifact):
:param artifact: A dict of info about the artifact.
:returns: A semi-random dict for use in creating a content unit.
"""
return {"_artifact": artifact["_href"], "relative_path": utils.uuid4()}
return {"artifact": artifact["_href"], "relative_path": utils.uuid4()}


def populate_pulp(cfg, url=FILE_FIXTURE_MANIFEST_URL):
Expand Down
6 changes: 3 additions & 3 deletions pulp_file/tests/unit/test_serializers.py
Expand Up @@ -26,7 +26,7 @@ def setUp(self):
def test_valid_data(self):
"""Test that the FileContentSerializer accepts valid data."""
data = {
"_artifact": "/pulp/api/v3/artifacts/{}/".format(self.artifact.pk),
"artifact": "/pulp/api/v3/artifacts/{}/".format(self.artifact.pk),
"relative_path": "foo",
}
serializer = FileContentSerializer(data=data)
Expand All @@ -35,7 +35,7 @@ def test_valid_data(self):
def test_absolute_path_data(self):
"""Test that the FileContentSerializer does not accept data."""
data = {
"_artifact": "/pulp/api/v3/artifacts/{}/".format(self.artifact.pk),
"artifact": "/pulp/api/v3/artifacts/{}/".format(self.artifact.pk),
"relative_path": "/foo",
}
serializer = FileContentSerializer(data=data)
Expand All @@ -45,7 +45,7 @@ def test_duplicate_data(self):
"""Test that the FileContentSerializer does not accept data."""
FileContent.objects.create(relative_path="foo", digest=self.artifact.sha256)
data = {
"_artifact": "/pulp/api/v3/artifacts/{}/".format(self.artifact.pk),
"artifact": "/pulp/api/v3/artifacts/{}/".format(self.artifact.pk),
"relative_path": "foo",
}
serializer = FileContentSerializer(data=data)
Expand Down

0 comments on commit 4f3ac9f

Please sign in to comment.