Skip to content

Commit 6e232c0

Browse files
committed
LinkView Exception Tests
1 parent f703817 commit 6e232c0

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

server/portal/apps/datafiles/views_unit_test.py

+29
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,21 @@ def test_link_post(postits_create, authenticated_user, client):
130130
)
131131

132132

133+
def test_link_post_already_exists(postits_create, authenticated_user, client):
134+
result = client.post("/api/datafiles/link/tapis/system/path")
135+
assert json.loads(result.content)["data"] == "https://tenant/uuid"
136+
assert Link.objects.all()[0].get_uuid() == "uuid"
137+
postits_create.assert_called_with(
138+
systemId="system",
139+
path="path",
140+
allowedUses=-1,
141+
validSeconds=31536000
142+
)
143+
result = client.post("/api/datafiles/link/tapis/system/path")
144+
assert result.status_code == 400
145+
assert result.json() == {"message": "Link for this file already exists"}
146+
147+
133148
def test_link_delete(postits_create, authenticated_user, mock_tapis_client, client):
134149
mock_tapis_client.files.deletePostIt.return_value = "OK"
135150
client.post("/api/datafiles/link/tapis/system/path")
@@ -139,6 +154,13 @@ def test_link_delete(postits_create, authenticated_user, mock_tapis_client, clie
139154
assert len(Link.objects.all()) == 0
140155

141156

157+
def test_link_delete_dne(authenticated_user, mock_tapis_client, client):
158+
mock_tapis_client.files.deletePostIt.return_value = "Bad Request"
159+
result = client.delete("/api/datafiles/link/tapis/system/path")
160+
assert result.status_code == 400
161+
assert result.json() == {"message": "Post-it does not exist"}
162+
163+
142164
def test_link_put(postits_create, authenticated_user, mock_tapis_client, client):
143165
mock_tapis_client.files.deletePostIt.return_value = "OK"
144166
Link.objects.create(
@@ -150,6 +172,13 @@ def test_link_put(postits_create, authenticated_user, mock_tapis_client, client)
150172
assert Link.objects.all()[0].get_uuid() == "uuid"
151173

152174

175+
def test_link_put_dne(postits_create, authenticated_user, mock_tapis_client, client):
176+
mock_tapis_client.files.deletePostIt.return_value = "Bad Request"
177+
result = client.put("/api/datafiles/link/tapis/system/path")
178+
assert result.status_code == 400
179+
assert result.json() == {"message": "Could not find pre-existing link"}
180+
181+
153182
def test_get_system(client, authenticated_user, mock_tapis_client, agave_storage_system_mock):
154183
mock_tapis_client.systems.getSystem.return_value = TapisResult(**agave_storage_system_mock)
155184

0 commit comments

Comments
 (0)