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 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)
|
||||
|
||||
Reference in New Issue
Block a user