forked from enviPath/enviPy
[Chore] Linted Files (#150)
Co-authored-by: Tim Lorsbach <tim@lorsba.ch> Reviewed-on: enviPath/enviPy#150
This commit is contained in:
@ -3,7 +3,7 @@ from django.urls import reverse
|
||||
from envipy_additional_information import Temperature, Interval
|
||||
|
||||
from epdb.logic import UserManager, PackageManager
|
||||
from epdb.models import Compound, Scenario, ExternalIdentifier, ExternalDatabase
|
||||
from epdb.models import Compound, Scenario, ExternalDatabase
|
||||
|
||||
|
||||
class CompoundViewTest(TestCase):
|
||||
@ -12,21 +12,28 @@ class CompoundViewTest(TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(CompoundViewTest, cls).setUpClass()
|
||||
cls.user1 = UserManager.create_user("user1", "user1@envipath.com", "SuperSafe",
|
||||
set_setting=False, add_to_group=True, is_active=True)
|
||||
cls.user1 = UserManager.create_user(
|
||||
"user1",
|
||||
"user1@envipath.com",
|
||||
"SuperSafe",
|
||||
set_setting=False,
|
||||
add_to_group=True,
|
||||
is_active=True,
|
||||
)
|
||||
cls.user1_default_package = cls.user1.default_package
|
||||
cls.package = PackageManager.create_package(cls.user1, 'Test', 'Test Pack')
|
||||
cls.package = PackageManager.create_package(cls.user1, "Test", "Test Pack")
|
||||
|
||||
def setUp(self):
|
||||
self.client.force_login(self.user1)
|
||||
|
||||
def test_create_compound(self):
|
||||
response = self.client.post(
|
||||
reverse("compounds"), {
|
||||
reverse("compounds"),
|
||||
{
|
||||
"compound-name": "1,2-Dichloroethane",
|
||||
"compound-description": "Eawag BBD compound c0001",
|
||||
"compound-smiles": "C(CCl)Cl",
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 302)
|
||||
@ -38,17 +45,18 @@ class CompoundViewTest(TestCase):
|
||||
self.assertEqual(c.name, "1,2-Dichloroethane")
|
||||
self.assertEqual(c.description, "Eawag BBD compound c0001")
|
||||
self.assertEqual(c.default_structure.smiles, "C(CCl)Cl")
|
||||
self.assertEqual(c.default_structure.canonical_smiles, 'ClCCCl')
|
||||
self.assertEqual(c.default_structure.canonical_smiles, "ClCCCl")
|
||||
self.assertEqual(c.structures.all().count(), 2)
|
||||
self.assertEqual(self.user1_default_package.compounds.count(), 1)
|
||||
|
||||
# Adding the same rule again should return the existing one, hence not increasing the number of rules
|
||||
response = self.client.post(
|
||||
reverse("compounds"), {
|
||||
reverse("compounds"),
|
||||
{
|
||||
"compound-name": "1,2-Dichloroethane",
|
||||
"compound-description": "Eawag BBD compound c0001",
|
||||
"compound-smiles": "C(CCl)Cl",
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
self.assertEqual(response.url, compound_url)
|
||||
@ -57,11 +65,12 @@ class CompoundViewTest(TestCase):
|
||||
|
||||
# Adding the same rule in a different package should create a new rule
|
||||
response = self.client.post(
|
||||
reverse("package compound list", kwargs={'package_uuid': self.package.uuid}), {
|
||||
reverse("package compound list", kwargs={"package_uuid": self.package.uuid}),
|
||||
{
|
||||
"compound-name": "1,2-Dichloroethane",
|
||||
"compound-description": "Eawag BBD compound c0001",
|
||||
"compound-smiles": "C(CCl)Cl",
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 302)
|
||||
@ -69,11 +78,12 @@ class CompoundViewTest(TestCase):
|
||||
|
||||
# adding another reaction should increase count
|
||||
response = self.client.post(
|
||||
reverse("compounds"), {
|
||||
reverse("compounds"),
|
||||
{
|
||||
"compound-name": "2-Chloroethanol",
|
||||
"compound-description": "Eawag BBD compound c0005",
|
||||
"compound-smiles": "C(CO)Cl",
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 302)
|
||||
@ -82,11 +92,12 @@ class CompoundViewTest(TestCase):
|
||||
# Edit
|
||||
def test_edit_rule(self):
|
||||
response = self.client.post(
|
||||
reverse("compounds"), {
|
||||
reverse("compounds"),
|
||||
{
|
||||
"compound-name": "1,2-Dichloroethane",
|
||||
"compound-description": "Eawag BBD compound c0001",
|
||||
"compound-smiles": "C(CCl)Cl",
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 302)
|
||||
@ -95,13 +106,17 @@ class CompoundViewTest(TestCase):
|
||||
c = Compound.objects.get(url=compound_url)
|
||||
|
||||
response = self.client.post(
|
||||
reverse("package compound detail", kwargs={
|
||||
'package_uuid': str(self.user1_default_package.uuid),
|
||||
'compound_uuid': str(c.uuid)
|
||||
}), {
|
||||
reverse(
|
||||
"package compound detail",
|
||||
kwargs={
|
||||
"package_uuid": str(self.user1_default_package.uuid),
|
||||
"compound_uuid": str(c.uuid),
|
||||
},
|
||||
),
|
||||
{
|
||||
"compound-name": "Test Compound Adjusted",
|
||||
"compound-description": "New Description",
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 302)
|
||||
@ -121,7 +136,7 @@ class CompoundViewTest(TestCase):
|
||||
"Test Desc",
|
||||
"2025-10",
|
||||
"soil",
|
||||
[Temperature(interval=Interval(start=20, end=30))]
|
||||
[Temperature(interval=Interval(start=20, end=30))],
|
||||
)
|
||||
|
||||
s2 = Scenario.create(
|
||||
@ -130,15 +145,16 @@ class CompoundViewTest(TestCase):
|
||||
"Test Desc2",
|
||||
"2025-10",
|
||||
"soil",
|
||||
[Temperature(interval=Interval(start=10, end=20))]
|
||||
[Temperature(interval=Interval(start=10, end=20))],
|
||||
)
|
||||
|
||||
response = self.client.post(
|
||||
reverse("compounds"), {
|
||||
reverse("compounds"),
|
||||
{
|
||||
"compound-name": "1,2-Dichloroethane",
|
||||
"compound-description": "Eawag BBD compound c0001",
|
||||
"compound-smiles": "C(CCl)Cl",
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 302)
|
||||
@ -147,36 +163,35 @@ class CompoundViewTest(TestCase):
|
||||
c = Compound.objects.get(url=compound_url)
|
||||
|
||||
response = self.client.post(
|
||||
reverse("package compound detail", kwargs={
|
||||
'package_uuid': str(c.package.uuid),
|
||||
'compound_uuid': str(c.uuid)
|
||||
}), {
|
||||
"selected-scenarios": [s1.url, s2.url]
|
||||
}
|
||||
reverse(
|
||||
"package compound detail",
|
||||
kwargs={"package_uuid": str(c.package.uuid), "compound_uuid": str(c.uuid)},
|
||||
),
|
||||
{"selected-scenarios": [s1.url, s2.url]},
|
||||
)
|
||||
|
||||
self.assertEqual(len(c.scenarios.all()), 2)
|
||||
|
||||
response = self.client.post(
|
||||
reverse("package compound detail", kwargs={
|
||||
'package_uuid': str(c.package.uuid),
|
||||
'compound_uuid': str(c.uuid)
|
||||
}), {
|
||||
"selected-scenarios": [s1.url]
|
||||
}
|
||||
reverse(
|
||||
"package compound detail",
|
||||
kwargs={"package_uuid": str(c.package.uuid), "compound_uuid": str(c.uuid)},
|
||||
),
|
||||
{"selected-scenarios": [s1.url]},
|
||||
)
|
||||
|
||||
self.assertEqual(len(c.scenarios.all()), 1)
|
||||
self.assertEqual(c.scenarios.first().url, s1.url)
|
||||
|
||||
response = self.client.post(
|
||||
reverse("package compound detail", kwargs={
|
||||
'package_uuid': str(c.package.uuid),
|
||||
'compound_uuid': str(c.uuid)
|
||||
}), {
|
||||
reverse(
|
||||
"package compound detail",
|
||||
kwargs={"package_uuid": str(c.package.uuid), "compound_uuid": str(c.uuid)},
|
||||
),
|
||||
{
|
||||
# We have to set an empty string to avoid that the parameter is removed
|
||||
"selected-scenarios": ""
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
self.assertEqual(len(c.scenarios.all()), 0)
|
||||
@ -184,11 +199,12 @@ class CompoundViewTest(TestCase):
|
||||
#
|
||||
def test_copy(self):
|
||||
response = self.client.post(
|
||||
reverse("compounds"), {
|
||||
reverse("compounds"),
|
||||
{
|
||||
"compound-name": "1,2-Dichloroethane",
|
||||
"compound-description": "Eawag BBD compound c0001",
|
||||
"compound-smiles": "C(CCl)Cl",
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 302)
|
||||
@ -196,12 +212,13 @@ class CompoundViewTest(TestCase):
|
||||
c = Compound.objects.get(url=compound_url)
|
||||
|
||||
response = self.client.post(
|
||||
reverse("package detail", kwargs={
|
||||
'package_uuid': str(self.package.uuid),
|
||||
}), {
|
||||
"hidden": "copy",
|
||||
"object_to_copy": c.url
|
||||
}
|
||||
reverse(
|
||||
"package detail",
|
||||
kwargs={
|
||||
"package_uuid": str(self.package.uuid),
|
||||
},
|
||||
),
|
||||
{"hidden": "copy", "object_to_copy": c.url},
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
@ -215,44 +232,48 @@ class CompoundViewTest(TestCase):
|
||||
|
||||
# Copy to the same package should fail
|
||||
response = self.client.post(
|
||||
reverse("package detail", kwargs={
|
||||
'package_uuid': str(c.package.uuid),
|
||||
}), {
|
||||
"hidden": "copy",
|
||||
"object_to_copy": c.url
|
||||
}
|
||||
reverse(
|
||||
"package detail",
|
||||
kwargs={
|
||||
"package_uuid": str(c.package.uuid),
|
||||
},
|
||||
),
|
||||
{"hidden": "copy", "object_to_copy": c.url},
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 400)
|
||||
self.assertEqual(response.json()['error'], f"Can't copy object {compound_url} to the same package!")
|
||||
self.assertEqual(
|
||||
response.json()["error"], f"Can't copy object {compound_url} to the same package!"
|
||||
)
|
||||
|
||||
def test_references(self):
|
||||
ext_db, _ = ExternalDatabase.objects.get_or_create(
|
||||
name='PubChem Compound',
|
||||
name="PubChem Compound",
|
||||
defaults={
|
||||
'full_name': 'PubChem Compound Database',
|
||||
'description': 'Chemical database of small organic molecules',
|
||||
'base_url': 'https://pubchem.ncbi.nlm.nih.gov',
|
||||
'url_pattern': 'https://pubchem.ncbi.nlm.nih.gov/compound/{id}'
|
||||
}
|
||||
"full_name": "PubChem Compound Database",
|
||||
"description": "Chemical database of small organic molecules",
|
||||
"base_url": "https://pubchem.ncbi.nlm.nih.gov",
|
||||
"url_pattern": "https://pubchem.ncbi.nlm.nih.gov/compound/{id}",
|
||||
},
|
||||
)
|
||||
|
||||
ext_db2, _ = ExternalDatabase.objects.get_or_create(
|
||||
name='PubChem Substance',
|
||||
name="PubChem Substance",
|
||||
defaults={
|
||||
'full_name': 'PubChem Substance Database',
|
||||
'description': 'Database of chemical substances',
|
||||
'base_url': 'https://pubchem.ncbi.nlm.nih.gov',
|
||||
'url_pattern': 'https://pubchem.ncbi.nlm.nih.gov/substance/{id}'
|
||||
}
|
||||
"full_name": "PubChem Substance Database",
|
||||
"description": "Database of chemical substances",
|
||||
"base_url": "https://pubchem.ncbi.nlm.nih.gov",
|
||||
"url_pattern": "https://pubchem.ncbi.nlm.nih.gov/substance/{id}",
|
||||
},
|
||||
)
|
||||
|
||||
response = self.client.post(
|
||||
reverse("compounds"), {
|
||||
reverse("compounds"),
|
||||
{
|
||||
"compound-name": "1,2-Dichloroethane",
|
||||
"compound-description": "Eawag BBD compound c0001",
|
||||
"compound-smiles": "C(CCl)Cl",
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 302)
|
||||
@ -260,42 +281,49 @@ class CompoundViewTest(TestCase):
|
||||
c = Compound.objects.get(url=compound_url)
|
||||
|
||||
response = self.client.post(
|
||||
reverse("package compound detail", kwargs={
|
||||
'package_uuid': str(c.package.uuid),
|
||||
'compound_uuid': str(c.uuid),
|
||||
}), {
|
||||
'selected-database': ext_db.pk,
|
||||
'identifier': '25154249'
|
||||
}
|
||||
reverse(
|
||||
"package compound detail",
|
||||
kwargs={
|
||||
"package_uuid": str(c.package.uuid),
|
||||
"compound_uuid": str(c.uuid),
|
||||
},
|
||||
),
|
||||
{"selected-database": ext_db.pk, "identifier": "25154249"},
|
||||
)
|
||||
|
||||
self.assertEqual(c.external_identifiers.count(), 1)
|
||||
self.assertEqual(c.external_identifiers.first().database, ext_db)
|
||||
self.assertEqual(c.external_identifiers.first().identifier_value, '25154249')
|
||||
self.assertEqual(c.external_identifiers.first().url, 'https://pubchem.ncbi.nlm.nih.gov/compound/25154249')
|
||||
self.assertEqual(c.external_identifiers.first().identifier_value, "25154249")
|
||||
self.assertEqual(
|
||||
c.external_identifiers.first().url, "https://pubchem.ncbi.nlm.nih.gov/compound/25154249"
|
||||
)
|
||||
|
||||
response = self.client.post(
|
||||
reverse("package compound detail", kwargs={
|
||||
'package_uuid': str(c.package.uuid),
|
||||
'compound_uuid': str(c.uuid),
|
||||
}), {
|
||||
'selected-database': ext_db2.pk,
|
||||
'identifier': '25154249'
|
||||
}
|
||||
reverse(
|
||||
"package compound detail",
|
||||
kwargs={
|
||||
"package_uuid": str(c.package.uuid),
|
||||
"compound_uuid": str(c.uuid),
|
||||
},
|
||||
),
|
||||
{"selected-database": ext_db2.pk, "identifier": "25154249"},
|
||||
)
|
||||
|
||||
self.assertEqual(c.external_identifiers.count(), 2)
|
||||
self.assertEqual(c.external_identifiers.last().database, ext_db2)
|
||||
self.assertEqual(c.external_identifiers.last().identifier_value, '25154249')
|
||||
self.assertEqual(c.external_identifiers.last().url, 'https://pubchem.ncbi.nlm.nih.gov/substance/25154249')
|
||||
self.assertEqual(c.external_identifiers.last().identifier_value, "25154249")
|
||||
self.assertEqual(
|
||||
c.external_identifiers.last().url, "https://pubchem.ncbi.nlm.nih.gov/substance/25154249"
|
||||
)
|
||||
|
||||
def test_delete(self):
|
||||
response = self.client.post(
|
||||
reverse("compounds"), {
|
||||
reverse("compounds"),
|
||||
{
|
||||
"compound-name": "1,2-Dichloroethane",
|
||||
"compound-description": "Eawag BBD compound c0001",
|
||||
"compound-smiles": "C(CCl)Cl",
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 302)
|
||||
@ -304,12 +332,11 @@ class CompoundViewTest(TestCase):
|
||||
c = Compound.objects.get(url=compound_url)
|
||||
|
||||
response = self.client.post(
|
||||
reverse("package compound detail", kwargs={
|
||||
'package_uuid': str(c.package.uuid),
|
||||
'compound_uuid': str(c.uuid)
|
||||
}), {
|
||||
"hidden": "delete"
|
||||
}
|
||||
reverse(
|
||||
"package compound detail",
|
||||
kwargs={"package_uuid": str(c.package.uuid), "compound_uuid": str(c.uuid)},
|
||||
),
|
||||
{"hidden": "delete"},
|
||||
)
|
||||
|
||||
self.assertEqual(self.user1_default_package.compounds.count(), 0)
|
||||
|
||||
Reference in New Issue
Block a user