forked from enviPath/enviPy
[Feature] Alias Support (#151)
Fixes #149 Co-authored-by: Tim Lorsbach <tim@lorsba.ch> Reviewed-on: enviPath/enviPy#151
This commit is contained in:
@ -74,6 +74,7 @@ class MultiGenTest(TestCase):
|
||||
|
||||
shallow_pathway = graph_from_pathway(SPathway.from_pathway(pathway))
|
||||
pathway = graph_from_pathway(pathway)
|
||||
|
||||
if not graphs_equal(shallow_pathway, pathway):
|
||||
print("\n\nS", shallow_pathway.adj)
|
||||
print("\n\nPW", pathway.adj)
|
||||
|
||||
@ -340,3 +340,57 @@ class CompoundViewTest(TestCase):
|
||||
)
|
||||
|
||||
self.assertEqual(self.user1_default_package.compounds.count(), 0)
|
||||
|
||||
def test_set_aliases(self):
|
||||
alias_1 = "Alias 1"
|
||||
alias_2 = "Alias 2"
|
||||
|
||||
response = self.client.post(
|
||||
reverse("compounds"),
|
||||
{
|
||||
"compound-name": "1,2-Dichloroethane",
|
||||
"compound-description": "Eawag BBD compound c0001",
|
||||
"compound-smiles": "C(CCl)Cl",
|
||||
},
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 302)
|
||||
compound_url = response.url
|
||||
|
||||
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)},
|
||||
),
|
||||
{"aliases": [alias_1, alias_2]},
|
||||
)
|
||||
|
||||
c = Compound.objects.get(url=compound_url)
|
||||
self.assertEqual(len(c.aliases), 2)
|
||||
|
||||
response = self.client.post(
|
||||
reverse(
|
||||
"package compound detail",
|
||||
kwargs={"package_uuid": str(c.package.uuid), "compound_uuid": str(c.uuid)},
|
||||
),
|
||||
{"aliases": [alias_1]},
|
||||
)
|
||||
|
||||
c = Compound.objects.get(url=compound_url)
|
||||
self.assertEqual(len(c.aliases), 1)
|
||||
|
||||
response = self.client.post(
|
||||
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
|
||||
"aliases": ""
|
||||
},
|
||||
)
|
||||
|
||||
c = Compound.objects.get(url=compound_url)
|
||||
self.assertEqual(len(c.aliases), 0)
|
||||
|
||||
@ -112,3 +112,57 @@ class PathwayViewTest(TestCase):
|
||||
predicted_nodes.add(n.default_node_label.smiles)
|
||||
|
||||
self.assertEqual(first_level_nodes, predicted_nodes)
|
||||
|
||||
def test_set_aliases(self):
|
||||
alias_1 = "Alias 1"
|
||||
alias_2 = "Alias 2"
|
||||
|
||||
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",
|
||||
},
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 302)
|
||||
pathway_url = response.url
|
||||
pw = Pathway.objects.get(url=pathway_url)
|
||||
|
||||
response = self.client.post(
|
||||
reverse(
|
||||
"package pathway detail",
|
||||
kwargs={"package_uuid": str(pw.package.uuid), "pathway_uuid": str(pw.uuid)},
|
||||
),
|
||||
{"aliases": [alias_1, alias_2]},
|
||||
)
|
||||
|
||||
pw = Pathway.objects.get(url=pathway_url)
|
||||
self.assertEqual(len(pw.aliases), 2)
|
||||
|
||||
response = self.client.post(
|
||||
reverse(
|
||||
"package pathway detail",
|
||||
kwargs={"package_uuid": str(pw.package.uuid), "pathway_uuid": str(pw.uuid)},
|
||||
),
|
||||
{"aliases": [alias_1]},
|
||||
)
|
||||
|
||||
pw = Pathway.objects.get(url=pathway_url)
|
||||
self.assertEqual(len(pw.aliases), 1)
|
||||
|
||||
response = self.client.post(
|
||||
reverse(
|
||||
"package pathway detail",
|
||||
kwargs={"package_uuid": str(pw.package.uuid), "pathway_uuid": str(pw.uuid)},
|
||||
),
|
||||
{
|
||||
# We have to set an empty string to avoid that the parameter is removed
|
||||
"aliases": ""
|
||||
},
|
||||
)
|
||||
|
||||
pw = Pathway.objects.get(url=pathway_url)
|
||||
self.assertEqual(len(pw.aliases), 0)
|
||||
|
||||
@ -335,3 +335,56 @@ class ReactionViewTest(TestCase):
|
||||
)
|
||||
|
||||
self.assertEqual(self.user1_default_package.reactions.count(), 0)
|
||||
|
||||
def test_set_aliases(self):
|
||||
alias_1 = "Alias 1"
|
||||
alias_2 = "Alias 2"
|
||||
|
||||
response = self.client.post(
|
||||
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)
|
||||
reaction_url = response.url
|
||||
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)},
|
||||
),
|
||||
{"aliases": [alias_1, alias_2]},
|
||||
)
|
||||
|
||||
r = Reaction.objects.get(url=reaction_url)
|
||||
self.assertEqual(len(r.aliases), 2)
|
||||
|
||||
response = self.client.post(
|
||||
reverse(
|
||||
"package reaction detail",
|
||||
kwargs={"package_uuid": str(r.package.uuid), "reaction_uuid": str(r.uuid)},
|
||||
),
|
||||
{"aliases": [alias_1]},
|
||||
)
|
||||
|
||||
r = Reaction.objects.get(url=reaction_url)
|
||||
self.assertEqual(len(r.aliases), 1)
|
||||
|
||||
response = self.client.post(
|
||||
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
|
||||
"aliases": ""
|
||||
},
|
||||
)
|
||||
|
||||
r = Reaction.objects.get(url=reaction_url)
|
||||
self.assertEqual(len(r.aliases), 0)
|
||||
|
||||
@ -258,3 +258,57 @@ class RuleViewTest(TestCase):
|
||||
)
|
||||
|
||||
self.assertEqual(self.user1_default_package.rules.count(), 0)
|
||||
|
||||
def test_set_aliases(self):
|
||||
alias_1 = "Alias 1"
|
||||
alias_2 = "Alias 2"
|
||||
|
||||
response = self.client.post(
|
||||
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)
|
||||
rule_url = response.url
|
||||
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)},
|
||||
),
|
||||
{"aliases": [alias_1, alias_2]},
|
||||
)
|
||||
|
||||
r = Rule.objects.get(url=rule_url)
|
||||
self.assertEqual(len(r.aliases), 2)
|
||||
|
||||
response = self.client.post(
|
||||
reverse(
|
||||
"package rule detail",
|
||||
kwargs={"package_uuid": str(r.package.uuid), "rule_uuid": str(r.uuid)},
|
||||
),
|
||||
{"aliases": [alias_1]},
|
||||
)
|
||||
|
||||
r = Rule.objects.get(url=rule_url)
|
||||
self.assertEqual(len(r.aliases), 1)
|
||||
|
||||
response = self.client.post(
|
||||
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
|
||||
"aliases": ""
|
||||
},
|
||||
)
|
||||
|
||||
r = Rule.objects.get(url=rule_url)
|
||||
self.assertEqual(len(r.aliases), 0)
|
||||
|
||||
Reference in New Issue
Block a user