[Feature] Alias Support (#151)

Fixes #149

Co-authored-by: Tim Lorsbach <tim@lorsba.ch>
Reviewed-on: enviPath/enviPy#151
This commit is contained in:
2025-10-09 23:14:34 +13:00
parent afeb56622c
commit 68a3f3b982
25 changed files with 675 additions and 31 deletions

View File

@ -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)