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)
|
||||
|
||||
@ -2,8 +2,8 @@ from django.test import TestCase, override_settings
|
||||
from django.urls import reverse
|
||||
from django.conf import settings as s
|
||||
|
||||
from epdb.logic import UserManager, PackageManager
|
||||
from epdb.models import Pathway, Edge, Package, User
|
||||
from epdb.logic import UserManager
|
||||
from epdb.models import Package, User
|
||||
|
||||
|
||||
@override_settings(MODEL_DIR=s.FIXTURE_DIRS[0] / "models")
|
||||
@ -13,10 +13,16 @@ class PathwayViewTest(TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(PathwayViewTest, cls).setUpClass()
|
||||
cls.user1 = UserManager.create_user("user1", "user1@envipath.com", "SuperSafe",
|
||||
set_setting=True, add_to_group=True, is_active=True)
|
||||
cls.user1 = UserManager.create_user(
|
||||
"user1",
|
||||
"user1@envipath.com",
|
||||
"SuperSafe",
|
||||
set_setting=True,
|
||||
add_to_group=True,
|
||||
is_active=True,
|
||||
)
|
||||
cls.user1_default_package = cls.user1.default_package
|
||||
cls.model_package = Package.objects.get(name='Fixtures')
|
||||
cls.model_package = Package.objects.get(name="Fixtures")
|
||||
|
||||
def setUp(self):
|
||||
self.client.force_login(self.user1)
|
||||
@ -24,90 +30,96 @@ class PathwayViewTest(TestCase):
|
||||
def test_predict(self):
|
||||
self.client.force_login(User.objects.get(username="admin"))
|
||||
response = self.client.get(
|
||||
reverse("package model detail", kwargs={
|
||||
'package_uuid': str(self.model_package.uuid),
|
||||
'model_uuid': str(self.model_package.models.first().uuid)
|
||||
}), {
|
||||
'classify': 'ILikeCats!',
|
||||
'smiles': 'CCN(CC)C(=O)C1=CC(=CC=C1)CO',
|
||||
}
|
||||
reverse(
|
||||
"package model detail",
|
||||
kwargs={
|
||||
"package_uuid": str(self.model_package.uuid),
|
||||
"model_uuid": str(self.model_package.models.first().uuid),
|
||||
},
|
||||
),
|
||||
{
|
||||
"classify": "ILikeCats!",
|
||||
"smiles": "CCN(CC)C(=O)C1=CC(=CC=C1)CO",
|
||||
},
|
||||
)
|
||||
|
||||
expected = [
|
||||
{
|
||||
'products': [
|
||||
[
|
||||
'O=C(O)C1=CC(CO)=CC=C1',
|
||||
'CCNCC'
|
||||
]
|
||||
],
|
||||
'probability': 0.25,
|
||||
'btrule': {
|
||||
'url': 'http://localhost:8000/package/1869d3f0-60bb-41fd-b6f8-afa75ffb09d3/simple-ambit-rule/0e6e9290-b658-4450-b291-3ec19fa19206',
|
||||
'name': 'bt0430-4011'
|
||||
}
|
||||
}, {
|
||||
'products': [
|
||||
[
|
||||
'CCNC(=O)C1=CC(CO)=CC=C1',
|
||||
'CC=O'
|
||||
]
|
||||
], 'probability': 0.0,
|
||||
'btrule': {
|
||||
'url': 'http://localhost:8000/package/1869d3f0-60bb-41fd-b6f8-afa75ffb09d3/simple-ambit-rule/27a3a353-0b66-4228-bd16-e407949e90df',
|
||||
'name': 'bt0243-4301'
|
||||
}
|
||||
}, {
|
||||
'products': [
|
||||
[
|
||||
'CCN(CC)C(=O)C1=CC(C=O)=CC=C1'
|
||||
]
|
||||
], 'probability': 0.75,
|
||||
'btrule': {
|
||||
'url': 'http://localhost:8000/package/1869d3f0-60bb-41fd-b6f8-afa75ffb09d3/simple-ambit-rule/2f2e0c39-e109-4836-959f-2bda2524f022',
|
||||
'name': 'bt0001-3568'
|
||||
}
|
||||
}
|
||||
"products": [["O=C(O)C1=CC(CO)=CC=C1", "CCNCC"]],
|
||||
"probability": 0.25,
|
||||
"btrule": {
|
||||
"url": "http://localhost:8000/package/1869d3f0-60bb-41fd-b6f8-afa75ffb09d3/simple-ambit-rule/0e6e9290-b658-4450-b291-3ec19fa19206",
|
||||
"name": "bt0430-4011",
|
||||
},
|
||||
},
|
||||
{
|
||||
"products": [["CCNC(=O)C1=CC(CO)=CC=C1", "CC=O"]],
|
||||
"probability": 0.0,
|
||||
"btrule": {
|
||||
"url": "http://localhost:8000/package/1869d3f0-60bb-41fd-b6f8-afa75ffb09d3/simple-ambit-rule/27a3a353-0b66-4228-bd16-e407949e90df",
|
||||
"name": "bt0243-4301",
|
||||
},
|
||||
},
|
||||
{
|
||||
"products": [["CCN(CC)C(=O)C1=CC(C=O)=CC=C1"]],
|
||||
"probability": 0.75,
|
||||
"btrule": {
|
||||
"url": "http://localhost:8000/package/1869d3f0-60bb-41fd-b6f8-afa75ffb09d3/simple-ambit-rule/2f2e0c39-e109-4836-959f-2bda2524f022",
|
||||
"name": "bt0001-3568",
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
actual = response.json()
|
||||
self.assertEqual(actual, expected)
|
||||
|
||||
response = self.client.get(
|
||||
reverse("package model detail", kwargs={
|
||||
'package_uuid': str(self.model_package.uuid),
|
||||
'model_uuid': str(self.model_package.models.first().uuid)
|
||||
}), {
|
||||
'classify': 'ILikeCats!',
|
||||
'smiles': '',
|
||||
}
|
||||
reverse(
|
||||
"package model detail",
|
||||
kwargs={
|
||||
"package_uuid": str(self.model_package.uuid),
|
||||
"model_uuid": str(self.model_package.models.first().uuid),
|
||||
},
|
||||
),
|
||||
{
|
||||
"classify": "ILikeCats!",
|
||||
"smiles": "",
|
||||
},
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 400)
|
||||
self.assertEqual(response.json()['error'], 'Received empty SMILES')
|
||||
self.assertEqual(response.json()["error"], "Received empty SMILES")
|
||||
|
||||
response = self.client.get(
|
||||
reverse("package model detail", kwargs={
|
||||
'package_uuid': str(self.model_package.uuid),
|
||||
'model_uuid': str(self.model_package.models.first().uuid)
|
||||
}), {
|
||||
'classify': 'ILikeCats!',
|
||||
'smiles': ' ', # Input should be stripped
|
||||
}
|
||||
reverse(
|
||||
"package model detail",
|
||||
kwargs={
|
||||
"package_uuid": str(self.model_package.uuid),
|
||||
"model_uuid": str(self.model_package.models.first().uuid),
|
||||
},
|
||||
),
|
||||
{
|
||||
"classify": "ILikeCats!",
|
||||
"smiles": " ", # Input should be stripped
|
||||
},
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 400)
|
||||
self.assertEqual(response.json()['error'], 'Received empty SMILES')
|
||||
self.assertEqual(response.json()["error"], "Received empty SMILES")
|
||||
|
||||
response = self.client.get(
|
||||
reverse("package model detail", kwargs={
|
||||
'package_uuid': str(self.model_package.uuid),
|
||||
'model_uuid': str(self.model_package.models.first().uuid)
|
||||
}), {
|
||||
'classify': 'ILikeCats!',
|
||||
'smiles': 'RandomInput',
|
||||
}
|
||||
reverse(
|
||||
"package model detail",
|
||||
kwargs={
|
||||
"package_uuid": str(self.model_package.uuid),
|
||||
"model_uuid": str(self.model_package.models.first().uuid),
|
||||
},
|
||||
),
|
||||
{
|
||||
"classify": "ILikeCats!",
|
||||
"smiles": "RandomInput",
|
||||
},
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 400)
|
||||
self.assertEqual(response.json()['error'], '"RandomInput" is not a valid SMILES')
|
||||
self.assertEqual(response.json()["error"], '"RandomInput" is not a valid SMILES')
|
||||
|
||||
@ -13,19 +13,34 @@ class PackageViewTest(TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(PackageViewTest, cls).setUpClass()
|
||||
cls.user1 = UserManager.create_user("user1", "user1@envipath.com", "SuperSafe",
|
||||
set_setting=False, add_to_group=True, is_active=True)
|
||||
cls.user2 = UserManager.create_user("user2", "user2@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.user2 = UserManager.create_user(
|
||||
"user2",
|
||||
"user2@envipath.com",
|
||||
"SuperSafe",
|
||||
set_setting=False,
|
||||
add_to_group=True,
|
||||
is_active=True,
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
self.client.force_login(self.user1)
|
||||
|
||||
def test_create_package(self):
|
||||
response = self.client.post(reverse("packages"), {
|
||||
"package-name": "Test Package",
|
||||
"package-description": "Just a Description",
|
||||
})
|
||||
response = self.client.post(
|
||||
reverse("packages"),
|
||||
{
|
||||
"package-name": "Test Package",
|
||||
"package-description": "Just a Description",
|
||||
},
|
||||
)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
package_url = response.url
|
||||
|
||||
@ -41,13 +56,12 @@ class PackageViewTest(TestCase):
|
||||
file = SimpleUploadedFile(
|
||||
"Fixture_Package.json",
|
||||
open(s.FIXTURE_DIRS[0] / "Fixture_Package.json", "rb").read(),
|
||||
content_type="application/json"
|
||||
content_type="application/json",
|
||||
)
|
||||
|
||||
response = self.client.post(reverse("packages"), {
|
||||
"file": file,
|
||||
"hidden": "import-package-json"
|
||||
})
|
||||
response = self.client.post(
|
||||
reverse("packages"), {"file": file, "hidden": "import-package-json"}
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 302)
|
||||
package_url = response.url
|
||||
@ -67,13 +81,12 @@ class PackageViewTest(TestCase):
|
||||
file = SimpleUploadedFile(
|
||||
"EAWAG-BBD.json",
|
||||
open(s.FIXTURE_DIRS[0] / "packages" / "2025-07-18" / "EAWAG-BBD.json", "rb").read(),
|
||||
content_type="application/json"
|
||||
content_type="application/json",
|
||||
)
|
||||
|
||||
response = self.client.post(reverse("packages"), {
|
||||
"file": file,
|
||||
"hidden": "import-legacy-package-json"
|
||||
})
|
||||
response = self.client.post(
|
||||
reverse("packages"), {"file": file, "hidden": "import-legacy-package-json"}
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 302)
|
||||
package_url = response.url
|
||||
@ -90,17 +103,23 @@ class PackageViewTest(TestCase):
|
||||
self.assertEqual(upp.permission, Permission.ALL[0])
|
||||
|
||||
def test_edit_package(self):
|
||||
response = self.client.post(reverse("packages"), {
|
||||
"package-name": "Test Package",
|
||||
"package-description": "Just a Description",
|
||||
})
|
||||
response = self.client.post(
|
||||
reverse("packages"),
|
||||
{
|
||||
"package-name": "Test Package",
|
||||
"package-description": "Just a Description",
|
||||
},
|
||||
)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
package_url = response.url
|
||||
|
||||
self.client.post(package_url, {
|
||||
"package-name": "New Name",
|
||||
"package-description": "New Description",
|
||||
})
|
||||
self.client.post(
|
||||
package_url,
|
||||
{
|
||||
"package-name": "New Name",
|
||||
"package-description": "New Description",
|
||||
},
|
||||
)
|
||||
|
||||
p = Package.objects.get(url=package_url)
|
||||
|
||||
@ -108,10 +127,13 @@ class PackageViewTest(TestCase):
|
||||
self.assertEqual(p.description, "New Description")
|
||||
|
||||
def test_edit_package_permissions(self):
|
||||
response = self.client.post(reverse("packages"), {
|
||||
"package-name": "Test Package",
|
||||
"package-description": "Just a Description",
|
||||
})
|
||||
response = self.client.post(
|
||||
reverse("packages"),
|
||||
{
|
||||
"package-name": "Test Package",
|
||||
"package-description": "Just a Description",
|
||||
},
|
||||
)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
package_url = response.url
|
||||
p = Package.objects.get(url=package_url)
|
||||
@ -119,57 +141,63 @@ class PackageViewTest(TestCase):
|
||||
with self.assertRaises(UserPackagePermission.DoesNotExist):
|
||||
UserPackagePermission.objects.get(package=p, user=self.user2)
|
||||
|
||||
self.client.post(package_url, {
|
||||
"grantee": self.user2.url,
|
||||
"read": "on",
|
||||
"write": "on",
|
||||
})
|
||||
self.client.post(
|
||||
package_url,
|
||||
{
|
||||
"grantee": self.user2.url,
|
||||
"read": "on",
|
||||
"write": "on",
|
||||
},
|
||||
)
|
||||
|
||||
upp = UserPackagePermission.objects.get(package=p, user=self.user2)
|
||||
|
||||
self.assertEqual(upp.permission, Permission.WRITE[0])
|
||||
|
||||
def test_publish_package(self):
|
||||
response = self.client.post(reverse("packages"), {
|
||||
"package-name": "Test Package",
|
||||
"package-description": "Just a Description",
|
||||
})
|
||||
response = self.client.post(
|
||||
reverse("packages"),
|
||||
{
|
||||
"package-name": "Test Package",
|
||||
"package-description": "Just a Description",
|
||||
},
|
||||
)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
package_url = response.url
|
||||
p = Package.objects.get(url=package_url)
|
||||
|
||||
self.client.post(package_url, {
|
||||
"hidden": "publish-package"
|
||||
})
|
||||
self.client.post(package_url, {"hidden": "publish-package"})
|
||||
|
||||
self.assertEqual(Group.objects.filter(public=True).count(), 1)
|
||||
g = Group.objects.get(public=True)
|
||||
gpp = GroupPackagePermission.objects.get(package=p, group=g)
|
||||
self.assertEqual(gpp.permission, Permission.READ[0])
|
||||
|
||||
|
||||
def test_set_package_license(self):
|
||||
response = self.client.post(reverse("packages"), {
|
||||
"package-name": "Test Package",
|
||||
"package-description": "Just a Description",
|
||||
})
|
||||
response = self.client.post(
|
||||
reverse("packages"),
|
||||
{
|
||||
"package-name": "Test Package",
|
||||
"package-description": "Just a Description",
|
||||
},
|
||||
)
|
||||
|
||||
package_url = response.url
|
||||
p = Package.objects.get(url=package_url)
|
||||
|
||||
self.client.post(package_url, {
|
||||
"license": "no-license"
|
||||
})
|
||||
self.client.post(package_url, {"license": "no-license"})
|
||||
|
||||
self.assertIsNone(p.license)
|
||||
# TODO test others
|
||||
|
||||
|
||||
def test_delete_package(self):
|
||||
response = self.client.post(reverse("packages"), {
|
||||
"package-name": "Test Package",
|
||||
"package-description": "Just a Description",
|
||||
})
|
||||
response = self.client.post(
|
||||
reverse("packages"),
|
||||
{
|
||||
"package-name": "Test Package",
|
||||
"package-description": "Just a Description",
|
||||
},
|
||||
)
|
||||
|
||||
package_url = response.url
|
||||
p = Package.objects.get(url=package_url)
|
||||
@ -182,11 +210,11 @@ class PackageViewTest(TestCase):
|
||||
def test_delete_default_package(self):
|
||||
self.client.force_login(self.user1)
|
||||
# Try to delete the default package
|
||||
response = self.client.post(self.user1.default_package.url, {
|
||||
"hidden": "delete"
|
||||
})
|
||||
response = self.client.post(self.user1.default_package.url, {"hidden": "delete"})
|
||||
|
||||
self.assertEqual(response.status_code, 400)
|
||||
self.assertTrue(f'You cannot delete the default package. '
|
||||
f'If you want to delete this package you have to '
|
||||
f'set another default package first' in response.content.decode())
|
||||
self.assertTrue(
|
||||
"You cannot delete the default package. "
|
||||
"If you want to delete this package you have to "
|
||||
"set another default package first" in response.content.decode()
|
||||
)
|
||||
|
||||
@ -5,6 +5,7 @@ from django.conf import settings as s
|
||||
from epdb.logic import UserManager, PackageManager
|
||||
from epdb.models import Pathway, Edge
|
||||
|
||||
|
||||
@override_settings(MODEL_DIR=s.FIXTURE_DIRS[0] / "models")
|
||||
class PathwayViewTest(TestCase):
|
||||
fixtures = ["test_fixtures_incl_model.jsonl.gz"]
|
||||
@ -12,41 +13,52 @@ class PathwayViewTest(TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(PathwayViewTest, cls).setUpClass()
|
||||
cls.user1 = UserManager.create_user("user1", "user1@envipath.com", "SuperSafe",
|
||||
set_setting=True, add_to_group=True, is_active=True)
|
||||
cls.user1 = UserManager.create_user(
|
||||
"user1",
|
||||
"user1@envipath.com",
|
||||
"SuperSafe",
|
||||
set_setting=True,
|
||||
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_predict_pathway(self):
|
||||
response = self.client.post(reverse("pathways"), {
|
||||
'name': 'Test Pathway',
|
||||
'description': 'Just a Description',
|
||||
'predict': 'predict',
|
||||
'smiles': 'CCN(CC)C(=O)C1=CC(=CC=C1)CO',
|
||||
})
|
||||
response = self.client.post(
|
||||
reverse("pathways"),
|
||||
{
|
||||
"name": "Test Pathway",
|
||||
"description": "Just a Description",
|
||||
"predict": "predict",
|
||||
"smiles": "CCN(CC)C(=O)C1=CC(=CC=C1)CO",
|
||||
},
|
||||
)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
pathway_url = response.url
|
||||
|
||||
pw = Pathway.objects.get(url=pathway_url)
|
||||
self.assertEqual(self.user1_default_package, pw.package)
|
||||
|
||||
self.assertEqual(pw.name, 'Test Pathway')
|
||||
self.assertEqual(pw.description, 'Just a Description')
|
||||
self.assertEqual(pw.name, "Test Pathway")
|
||||
self.assertEqual(pw.description, "Just a Description")
|
||||
self.assertEqual(len(pw.root_nodes), 1)
|
||||
self.assertEqual(pw.root_nodes.first().default_node_label.smiles, 'CCN(CC)C(=O)C1=CC(CO)=CC=C1')
|
||||
self.assertEqual(
|
||||
pw.root_nodes.first().default_node_label.smiles, "CCN(CC)C(=O)C1=CC(CO)=CC=C1"
|
||||
)
|
||||
|
||||
first_level_nodes = {
|
||||
# Edge 1
|
||||
'CCN(CC)C(=O)C1=CC(C=O)=CC=C1',
|
||||
"CCN(CC)C(=O)C1=CC(C=O)=CC=C1",
|
||||
# Edge 2
|
||||
'CCNC(=O)C1=CC(CO)=CC=C1',
|
||||
'CC=O',
|
||||
"CCNC(=O)C1=CC(CO)=CC=C1",
|
||||
"CC=O",
|
||||
# Edge 3
|
||||
'CCNCC',
|
||||
'O=C(O)C1=CC(CO)=CC=C1',
|
||||
"CCNCC",
|
||||
"O=C(O)C1=CC(CO)=CC=C1",
|
||||
}
|
||||
|
||||
predicted_nodes = set()
|
||||
@ -60,32 +72,36 @@ class PathwayViewTest(TestCase):
|
||||
|
||||
def test_predict_package_pathway(self):
|
||||
response = self.client.post(
|
||||
reverse("package pathway list", kwargs={'package_uuid': str(self.package.uuid)}), {
|
||||
'name': 'Test Pathway',
|
||||
'description': 'Just a Description',
|
||||
'predict': 'predict',
|
||||
'smiles': 'CCN(CC)C(=O)C1=CC(=CC=C1)CO',
|
||||
})
|
||||
reverse("package pathway list", kwargs={"package_uuid": str(self.package.uuid)}),
|
||||
{
|
||||
"name": "Test Pathway",
|
||||
"description": "Just a Description",
|
||||
"predict": "predict",
|
||||
"smiles": "CCN(CC)C(=O)C1=CC(=CC=C1)CO",
|
||||
},
|
||||
)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
pathway_url = response.url
|
||||
|
||||
pw = Pathway.objects.get(url=pathway_url)
|
||||
self.assertEqual(self.package, pw.package)
|
||||
|
||||
self.assertEqual(pw.name, 'Test Pathway')
|
||||
self.assertEqual(pw.description, 'Just a Description')
|
||||
self.assertEqual(pw.name, "Test Pathway")
|
||||
self.assertEqual(pw.description, "Just a Description")
|
||||
self.assertEqual(len(pw.root_nodes), 1)
|
||||
self.assertEqual(pw.root_nodes.first().default_node_label.smiles, 'CCN(CC)C(=O)C1=CC(CO)=CC=C1')
|
||||
self.assertEqual(
|
||||
pw.root_nodes.first().default_node_label.smiles, "CCN(CC)C(=O)C1=CC(CO)=CC=C1"
|
||||
)
|
||||
|
||||
first_level_nodes = {
|
||||
# Edge 1
|
||||
'CCN(CC)C(=O)C1=CC(C=O)=CC=C1',
|
||||
"CCN(CC)C(=O)C1=CC(C=O)=CC=C1",
|
||||
# Edge 2
|
||||
'CCNC(=O)C1=CC(CO)=CC=C1',
|
||||
'CC=O',
|
||||
"CCNC(=O)C1=CC(CO)=CC=C1",
|
||||
"CC=O",
|
||||
# Edge 3
|
||||
'CCNCC',
|
||||
'O=C(O)C1=CC(CO)=CC=C1',
|
||||
"CCNCC",
|
||||
"O=C(O)C1=CC(CO)=CC=C1",
|
||||
}
|
||||
|
||||
predicted_nodes = set()
|
||||
|
||||
@ -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 Reaction, Scenario, ExternalIdentifier, ExternalDatabase
|
||||
from epdb.models import Reaction, Scenario, ExternalDatabase
|
||||
|
||||
|
||||
class ReactionViewTest(TestCase):
|
||||
@ -12,21 +12,28 @@ class ReactionViewTest(TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(ReactionViewTest, 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_reaction(self):
|
||||
response = self.client.post(
|
||||
reverse("reactions"), {
|
||||
reverse("reactions"),
|
||||
{
|
||||
"reaction-name": "Eawag BBD reaction r0001",
|
||||
"reaction-description": "Description for Eawag BBD reaction r0001",
|
||||
"reaction-smirks": "C(CCl)Cl>>C(CO)Cl",
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 302)
|
||||
@ -42,11 +49,12 @@ class ReactionViewTest(TestCase):
|
||||
|
||||
# Adding the same rule again should return the existing one, hence not increasing the number of rules
|
||||
response = self.client.post(
|
||||
reverse("reactions"), {
|
||||
reverse("reactions"),
|
||||
{
|
||||
"reaction-name": "Eawag BBD reaction r0001",
|
||||
"reaction-description": "Description for Eawag BBD reaction r0001",
|
||||
"reaction-smirks": "C(CCl)Cl>>C(CO)Cl",
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
self.assertEqual(response.url, reaction_url)
|
||||
@ -55,11 +63,12 @@ class ReactionViewTest(TestCase):
|
||||
|
||||
# Adding the same rule in a different package should create a new rule
|
||||
response = self.client.post(
|
||||
reverse("package reaction list", kwargs={'package_uuid': self.package.uuid}), {
|
||||
reverse("package reaction list", kwargs={"package_uuid": self.package.uuid}),
|
||||
{
|
||||
"reaction-name": "Eawag BBD reaction r0001",
|
||||
"reaction-description": "Description for Eawag BBD reaction r0001",
|
||||
"reaction-smirks": "C(CCl)Cl>>C(CO)Cl",
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 302)
|
||||
@ -67,11 +76,12 @@ class ReactionViewTest(TestCase):
|
||||
|
||||
# adding another reaction should increase count
|
||||
response = self.client.post(
|
||||
reverse("reactions"), {
|
||||
reverse("reactions"),
|
||||
{
|
||||
"reaction-name": "Eawag BBD reaction r0002",
|
||||
"reaction-description": "Description for Eawag BBD reaction r0002",
|
||||
"reaction-smirks": "C(CO)Cl>>C(C=O)Cl",
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 302)
|
||||
@ -80,11 +90,12 @@ class ReactionViewTest(TestCase):
|
||||
# Edit
|
||||
def test_edit_rule(self):
|
||||
response = self.client.post(
|
||||
reverse("reactions"), {
|
||||
reverse("reactions"),
|
||||
{
|
||||
"reaction-name": "Eawag BBD reaction r0001",
|
||||
"reaction-description": "Description for Eawag BBD reaction r0001",
|
||||
"reaction-smirks": "C(CCl)Cl>>C(CO)Cl",
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 302)
|
||||
@ -93,13 +104,17 @@ class ReactionViewTest(TestCase):
|
||||
r = Reaction.objects.get(url=reaction_url)
|
||||
|
||||
response = self.client.post(
|
||||
reverse("package reaction detail", kwargs={
|
||||
'package_uuid': str(self.user1_default_package.uuid),
|
||||
'reaction_uuid': str(r.uuid)
|
||||
}), {
|
||||
reverse(
|
||||
"package reaction detail",
|
||||
kwargs={
|
||||
"package_uuid": str(self.user1_default_package.uuid),
|
||||
"reaction_uuid": str(r.uuid),
|
||||
},
|
||||
),
|
||||
{
|
||||
"reaction-name": "Test Reaction Adjusted",
|
||||
"reaction-description": "New Description",
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 302)
|
||||
@ -119,7 +134,7 @@ class ReactionViewTest(TestCase):
|
||||
"Test Desc",
|
||||
"2025-10",
|
||||
"soil",
|
||||
[Temperature(interval=Interval(start=20, end=30))]
|
||||
[Temperature(interval=Interval(start=20, end=30))],
|
||||
)
|
||||
|
||||
s2 = Scenario.create(
|
||||
@ -128,15 +143,16 @@ class ReactionViewTest(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("reactions"), {
|
||||
reverse("reactions"),
|
||||
{
|
||||
"reaction-name": "Eawag BBD reaction r0001",
|
||||
"reaction-description": "Description for Eawag BBD reaction r0001",
|
||||
"reaction-smirks": "C(CCl)Cl>>C(CO)Cl",
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 302)
|
||||
@ -144,47 +160,47 @@ class ReactionViewTest(TestCase):
|
||||
r = Reaction.objects.get(url=reaction_url)
|
||||
|
||||
response = self.client.post(
|
||||
reverse("package reaction detail", kwargs={
|
||||
'package_uuid': str(r.package.uuid),
|
||||
'reaction_uuid': str(r.uuid)
|
||||
}), {
|
||||
"selected-scenarios": [s1.url, s2.url]
|
||||
}
|
||||
reverse(
|
||||
"package reaction detail",
|
||||
kwargs={"package_uuid": str(r.package.uuid), "reaction_uuid": str(r.uuid)},
|
||||
),
|
||||
{"selected-scenarios": [s1.url, s2.url]},
|
||||
)
|
||||
|
||||
self.assertEqual(len(r.scenarios.all()), 2)
|
||||
|
||||
response = self.client.post(
|
||||
reverse("package reaction detail", kwargs={
|
||||
'package_uuid': str(r.package.uuid),
|
||||
'reaction_uuid': str(r.uuid)
|
||||
}), {
|
||||
"selected-scenarios": [s1.url]
|
||||
}
|
||||
reverse(
|
||||
"package reaction detail",
|
||||
kwargs={"package_uuid": str(r.package.uuid), "reaction_uuid": str(r.uuid)},
|
||||
),
|
||||
{"selected-scenarios": [s1.url]},
|
||||
)
|
||||
|
||||
self.assertEqual(len(r.scenarios.all()), 1)
|
||||
self.assertEqual(r.scenarios.first().url, s1.url)
|
||||
|
||||
response = self.client.post(
|
||||
reverse("package reaction detail", kwargs={
|
||||
'package_uuid': str(r.package.uuid),
|
||||
'reaction_uuid': str(r.uuid)
|
||||
}), {
|
||||
reverse(
|
||||
"package reaction detail",
|
||||
kwargs={"package_uuid": str(r.package.uuid), "reaction_uuid": str(r.uuid)},
|
||||
),
|
||||
{
|
||||
# We have to set an empty string to avoid that the parameter is removed
|
||||
"selected-scenarios": ""
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
self.assertEqual(len(r.scenarios.all()), 0)
|
||||
|
||||
def test_copy(self):
|
||||
response = self.client.post(
|
||||
reverse("reactions"), {
|
||||
reverse("reactions"),
|
||||
{
|
||||
"reaction-name": "Eawag BBD reaction r0001",
|
||||
"reaction-description": "Description for Eawag BBD reaction r0001",
|
||||
"reaction-smirks": "C(CCl)Cl>>C(CO)Cl",
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 302)
|
||||
@ -192,12 +208,13 @@ class ReactionViewTest(TestCase):
|
||||
r = Reaction.objects.get(url=reaction_url)
|
||||
|
||||
response = self.client.post(
|
||||
reverse("package detail", kwargs={
|
||||
'package_uuid': str(self.package.uuid),
|
||||
}), {
|
||||
"hidden": "copy",
|
||||
"object_to_copy": r.url
|
||||
}
|
||||
reverse(
|
||||
"package detail",
|
||||
kwargs={
|
||||
"package_uuid": str(self.package.uuid),
|
||||
},
|
||||
),
|
||||
{"hidden": "copy", "object_to_copy": r.url},
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
@ -211,44 +228,48 @@ class ReactionViewTest(TestCase):
|
||||
|
||||
# Copy to the same package should fail
|
||||
response = self.client.post(
|
||||
reverse("package detail", kwargs={
|
||||
'package_uuid': str(r.package.uuid),
|
||||
}), {
|
||||
"hidden": "copy",
|
||||
"object_to_copy": r.url
|
||||
}
|
||||
reverse(
|
||||
"package detail",
|
||||
kwargs={
|
||||
"package_uuid": str(r.package.uuid),
|
||||
},
|
||||
),
|
||||
{"hidden": "copy", "object_to_copy": r.url},
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 400)
|
||||
self.assertEqual(response.json()['error'], f"Can't copy object {reaction_url} to the same package!")
|
||||
self.assertEqual(
|
||||
response.json()["error"], f"Can't copy object {reaction_url} to the same package!"
|
||||
)
|
||||
|
||||
def test_references(self):
|
||||
ext_db, _ = ExternalDatabase.objects.get_or_create(
|
||||
name='KEGG Reaction',
|
||||
name="KEGG Reaction",
|
||||
defaults={
|
||||
'full_name': 'KEGG Reaction Database',
|
||||
'description': 'Database of biochemical reactions',
|
||||
'base_url': 'https://www.genome.jp',
|
||||
'url_pattern': 'https://www.genome.jp/entry/{id}'
|
||||
}
|
||||
"full_name": "KEGG Reaction Database",
|
||||
"description": "Database of biochemical reactions",
|
||||
"base_url": "https://www.genome.jp",
|
||||
"url_pattern": "https://www.genome.jp/entry/{id}",
|
||||
},
|
||||
)
|
||||
|
||||
ext_db2, _ = ExternalDatabase.objects.get_or_create(
|
||||
name='RHEA',
|
||||
name="RHEA",
|
||||
defaults={
|
||||
'full_name': 'RHEA Reaction Database',
|
||||
'description': 'Comprehensive resource of biochemical reactions',
|
||||
'base_url': 'https://www.rhea-db.org',
|
||||
'url_pattern': 'https://www.rhea-db.org/rhea/{id}'
|
||||
"full_name": "RHEA Reaction Database",
|
||||
"description": "Comprehensive resource of biochemical reactions",
|
||||
"base_url": "https://www.rhea-db.org",
|
||||
"url_pattern": "https://www.rhea-db.org/rhea/{id}",
|
||||
},
|
||||
)
|
||||
|
||||
response = self.client.post(
|
||||
reverse("reactions"), {
|
||||
reverse("reactions"),
|
||||
{
|
||||
"reaction-name": "Eawag BBD reaction r0001",
|
||||
"reaction-description": "Description for Eawag BBD reaction r0001",
|
||||
"reaction-smirks": "C(CCl)Cl>>C(CO)Cl",
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 302)
|
||||
@ -256,45 +277,49 @@ class ReactionViewTest(TestCase):
|
||||
r = Reaction.objects.get(url=reaction_url)
|
||||
|
||||
response = self.client.post(
|
||||
reverse("package reaction detail", kwargs={
|
||||
'package_uuid': str(r.package.uuid),
|
||||
'reaction_uuid': str(r.uuid),
|
||||
}), {
|
||||
'selected-database': ext_db.pk,
|
||||
'identifier': 'C12345'
|
||||
}
|
||||
reverse(
|
||||
"package reaction detail",
|
||||
kwargs={
|
||||
"package_uuid": str(r.package.uuid),
|
||||
"reaction_uuid": str(r.uuid),
|
||||
},
|
||||
),
|
||||
{"selected-database": ext_db.pk, "identifier": "C12345"},
|
||||
)
|
||||
|
||||
self.assertEqual(r.external_identifiers.count(), 1)
|
||||
self.assertEqual(r.external_identifiers.first().database, ext_db)
|
||||
self.assertEqual(r.external_identifiers.first().identifier_value, 'C12345')
|
||||
self.assertEqual(r.external_identifiers.first().identifier_value, "C12345")
|
||||
# TODO Fixture contains old url template there the real test fails, use old value instead
|
||||
# self.assertEqual(r.external_identifiers.first().url, 'https://www.genome.jp/entry/C12345')
|
||||
self.assertEqual(r.external_identifiers.first().url, 'https://www.genome.jp/entry/reaction+C12345')
|
||||
self.assertEqual(
|
||||
r.external_identifiers.first().url, "https://www.genome.jp/entry/reaction+C12345"
|
||||
)
|
||||
|
||||
response = self.client.post(
|
||||
reverse("package reaction detail", kwargs={
|
||||
'package_uuid': str(r.package.uuid),
|
||||
'reaction_uuid': str(r.uuid),
|
||||
}), {
|
||||
'selected-database': ext_db2.pk,
|
||||
'identifier': '60116'
|
||||
}
|
||||
reverse(
|
||||
"package reaction detail",
|
||||
kwargs={
|
||||
"package_uuid": str(r.package.uuid),
|
||||
"reaction_uuid": str(r.uuid),
|
||||
},
|
||||
),
|
||||
{"selected-database": ext_db2.pk, "identifier": "60116"},
|
||||
)
|
||||
|
||||
self.assertEqual(r.external_identifiers.count(), 2)
|
||||
self.assertEqual(r.external_identifiers.last().database, ext_db2)
|
||||
self.assertEqual(r.external_identifiers.last().identifier_value, '60116')
|
||||
self.assertEqual(r.external_identifiers.last().url, 'https://www.rhea-db.org/rhea/60116')
|
||||
|
||||
self.assertEqual(r.external_identifiers.last().identifier_value, "60116")
|
||||
self.assertEqual(r.external_identifiers.last().url, "https://www.rhea-db.org/rhea/60116")
|
||||
|
||||
def test_delete(self):
|
||||
response = self.client.post(
|
||||
reverse("reactions"), {
|
||||
reverse("reactions"),
|
||||
{
|
||||
"reaction-name": "Eawag BBD reaction r0001",
|
||||
"reaction-description": "Description for Eawag BBD reaction r0001",
|
||||
"reaction-smirks": "C(CCl)Cl>>C(CO)Cl",
|
||||
}
|
||||
},
|
||||
)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
|
||||
@ -302,12 +327,11 @@ class ReactionViewTest(TestCase):
|
||||
r = Reaction.objects.get(url=reaction_url)
|
||||
|
||||
response = self.client.post(
|
||||
reverse("package reaction detail", kwargs={
|
||||
'package_uuid': str(r.package.uuid),
|
||||
'reaction_uuid': str(r.uuid)
|
||||
}), {
|
||||
"hidden": "delete"
|
||||
}
|
||||
reverse(
|
||||
"package reaction detail",
|
||||
kwargs={"package_uuid": str(r.package.uuid), "reaction_uuid": str(r.uuid)},
|
||||
),
|
||||
{"hidden": "delete"},
|
||||
)
|
||||
|
||||
self.assertEqual(self.user1_default_package.reactions.count(), 0)
|
||||
|
||||
@ -12,22 +12,29 @@ class RuleViewTest(TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(RuleViewTest, 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_rule(self):
|
||||
response = self.client.post(
|
||||
reverse("rules"), {
|
||||
reverse("rules"),
|
||||
{
|
||||
"rule-name": "Test Rule",
|
||||
"rule-description": "Just a Description",
|
||||
"rule-smirks": "[H:5][C:1]([#6:6])([#1,#9,#17,#35,#53:4])[#9,#17,#35,#53]>>[H:5][C:1]([#6:6])([#8])[#1,#9,#17,#35,#53:4]",
|
||||
"rule-type": "SimpleAmbitRule",
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 302)
|
||||
@ -38,18 +45,21 @@ class RuleViewTest(TestCase):
|
||||
self.assertEqual(r.package, self.user1_default_package)
|
||||
self.assertEqual(r.name, "Test Rule")
|
||||
self.assertEqual(r.description, "Just a Description")
|
||||
self.assertEqual(r.smirks,
|
||||
"[H:5][C:1]([#6:6])([#1,#9,#17,#35,#53:4])[#9,#17,#35,#53]>>[H:5][C:1]([#6:6])([#8])[#1,#9,#17,#35,#53:4]")
|
||||
self.assertEqual(
|
||||
r.smirks,
|
||||
"[H:5][C:1]([#6:6])([#1,#9,#17,#35,#53:4])[#9,#17,#35,#53]>>[H:5][C:1]([#6:6])([#8])[#1,#9,#17,#35,#53:4]",
|
||||
)
|
||||
self.assertEqual(self.user1_default_package.rules.count(), 1)
|
||||
|
||||
# Adding the same rule again should return the existing one, hence not increasing the number of rules
|
||||
response = self.client.post(
|
||||
reverse("rules"), {
|
||||
reverse("rules"),
|
||||
{
|
||||
"rule-name": "Test Rule",
|
||||
"rule-description": "Just a Description",
|
||||
"rule-smirks": "[H:5][C:1]([#6:6])([#1,#9,#17,#35,#53:4])[#9,#17,#35,#53]>>[H:5][C:1]([#6:6])([#8])[#1,#9,#17,#35,#53:4]",
|
||||
"rule-type": "SimpleAmbitRule",
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
self.assertEqual(response.url, rule_url)
|
||||
@ -58,12 +68,13 @@ class RuleViewTest(TestCase):
|
||||
|
||||
# Adding the same rule in a different package should create a new rule
|
||||
response = self.client.post(
|
||||
reverse("package rule list", kwargs={'package_uuid': self.package.uuid}), {
|
||||
reverse("package rule list", kwargs={"package_uuid": self.package.uuid}),
|
||||
{
|
||||
"rule-name": "Test Rule",
|
||||
"rule-description": "Just a Description",
|
||||
"rule-smirks": "[H:5][C:1]([#6:6])([#1,#9,#17,#35,#53:4])[#9,#17,#35,#53]>>[H:5][C:1]([#6:6])([#8])[#1,#9,#17,#35,#53:4]",
|
||||
"rule-type": "SimpleAmbitRule",
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 302)
|
||||
@ -72,12 +83,13 @@ class RuleViewTest(TestCase):
|
||||
# Edit
|
||||
def test_edit_rule(self):
|
||||
response = self.client.post(
|
||||
reverse("rules"), {
|
||||
reverse("rules"),
|
||||
{
|
||||
"rule-name": "Test Rule",
|
||||
"rule-description": "Just a Description",
|
||||
"rule-smirks": "[H:5][C:1]([#6:6])([#1,#9,#17,#35,#53:4])[#9,#17,#35,#53]>>[H:5][C:1]([#6:6])([#8])[#1,#9,#17,#35,#53:4]",
|
||||
"rule-type": "SimpleAmbitRule",
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 302)
|
||||
@ -86,13 +98,17 @@ class RuleViewTest(TestCase):
|
||||
r = Rule.objects.get(url=rule_url)
|
||||
|
||||
response = self.client.post(
|
||||
reverse("package rule detail", kwargs={
|
||||
'package_uuid': str(self.user1_default_package.uuid),
|
||||
'rule_uuid': str(r.uuid)
|
||||
}), {
|
||||
reverse(
|
||||
"package rule detail",
|
||||
kwargs={
|
||||
"package_uuid": str(self.user1_default_package.uuid),
|
||||
"rule_uuid": str(r.uuid),
|
||||
},
|
||||
),
|
||||
{
|
||||
"rule-name": "Test Rule Adjusted",
|
||||
"rule-description": "New Description",
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 302)
|
||||
@ -108,7 +124,7 @@ class RuleViewTest(TestCase):
|
||||
"Test Desc",
|
||||
"2025-10",
|
||||
"soil",
|
||||
[Temperature(interval=Interval(start=20, end=30))]
|
||||
[Temperature(interval=Interval(start=20, end=30))],
|
||||
)
|
||||
|
||||
s2 = Scenario.create(
|
||||
@ -117,16 +133,17 @@ class RuleViewTest(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("rules"), {
|
||||
reverse("rules"),
|
||||
{
|
||||
"rule-name": "Test Rule",
|
||||
"rule-description": "Just a Description",
|
||||
"rule-smirks": "[H:5][C:1]([#6:6])([#1,#9,#17,#35,#53:4])[#9,#17,#35,#53]>>[H:5][C:1]([#6:6])([#8])[#1,#9,#17,#35,#53:4]",
|
||||
"rule-type": "SimpleAmbitRule",
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 302)
|
||||
@ -134,48 +151,48 @@ class RuleViewTest(TestCase):
|
||||
r = Rule.objects.get(url=rule_url)
|
||||
|
||||
response = self.client.post(
|
||||
reverse("package rule detail", kwargs={
|
||||
'package_uuid': str(r.package.uuid),
|
||||
'rule_uuid': str(r.uuid)
|
||||
}), {
|
||||
"selected-scenarios": [s1.url, s2.url]
|
||||
}
|
||||
reverse(
|
||||
"package rule detail",
|
||||
kwargs={"package_uuid": str(r.package.uuid), "rule_uuid": str(r.uuid)},
|
||||
),
|
||||
{"selected-scenarios": [s1.url, s2.url]},
|
||||
)
|
||||
|
||||
self.assertEqual(len(r.scenarios.all()), 2)
|
||||
|
||||
response = self.client.post(
|
||||
reverse("package rule detail", kwargs={
|
||||
'package_uuid': str(r.package.uuid),
|
||||
'rule_uuid': str(r.uuid)
|
||||
}), {
|
||||
"selected-scenarios": [s1.url]
|
||||
}
|
||||
reverse(
|
||||
"package rule detail",
|
||||
kwargs={"package_uuid": str(r.package.uuid), "rule_uuid": str(r.uuid)},
|
||||
),
|
||||
{"selected-scenarios": [s1.url]},
|
||||
)
|
||||
|
||||
self.assertEqual(len(r.scenarios.all()), 1)
|
||||
self.assertEqual(r.scenarios.first().url, s1.url)
|
||||
|
||||
response = self.client.post(
|
||||
reverse("package rule detail", kwargs={
|
||||
'package_uuid': str(r.package.uuid),
|
||||
'rule_uuid': str(r.uuid)
|
||||
}), {
|
||||
reverse(
|
||||
"package rule detail",
|
||||
kwargs={"package_uuid": str(r.package.uuid), "rule_uuid": str(r.uuid)},
|
||||
),
|
||||
{
|
||||
# We have to set an empty string to avoid that the parameter is removed
|
||||
"selected-scenarios": ""
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
self.assertEqual(len(r.scenarios.all()), 0)
|
||||
|
||||
def test_copy(self):
|
||||
response = self.client.post(
|
||||
reverse("rules"), {
|
||||
reverse("rules"),
|
||||
{
|
||||
"rule-name": "Test Rule",
|
||||
"rule-description": "Just a Description",
|
||||
"rule-smirks": "[H:5][C:1]([#6:6])([#1,#9,#17,#35,#53:4])[#9,#17,#35,#53]>>[H:5][C:1]([#6:6])([#8])[#1,#9,#17,#35,#53:4]",
|
||||
"rule-type": "SimpleAmbitRule",
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 302)
|
||||
@ -183,12 +200,13 @@ class RuleViewTest(TestCase):
|
||||
r = Rule.objects.get(url=rule_url)
|
||||
|
||||
response = self.client.post(
|
||||
reverse("package detail", kwargs={
|
||||
'package_uuid': str(self.package.uuid),
|
||||
}), {
|
||||
"hidden": "copy",
|
||||
"object_to_copy": r.url
|
||||
}
|
||||
reverse(
|
||||
"package detail",
|
||||
kwargs={
|
||||
"package_uuid": str(self.package.uuid),
|
||||
},
|
||||
),
|
||||
{"hidden": "copy", "object_to_copy": r.url},
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
@ -202,26 +220,29 @@ class RuleViewTest(TestCase):
|
||||
|
||||
# Copy to the same package should fail
|
||||
response = self.client.post(
|
||||
reverse("package detail", kwargs={
|
||||
'package_uuid': str(r.package.uuid),
|
||||
}), {
|
||||
"hidden": "copy",
|
||||
"object_to_copy": r.url
|
||||
}
|
||||
reverse(
|
||||
"package detail",
|
||||
kwargs={
|
||||
"package_uuid": str(r.package.uuid),
|
||||
},
|
||||
),
|
||||
{"hidden": "copy", "object_to_copy": r.url},
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 400)
|
||||
self.assertEqual(response.json()['error'], f"Can't copy object {rule_url} to the same package!")
|
||||
|
||||
self.assertEqual(
|
||||
response.json()["error"], f"Can't copy object {rule_url} to the same package!"
|
||||
)
|
||||
|
||||
def test_delete(self):
|
||||
response = self.client.post(
|
||||
reverse("rules"), {
|
||||
reverse("rules"),
|
||||
{
|
||||
"rule-name": "Test Rule",
|
||||
"rule-description": "Just a Description",
|
||||
"rule-smirks": "[H:5][C:1]([#6:6])([#1,#9,#17,#35,#53:4])[#9,#17,#35,#53]>>[H:5][C:1]([#6:6])([#8])[#1,#9,#17,#35,#53:4]",
|
||||
"rule-type": "SimpleAmbitRule",
|
||||
}
|
||||
},
|
||||
)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
|
||||
@ -229,12 +250,11 @@ class RuleViewTest(TestCase):
|
||||
r = Rule.objects.get(url=rule_url)
|
||||
|
||||
response = self.client.post(
|
||||
reverse("package rule detail", kwargs={
|
||||
'package_uuid': str(r.package.uuid),
|
||||
'rule_uuid': str(r.uuid)
|
||||
}), {
|
||||
"hidden": "delete"
|
||||
}
|
||||
reverse(
|
||||
"package rule detail",
|
||||
kwargs={"package_uuid": str(r.package.uuid), "rule_uuid": str(r.uuid)},
|
||||
),
|
||||
{"hidden": "delete"},
|
||||
)
|
||||
|
||||
self.assertEqual(self.user1_default_package.rules.count(), 0)
|
||||
|
||||
@ -11,70 +11,81 @@ class UserViewTest(TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(UserViewTest, cls).setUpClass()
|
||||
cls.user = User.objects.get(username='anonymous')
|
||||
cls.package = PackageManager.create_package(cls.user, 'Anon Test Package', 'No Desc')
|
||||
cls.BBD_SUBSET = Package.objects.get(name='Fixtures')
|
||||
cls.user = User.objects.get(username="anonymous")
|
||||
cls.package = PackageManager.create_package(cls.user, "Anon Test Package", "No Desc")
|
||||
cls.BBD_SUBSET = Package.objects.get(name="Fixtures")
|
||||
|
||||
def test_login_with_valid_credentials(self):
|
||||
response = self.client.post(reverse("login"), {
|
||||
"username": "user0",
|
||||
"password": 'SuperSafe',
|
||||
})
|
||||
response = self.client.post(
|
||||
reverse("login"),
|
||||
{
|
||||
"username": "user0",
|
||||
"password": "SuperSafe",
|
||||
},
|
||||
)
|
||||
self.assertRedirects(response, reverse("index"))
|
||||
self.assertTrue(response.wsgi_request.user.is_authenticated)
|
||||
|
||||
def test_login_with_invalid_credentials(self):
|
||||
response = self.client.post(reverse("login"), {
|
||||
"username": "user0",
|
||||
"password": "wrongpassword",
|
||||
})
|
||||
response = self.client.post(
|
||||
reverse("login"),
|
||||
{
|
||||
"username": "user0",
|
||||
"password": "wrongpassword",
|
||||
},
|
||||
)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertFalse(response.wsgi_request.user.is_authenticated)
|
||||
|
||||
def test_register(self):
|
||||
response = self.client.post(reverse("register"), {
|
||||
"username": "user1",
|
||||
"email": "user1@envipath.com",
|
||||
"password": "SuperSafe",
|
||||
"rpassword": "SuperSafe",
|
||||
})
|
||||
response = self.client.post(
|
||||
reverse("register"),
|
||||
{
|
||||
"username": "user1",
|
||||
"email": "user1@envipath.com",
|
||||
"password": "SuperSafe",
|
||||
"rpassword": "SuperSafe",
|
||||
},
|
||||
)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
# TODO currently fails as the fixture does not provide a global setting...
|
||||
self.assertContains(response, "Registration failed!")
|
||||
|
||||
def test_register_password_mismatch(self):
|
||||
response = self.client.post(reverse("register"), {
|
||||
"username": "user1",
|
||||
"email": "user1@envipath.com",
|
||||
"password": "SuperSafe",
|
||||
"rpassword": "SuperSaf3",
|
||||
})
|
||||
response = self.client.post(
|
||||
reverse("register"),
|
||||
{
|
||||
"username": "user1",
|
||||
"email": "user1@envipath.com",
|
||||
"password": "SuperSafe",
|
||||
"rpassword": "SuperSaf3",
|
||||
},
|
||||
)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertContains(response, "Registration failed, provided passwords differ")
|
||||
|
||||
def test_logout(self):
|
||||
response = self.client.post(reverse("login"), {
|
||||
"username": "user0",
|
||||
"password": 'SuperSafe',
|
||||
"login": "true"
|
||||
})
|
||||
response = self.client.post(
|
||||
reverse("login"), {"username": "user0", "password": "SuperSafe", "login": "true"}
|
||||
)
|
||||
self.assertTrue(response.wsgi_request.user.is_authenticated)
|
||||
|
||||
response = self.client.post(reverse('logout'), {
|
||||
"logout": "true",
|
||||
})
|
||||
response = self.client.post(
|
||||
reverse("logout"),
|
||||
{
|
||||
"logout": "true",
|
||||
},
|
||||
)
|
||||
self.assertFalse(response.wsgi_request.user.is_authenticated)
|
||||
|
||||
def test_next_param_properly_handled(self):
|
||||
response = self.client.get(reverse('packages'))
|
||||
response = self.client.get(reverse("packages"))
|
||||
|
||||
self.assertRedirects(response, f"{reverse('login')}/?next=/package")
|
||||
|
||||
response = self.client.post(reverse('login'), {
|
||||
"username": "user0",
|
||||
"password": 'SuperSafe',
|
||||
"login": "true",
|
||||
"next": "/package"
|
||||
})
|
||||
response = self.client.post(
|
||||
reverse("login"),
|
||||
{"username": "user0", "password": "SuperSafe", "login": "true", "next": "/package"},
|
||||
)
|
||||
|
||||
self.assertRedirects(response, reverse('packages'))
|
||||
self.assertRedirects(response, reverse("packages"))
|
||||
|
||||
Reference in New Issue
Block a user