forked from enviPath/enviPy
This is an initial implementation that creates a working minimal .i6z document. It passes schema validation and can be imported into IUCLID. Caveat: IUCLID files target individual compounds. Pathway is not actually covered by the format. It can be added in either soil or water and soil OECD endpoints. **I currently only implemented the soil endpoint for all data.** This sort of works, and I can report all degradation products in a pathway (not a nice view, but we can report many transformation products and add a diagram attachment in the future). Adding additional information is an absolute pain, as we need to explicitly map each type of information to the relevant OECD field. I use the XSD scheme for validation, but unfortunately the IUCLID parser is not fully compliant and requires a specific order, etc. The workflow is: finding the AI structure from the XSD scheme -> make the scheme validation pass -> upload to IUCLID to get obscure error messages -> guess what could be wrong -> repeat 💣 New specifications get released once per year, so we will have to update accordingly. I believe that this should be a more expensive feature, as it requires significant effort to uphold. Currently implemented for root compound only in SOIL: - Soil Texture 2 - Soil Texture 1 - pH value - Half-life per soil sample / scenario (mapped to disappearance; not sure about that). - CEC - Organic Matter (only Carbon) - Moisture content - Humidity <img width="2123" alt="image.png" src="attachments/d29830e1-65ef-4136-8939-1825e0959c62"> <img width="2124" alt="image.png" src="attachments/ac9de2ac-bf68-4ba4-b40b-82f810a9de93"> <img width="2139" alt="image.png" src="attachments/5674c7e6-865e-420e-974a-6b825b331e6c"> Reviewed-on: enviPath/enviPy#338 Co-authored-by: Tobias O <tobias.olenyi@envipath.com> Co-committed-by: Tobias O <tobias.olenyi@envipath.com>
93 lines
3.1 KiB
Python
93 lines
3.1 KiB
Python
"""Integration tests for IUCLID export API endpoint."""
|
|
|
|
import io
|
|
import zipfile
|
|
from uuid import uuid4
|
|
|
|
from django.test import TestCase, tag
|
|
|
|
from epdb.logic import PackageManager, UserManager
|
|
from epdb.models import Node, Pathway
|
|
|
|
|
|
@tag("iuclid")
|
|
class IUCLIDExportAPITest(TestCase):
|
|
@classmethod
|
|
def setUpTestData(cls):
|
|
cls.user = UserManager.create_user(
|
|
"iuclid-api-user",
|
|
"iuclid-api@test.com",
|
|
"TestPass123",
|
|
set_setting=False,
|
|
add_to_group=False,
|
|
is_active=True,
|
|
)
|
|
default_pkg = cls.user.default_package
|
|
cls.user.default_package = None
|
|
cls.user.save()
|
|
default_pkg.delete()
|
|
|
|
cls.package = PackageManager.create_package(cls.user, "IUCLID API Test Package")
|
|
|
|
cls.pathway = Pathway.create(
|
|
cls.package,
|
|
"c1ccccc1",
|
|
name="Export Test Pathway",
|
|
)
|
|
Node.create(cls.pathway, "c1ccc(O)cc1", depth=1, name="Phenol")
|
|
|
|
# Unauthorized user
|
|
cls.other_user = UserManager.create_user(
|
|
"iuclid-other-user",
|
|
"other@test.com",
|
|
"TestPass123",
|
|
set_setting=False,
|
|
add_to_group=False,
|
|
is_active=True,
|
|
)
|
|
other_pkg = cls.other_user.default_package
|
|
cls.other_user.default_package = None
|
|
cls.other_user.save()
|
|
other_pkg.delete()
|
|
|
|
def test_export_returns_zip(self):
|
|
self.client.force_login(self.user)
|
|
url = f"/api/v1/pathway/{self.pathway.uuid}/export/iuclid"
|
|
response = self.client.get(url)
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
self.assertEqual(response["Content-Type"], "application/zip")
|
|
self.assertIn(".i6z", response["Content-Disposition"])
|
|
|
|
self.assertTrue(zipfile.is_zipfile(io.BytesIO(response.content)))
|
|
|
|
def test_export_contains_expected_files(self):
|
|
self.client.force_login(self.user)
|
|
url = f"/api/v1/pathway/{self.pathway.uuid}/export/iuclid"
|
|
response = self.client.get(url)
|
|
|
|
with zipfile.ZipFile(io.BytesIO(response.content)) as zf:
|
|
names = zf.namelist()
|
|
self.assertIn("manifest.xml", names)
|
|
i6d_files = [n for n in names if n.endswith(".i6d")]
|
|
# 2 substances + 2 ref substances + 1 ESR = 5 i6d files
|
|
self.assertEqual(len(i6d_files), 5)
|
|
|
|
def test_anonymous_returns_401(self):
|
|
self.client.logout()
|
|
url = f"/api/v1/pathway/{self.pathway.uuid}/export/iuclid"
|
|
response = self.client.get(url)
|
|
self.assertEqual(response.status_code, 401)
|
|
|
|
def test_unauthorized_user_returns_403(self):
|
|
self.client.force_login(self.other_user)
|
|
url = f"/api/v1/pathway/{self.pathway.uuid}/export/iuclid"
|
|
response = self.client.get(url)
|
|
self.assertEqual(response.status_code, 403)
|
|
|
|
def test_nonexistent_pathway_returns_404(self):
|
|
self.client.force_login(self.user)
|
|
url = f"/api/v1/pathway/{uuid4()}/export/iuclid"
|
|
response = self.client.get(url)
|
|
self.assertEqual(response.status_code, 404)
|