diff --git a/epdb/logic.py b/epdb/logic.py
index be7ecdee..530ebc51 100644
--- a/epdb/logic.py
+++ b/epdb/logic.py
@@ -691,6 +691,7 @@ class PackageManager(object):
struc.uuid = UUID(structure["id"].split("/")[-1]) if keep_ids else uuid4()
struc.name = structure["name"]
struc.description = structure["description"]
+ struc.aliases = structure.get("aliases", [])
struc.smiles = structure["smiles"]
struc.save()
@@ -728,6 +729,7 @@ class PackageManager(object):
r.package = pack
r.name = rule["name"]
r.description = rule["description"]
+ r.aliases = rule.get("aliases", [])
r.smirks = rule["smirks"]
r.reactant_filter_smarts = rule.get("reactantFilterSmarts", None)
r.product_filter_smarts = rule.get("productFilterSmarts", None)
@@ -747,6 +749,7 @@ class PackageManager(object):
r.uuid = UUID(par_rule["id"].split("/")[-1]) if keep_ids else uuid4()
r.name = par_rule["name"]
r.description = par_rule["description"]
+ r.aliases = par_rule.get("aliases", [])
r.save()
mapping[par_rule["id"]] = r.uuid
@@ -766,6 +769,7 @@ class PackageManager(object):
r.uuid = UUID(seq_rule["id"].split("/")[-1]) if keep_ids else uuid4()
r.name = seq_rule["name"]
r.description = seq_rule["description"]
+ r.aliases = seq_rule.get("aliases", [])
r.save()
mapping[seq_rule["id"]] = r.uuid
@@ -791,6 +795,7 @@ class PackageManager(object):
r.uuid = UUID(reaction["id"].split("/")[-1]) if keep_ids else uuid4()
r.name = reaction["name"]
r.description = reaction["description"]
+ r.aliases = reaction.get("aliases", [])
r.medlinereferences = (reaction["medlinereferences"],)
r.multi_step = True if reaction["multistep"] == "true" else False
r.save()
@@ -824,6 +829,7 @@ class PackageManager(object):
pw.uuid = UUID(pathway["id"].split("/")[-1]) if keep_ids else uuid4()
pw.name = pathway["name"]
pw.description = pathway["description"]
+ pw.aliases = pathway.get("aliases", [])
pw.save()
mapping[pathway["id"]] = pw.uuid
@@ -836,6 +842,8 @@ class PackageManager(object):
n = Node()
n.uuid = UUID(node["id"].split("/")[-1]) if keep_ids else uuid4()
n.name = node["name"]
+ n.description = node.get("description")
+ n.aliases = node.get("aliases", [])
n.pathway = pw
n.depth = node["depth"]
n.default_node_label = CompoundStructure.objects.get(
@@ -862,6 +870,7 @@ class PackageManager(object):
e.name = edge["name"]
e.pathway = pw
e.description = edge["description"]
+ e.aliases = edge.get("aliases", [])
e.edge_label = Reaction.objects.get(uuid=mapping[edge["edgeLabel"]["id"]])
e.save()
diff --git a/epdb/views.py b/epdb/views.py
index b13c0b39..b0ff39dc 100644
--- a/epdb/views.py
+++ b/epdb/views.py
@@ -300,6 +300,14 @@ def set_scenarios(current_user, attach_object, scenario_urls: List[str]):
attach_object.set_scenarios(scens)
+def set_aliases(current_user, attach_object, aliases: List[str]):
+ if aliases == [""]:
+ aliases = []
+
+ attach_object.aliases = aliases
+ attach_object.save()
+
+
def copy_object(current_user, target_package: "Package", source_object_url: str):
# Ensures that source is readable
source_package = PackageManager.get_package_by_url(current_user, source_object_url)
@@ -1160,10 +1168,19 @@ def package_compound(request, package_uuid, compound_uuid):
if "selected-scenarios" in request.POST:
selected_scenarios = request.POST.getlist("selected-scenarios")
-
set_scenarios(current_user, current_compound, selected_scenarios)
return redirect(current_compound.url)
+ if "aliases" in request.POST:
+ aliases = request.POST.getlist("aliases")
+
+ try:
+ set_aliases(current_user, current_compound, aliases)
+ except Exception as e:
+ return JsonResponse({"error": str(e)}, status=400)
+
+ return JsonResponse({"success": current_compound.url})
+
new_compound_name = request.POST.get("compound-name", "").strip()
new_compound_description = request.POST.get("compound-description", "").strip()
@@ -1311,6 +1328,16 @@ def package_compound_structure(request, package_uuid, compound_uuid, structure_u
set_scenarios(current_user, current_structure, selected_scenarios)
return redirect(current_structure.url)
+ if "aliases" in request.POST:
+ aliases = request.POST.getlist("aliases")
+
+ try:
+ set_aliases(current_user, current_structure, aliases)
+ except Exception as e:
+ return JsonResponse({"error": str(e)}, status=400)
+
+ return JsonResponse({"success": current_structure.url})
+
selected_database = request.POST.get("selected-database", "").strip()
external_identifier = request.POST.get("identifier", "").strip()
@@ -1472,6 +1499,16 @@ def package_rule(request, package_uuid, rule_uuid):
set_scenarios(current_user, current_rule, selected_scenarios)
return redirect(current_rule.url)
+ if "aliases" in request.POST:
+ aliases = request.POST.getlist("aliases")
+
+ try:
+ set_aliases(current_user, current_rule, aliases)
+ except Exception as e:
+ return JsonResponse({"error": str(e)}, status=400)
+
+ return JsonResponse({"success": current_rule.url})
+
rule_name = request.POST.get("rule-name", "").strip()
rule_description = request.POST.get("rule-description", "").strip()
@@ -1588,6 +1625,16 @@ def package_reaction(request, package_uuid, reaction_uuid):
set_scenarios(current_user, current_reaction, selected_scenarios)
return redirect(current_reaction.url)
+ if "aliases" in request.POST:
+ aliases = request.POST.getlist("aliases")
+
+ try:
+ set_aliases(current_user, current_reaction, aliases)
+ except Exception as e:
+ return JsonResponse({"error": str(e)}, status=400)
+
+ return JsonResponse({"success": current_reaction.url})
+
new_reaction_name = request.POST.get("reaction-name", "").strip()
new_reaction_description = request.POST.get("reaction-description", "").strip()
@@ -1807,6 +1854,16 @@ def package_pathway(request, package_uuid, pathway_uuid):
set_scenarios(current_user, current_pathway, selected_scenarios)
return redirect(current_pathway.url)
+ if "aliases" in request.POST:
+ aliases = request.POST.getlist("aliases")
+
+ try:
+ set_aliases(current_user, current_pathway, aliases)
+ except Exception as e:
+ return JsonResponse({"error": str(e)}, status=400)
+
+ return JsonResponse({"success": current_pathway.url})
+
pathway_name = request.POST.get("pathway-name")
pathway_description = request.POST.get("pathway-description")
@@ -1957,6 +2014,16 @@ def package_pathway_node(request, package_uuid, pathway_uuid, node_uuid):
set_scenarios(current_user, current_node, selected_scenarios)
return redirect(current_node.url)
+ if "aliases" in request.POST:
+ aliases = request.POST.getlist("aliases")
+
+ try:
+ set_aliases(current_user, current_node, aliases)
+ except Exception as e:
+ return JsonResponse({"error": str(e)}, status=400)
+
+ return JsonResponse({"success": current_node.url})
+
return HttpResponseBadRequest()
else:
return HttpResponseNotAllowed(["GET", "POST"])
@@ -2073,6 +2140,16 @@ def package_pathway_edge(request, package_uuid, pathway_uuid, edge_uuid):
set_scenarios(current_user, current_edge, selected_scenarios)
return redirect(current_edge.url)
+ if "aliases" in request.POST:
+ aliases = request.POST.getlist("aliases")
+
+ try:
+ set_aliases(current_user, current_edge, aliases)
+ except Exception as e:
+ return JsonResponse({"error": str(e)}, status=400)
+
+ return JsonResponse({"success": current_edge.url})
+
return HttpResponseBadRequest()
else:
diff --git a/templates/actions/objects/compound.html b/templates/actions/objects/compound.html
index 137cb748..c56918b5 100644
--- a/templates/actions/objects/compound.html
+++ b/templates/actions/objects/compound.html
@@ -3,6 +3,10 @@
Edit Compound
+
+
+ Set Aliases
+
Add Structure
@@ -25,4 +29,4 @@
Delete Compound
-{% endif %}
\ No newline at end of file
+{% endif %}
diff --git a/templates/actions/objects/compound_structure.html b/templates/actions/objects/compound_structure.html
index 46cd8c11..45647405 100644
--- a/templates/actions/objects/compound_structure.html
+++ b/templates/actions/objects/compound_structure.html
@@ -3,6 +3,10 @@
Edit Compound Structure
+
+
+ Set Aliases
+
Set Scenarios
@@ -15,4 +19,4 @@
Delete Compound Structure
-{% endif %}
\ No newline at end of file
+{% endif %}
diff --git a/templates/actions/objects/edge.html b/templates/actions/objects/edge.html
index 49642fcc..e595a248 100644
--- a/templates/actions/objects/edge.html
+++ b/templates/actions/objects/edge.html
@@ -1,4 +1,8 @@
{% if meta.can_edit %}
+
+
+ Set Aliases
+
Set Scenarios
diff --git a/templates/actions/objects/node.html b/templates/actions/objects/node.html
index 487c1435..605cacf6 100644
--- a/templates/actions/objects/node.html
+++ b/templates/actions/objects/node.html
@@ -3,6 +3,10 @@
Edit Node
+
+
+ Set Aliases
+
Set Scenarios
diff --git a/templates/actions/objects/pathway.html b/templates/actions/objects/pathway.html
index 4faaea4f..28f74443 100644
--- a/templates/actions/objects/pathway.html
+++ b/templates/actions/objects/pathway.html
@@ -31,6 +31,10 @@
Set Scenarios
+
+
+ Set Aliases
+
{# #}
{# #}
{# Calculate Compound Properties#}
@@ -48,4 +52,4 @@
Delete Pathway
-{% endif %}
\ No newline at end of file
+{% endif %}
diff --git a/templates/actions/objects/reaction.html b/templates/actions/objects/reaction.html
index 4ff845dd..73484600 100644
--- a/templates/actions/objects/reaction.html
+++ b/templates/actions/objects/reaction.html
@@ -3,6 +3,10 @@
Edit Reaction
+
+
+ Set Aliases
+
Set Scenarios
@@ -21,4 +25,4 @@
Delete Reaction
-{% endif %}
\ No newline at end of file
+{% endif %}
diff --git a/templates/actions/objects/rule.html b/templates/actions/objects/rule.html
index 416883ed..1b7b85c3 100644
--- a/templates/actions/objects/rule.html
+++ b/templates/actions/objects/rule.html
@@ -3,6 +3,10 @@
Edit Rule
+
+
+ Set Aliases
+
Set Scenarios
@@ -17,4 +21,4 @@
Delete Rule
-{% endif %}
\ No newline at end of file
+{% endif %}
diff --git a/templates/modals/collections/import_legacy_package_modal.html b/templates/modals/collections/import_legacy_package_modal.html
index d4101d7d..d4914541 100644
--- a/templates/modals/collections/import_legacy_package_modal.html
+++ b/templates/modals/collections/import_legacy_package_modal.html
@@ -15,12 +15,12 @@
enctype="multipart/form-data">
{% csrf_token %}
-
diff --git a/templates/modals/objects/generic_set_aliases_modal.html b/templates/modals/objects/generic_set_aliases_modal.html
new file mode 100644
index 00000000..7c882134
--- /dev/null
+++ b/templates/modals/objects/generic_set_aliases_modal.html
@@ -0,0 +1,169 @@
+{% load static %}
+
+
+
+
+
diff --git a/templates/modals/objects/generic_set_scenario_modal.html b/templates/modals/objects/generic_set_scenario_modal.html
index f4616a75..42ec3b16 100644
--- a/templates/modals/objects/generic_set_scenario_modal.html
+++ b/templates/modals/objects/generic_set_scenario_modal.html
@@ -64,8 +64,8 @@
$('#set_scenario_modal_form_submit').on('click', function (e) {
e.preventDefault();
- if ($('##scenario-select').val().length == 0) {
- $('##scenario-select').val([''])
+ if ($('#scenario-select').val().length == 0) {
+ $('#scenario-select').val([''])
}
$('#set_scenario_modal_form').submit();
});
diff --git a/templates/objects/composite_rule.html b/templates/objects/composite_rule.html
index 2fe741b5..4e5aaafe 100644
--- a/templates/objects/composite_rule.html
+++ b/templates/objects/composite_rule.html
@@ -2,12 +2,13 @@
{% block content %}
-{% block action_modals %}
-{% include "modals/objects/edit_rule_modal.html" %}
-{% include "modals/objects/generic_set_scenario_modal.html" %}
-{% include "modals/objects/generic_copy_object_modal.html" %}
-{% include "modals/objects/generic_delete_modal.html" %}
-{% endblock action_modals %}
+ {% block action_modals %}
+ {% include "modals/objects/edit_rule_modal.html" %}
+ {% include "modals/objects/generic_set_aliases_modal.html" %}
+ {% include "modals/objects/generic_set_scenario_modal.html" %}
+ {% include "modals/objects/generic_copy_object_modal.html" %}
+ {% include "modals/objects/generic_delete_modal.html" %}
+ {% endblock action_modals %}
@@ -32,6 +33,23 @@
+ {% if rule.aliases %}
+
+
+
+
+ {% for alias in rule.aliases %}
+
{{ alias }}
+ {% endfor %}
+
+
+ {% endif %}
+
diff --git a/templates/objects/compound.html b/templates/objects/compound.html
index 66a98bbe..98083ca6 100644
--- a/templates/objects/compound.html
+++ b/templates/objects/compound.html
@@ -4,6 +4,7 @@
{% block action_modals %}
{% include "modals/objects/edit_compound_modal.html" %}
+ {% include "modals/objects/generic_set_aliases_modal.html" %}
{% include "modals/objects/add_structure_modal.html" %}
{% include "modals/objects/generic_set_scenario_modal.html" %}
{% include "modals/objects/generic_set_external_reference_modal.html" %}
@@ -37,6 +38,23 @@
+ {% if compound.aliases %}
+
+
+
+
+ {% for alias in compound.aliases %}
+
{{ alias }}
+ {% endfor %}
+
+
+ {% endif %}
+
diff --git a/templates/objects/compound_structure.html b/templates/objects/compound_structure.html
index 3b4b7416..258a797a 100644
--- a/templates/objects/compound_structure.html
+++ b/templates/objects/compound_structure.html
@@ -2,12 +2,13 @@
{% block content %}
-{% block action_modals %}
-{% include "modals/objects/edit_compound_structure_modal.html" %}
-{% include "modals/objects/generic_set_scenario_modal.html" %}
-{% include "modals/objects/generic_set_external_reference_modal.html" %}
-{% include "modals/objects/generic_delete_modal.html" %}
-{% endblock action_modals %}
+ {% block action_modals %}
+ {% include "modals/objects/edit_compound_structure_modal.html" %}
+ {% include "modals/objects/generic_set_aliases_modal.html" %}
+ {% include "modals/objects/generic_set_scenario_modal.html" %}
+ {% include "modals/objects/generic_set_external_reference_modal.html" %}
+ {% include "modals/objects/generic_delete_modal.html" %}
+ {% endblock action_modals %}
@@ -33,34 +34,52 @@
-
+
{{ compound_structure.as_svg|safe }}
+
-
+
{{ compound_structure.smiles }}
+ {% if compound_structure.aliases %}
+
+
+
+
+ {% for alias in compound_structure.aliases %}
+
{{ alias }}
+ {% endfor %}
+
+
+ {% endif %}
+
{% if compound_structure.scenarios.all %}
diff --git a/templates/objects/edge.html b/templates/objects/edge.html
index 6e2a80dc..6ddab061 100644
--- a/templates/objects/edge.html
+++ b/templates/objects/edge.html
@@ -4,6 +4,7 @@
{% block action_modals %}
{# {% include "modals/objects/edit_edge_modal.html" %}#}
+ {% include "modals/objects/generic_set_aliases_modal.html" %}
{% include "modals/objects/generic_set_scenario_modal.html" %}
{% include "modals/objects/generic_delete_modal.html" %}
{% endblock action_modals %}
@@ -39,6 +40,23 @@
+ {% if edge.aliases %}
+
+
+
+
+ {% for alias in edge.aliases %}
+
{{ alias }}
+ {% endfor %}
+
+
+ {% endif %}
+
diff --git a/templates/objects/node.html b/templates/objects/node.html
index bc4ceee1..55069fb9 100644
--- a/templates/objects/node.html
+++ b/templates/objects/node.html
@@ -4,6 +4,7 @@
{% block action_modals %}
{% include "modals/objects/edit_node_modal.html" %}
+ {% include "modals/objects/generic_set_aliases_modal.html" %}
{% include "modals/objects/generic_set_scenario_modal.html" %}
{% include "modals/objects/generic_delete_modal.html" %}
{% endblock action_modals %}
@@ -42,6 +43,23 @@
+ {% if node.aliases %}
+
+
+
+
+ {% for alias in node.aliases %}
+
{{ alias }}
+ {% endfor %}
+
+
+ {% endif %}
+
diff --git a/templates/objects/pathway.html b/templates/objects/pathway.html
index 0b83e6fb..40f2d807 100644
--- a/templates/objects/pathway.html
+++ b/templates/objects/pathway.html
@@ -85,6 +85,7 @@
{% include "modals/objects/download_pathway_image_modal.html" %}
{% include "modals/objects/generic_copy_object_modal.html" %}
{% include "modals/objects/edit_pathway_modal.html" %}
+ {% include "modals/objects/generic_set_aliases_modal.html" %}
{% include "modals/objects/generic_set_scenario_modal.html" %}
{% include "modals/objects/delete_pathway_node_modal.html" %}
{% include "modals/objects/delete_pathway_edge_modal.html" %}
@@ -210,6 +211,23 @@
+ {% if pathway.aliases %}
+
+
+
+
+ {% for alias in pathway.aliases %}
+
{{ alias }}
+ {% endfor %}
+
+
+ {% endif %}
+
{% if pathway.scenarios.all %}
diff --git a/templates/objects/reaction.html b/templates/objects/reaction.html
index daed88fb..2a026d22 100644
--- a/templates/objects/reaction.html
+++ b/templates/objects/reaction.html
@@ -4,6 +4,7 @@
{% block action_modals %}
{% include "modals/objects/edit_reaction_modal.html" %}
+ {% include "modals/objects/generic_set_aliases_modal.html" %}
{% include "modals/objects/generic_set_scenario_modal.html" %}
{% include "modals/objects/generic_copy_object_modal.html" %}
{% include "modals/objects/generic_set_external_reference_modal.html" %}
@@ -41,6 +42,23 @@
+ {% if reaction.aliases %}
+
+
+
+
+ {% for alias in reaction.aliases %}
+
{{ alias }}
+ {% endfor %}
+
+
+ {% endif %}
+
diff --git a/templates/objects/simple_rule.html b/templates/objects/simple_rule.html
index d3e30893..cc55d856 100644
--- a/templates/objects/simple_rule.html
+++ b/templates/objects/simple_rule.html
@@ -4,6 +4,7 @@
{% block action_modals %}
{% include "modals/objects/edit_rule_modal.html" %}
+ {% include "modals/objects/generic_set_aliases_modal.html" %}
{% include "modals/objects/generic_set_scenario_modal.html" %}
{% include "modals/objects/generic_copy_object_modal.html" %}
{% include "modals/objects/generic_delete_modal.html" %}
@@ -32,6 +33,23 @@
+ {% if rule.aliases %}
+
+
+
+
+ {% for alias in rule.aliases %}
+
{{ alias }}
+ {% endfor %}
+
+
+ {% endif %}
+
diff --git a/tests/test_multigen_eval.py b/tests/test_multigen_eval.py
index 7959d81c..96cf4c14 100644
--- a/tests/test_multigen_eval.py
+++ b/tests/test_multigen_eval.py
@@ -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)
diff --git a/tests/views/test_compound_views.py b/tests/views/test_compound_views.py
index 731524e2..13b960bf 100644
--- a/tests/views/test_compound_views.py
+++ b/tests/views/test_compound_views.py
@@ -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)
diff --git a/tests/views/test_pathway_views.py b/tests/views/test_pathway_views.py
index 1094bae3..9e64e22f 100644
--- a/tests/views/test_pathway_views.py
+++ b/tests/views/test_pathway_views.py
@@ -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)
diff --git a/tests/views/test_reaction_views.py b/tests/views/test_reaction_views.py
index 1dafa297..2c40ac0b 100644
--- a/tests/views/test_reaction_views.py
+++ b/tests/views/test_reaction_views.py
@@ -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)
diff --git a/tests/views/test_rule_views.py b/tests/views/test_rule_views.py
index 92b0727b..47275172 100644
--- a/tests/views/test_rule_views.py
+++ b/tests/views/test_rule_views.py
@@ -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)