Skip to content

Commit

Permalink
Fix Drag and drop in Appraisal tab
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhwaniartefact authored and replaceafill committed Sep 28, 2023
1 parent ebd28c0 commit 425d2a2
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/dashboard/src/components/filesystem_ajax/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -915,8 +915,8 @@ def copy_to_arrange(request, sources=None, destinations=None, fetch_children=Fal
for entry in entries:
entries_to_copy.append(
models.SIPArrange(
original_path=entry["original_path"],
arrange_path=entry["arrange_path"],
original_path=entry["original_path"].encode(),
arrange_path=entry["arrange_path"].encode(),
file_uuid=entry["file_uuid"],
transfer_uuid=entry["transfer_uuid"],
)
Expand Down
5 changes: 4 additions & 1 deletion src/dashboard/src/main/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,10 @@ class Meta:
def __str__(self):
return str(
_("%(original)s -> %(arrange)s")
% {"original": self.original_path, "arrange": self.arrange_path}
% {
"original": self.original_path.decode(),
"arrange": self.arrange_path.decode(),
}
)

@classmethod
Expand Down
79 changes: 75 additions & 4 deletions src/dashboard/tests/test_filesystem_ajax.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ def setUp(self):
self.client.login(username="test", password="test")
helpers.set_setting("dashboard_uuid", "test-uuid")

def test_fixtures(self):
objs = models.SIPArrange.objects.all()
assert len(objs) > 0

def test_arrange_contents_data_no_path(self):
# Call endpoint
response = self.client.get(
Expand Down Expand Up @@ -621,3 +617,78 @@ def test_contents_sorting(db, tmp_path, admin_client):
b64encode_string("a"),
b64encode_string("e"),
]


@pytest.mark.django_db
def test_copy_within_arrange(mocker, admin_client):
mocker.patch(
"storageService.get_first_location",
return_value={"uuid": "355d110f-b641-4b6b-b1c0-8426e63951e5"},
)
mocker.patch(
"storageService.get_file_metadata",
side_effect=[
[
{
"fileuuid": "0b603cee-1f8a-4842-996a-e02a0307ccf7",
"sipuuid": "99c87143-6f74-4398-84e0-14a8ca4bd05a",
}
],
[
{
"fileuuid": "03a33ef5-8714-46cc-aefe-7283186341ca",
"sipuuid": "99c87143-6f74-4398-84e0-14a8ca4bd05a",
}
],
],
)
mocker.patch(
"storageService.browse_location",
return_value={
"directories": [],
"entries": ["file1.txt", "file2.txt"],
"properties": {
"file1.txt": {"size": 8},
"file2.txt": {"size": 6},
},
},
)
helpers.set_setting("dashboard_uuid", "test-uuid")

# Expected attributes for the new SIPArrange instances.
attrs = ("original_path", "arrange_path", "file_uuid", "transfer_uuid")
expected = {
(
b"originals/objects/file1.txt",
b"/arrange/file1.txt",
uuid.UUID("0b603cee-1f8a-4842-996a-e02a0307ccf7"),
uuid.UUID("99c87143-6f74-4398-84e0-14a8ca4bd05a"),
),
(
b"originals/objects/file2.txt",
b"/arrange/file2.txt",
uuid.UUID("03a33ef5-8714-46cc-aefe-7283186341ca"),
uuid.UUID("99c87143-6f74-4398-84e0-14a8ca4bd05a"),
),
}

# Verify there are no SIPArrange instances.
assert models.SIPArrange.objects.count() == 0

# Copy directory
response = admin_client.post(
reverse("filesystem_ajax:copy_to_arrange"),
data={
"filepath": b64encode_string("/originals/objects/"),
"destination": b64encode_string("/arrange/"),
},
follow=True,
)
assert response.status_code == 201
assert json.loads(response.content.decode("utf8")) == {
"message": "Files added to the SIP."
}

# Verify SIPArrange instances were created as expected.
assert models.SIPArrange.objects.count() == 2
assert set(list(models.SIPArrange.objects.values_list(*attrs))) == expected

0 comments on commit 425d2a2

Please sign in to comment.