Expose the sha1 in the API file serializer
Each filecontent is stored uniquely by sha1 so multiple files can refer to the same filecontent. Let's expose the sha1 for files so we can use this client side if need be. Change-Id: Iddd4701f8b9cc5f4b579854f495fffc6efbf04ac
This commit is contained in:
parent
41db775584
commit
7f2b3c2802
@ -103,8 +103,13 @@ class FileSerializer(serializers.ModelSerializer):
|
||||
model = models.File
|
||||
fields = "__all__"
|
||||
|
||||
sha1 = serializers.SerializerMethodField()
|
||||
content = FileContentField()
|
||||
|
||||
@staticmethod
|
||||
def get_sha1(obj):
|
||||
return obj.content.sha1
|
||||
|
||||
|
||||
class HostSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
|
@ -73,9 +73,11 @@ class FileTestCase(APITestCase):
|
||||
file = factories.FileFactory()
|
||||
request = self.client.get("/api/v1/files/%s" % file.id)
|
||||
self.assertEqual(file.path, request.data["path"])
|
||||
self.assertEqual(file.content.sha1, request.data["sha1"])
|
||||
|
||||
def test_update_file(self):
|
||||
file = factories.FileFactory()
|
||||
old_sha1 = file.content.sha1
|
||||
self.assertNotEqual("/path/new_playbook.yml", file.path)
|
||||
request = self.client.put(
|
||||
"/api/v1/files/%s" % file.id, {"path": "/path/new_playbook.yml", "content": "# playbook"}
|
||||
@ -83,6 +85,7 @@ class FileTestCase(APITestCase):
|
||||
self.assertEqual(200, request.status_code)
|
||||
file_updated = models.File.objects.get(id=file.id)
|
||||
self.assertEqual("/path/new_playbook.yml", file_updated.path)
|
||||
self.assertNotEqual(old_sha1, file_updated.content.sha1)
|
||||
|
||||
def test_partial_update_file(self):
|
||||
file = factories.FileFactory()
|
||||
|
Loading…
Reference in New Issue
Block a user