From 07150101b22167b1e59f3d116a7d1ca741e2b2e2 Mon Sep 17 00:00:00 2001 From: David Lougheed Date: Mon, 30 Sep 2024 13:47:40 -0400 Subject: [PATCH] test: dats as attachment --- chord_metadata_service/chord/tests/test_api.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/chord_metadata_service/chord/tests/test_api.py b/chord_metadata_service/chord/tests/test_api.py index d50391001..212c826e0 100644 --- a/chord_metadata_service/chord/tests/test_api.py +++ b/chord_metadata_service/chord/tests/test_api.py @@ -184,6 +184,24 @@ def test_dats(self): response = self.client.get("/api/datasets/does-not-exist/dats") self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) + def test_dats_as_attachment(self): + payload = {**self.dats_valid_payload, 'dats_file': {}} + + r = self.one_authz_post('/api/datasets', data=json.dumps(payload)) + + self.assertEqual(r.status_code, status.HTTP_201_CREATED) + dataset_id = Dataset.objects.first().identifier + + response = self.client.get(f"/api/datasets/{dataset_id}/dats?attachment=true") + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertDictEqual(response.data, payload['dats_file']) + self.assertEqual(response.headers["Content-Disposition"], f"attachment; filename=\"{dataset_id}_dats.json\"") + + response = self.client.get(f"/api/datasets/{dataset_id}/dats?attachment=false") + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertDictEqual(response.data, payload['dats_file']) + self.assertNotIn("Content-Disposition", response.headers) + def test_resources(self): resource = { "id": "NCBITaxon:2023-09-14",