From 53128da8342a7885b190f855d73e1a2f67b635a2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Herv=C3=A9=20M=C3=A9nager?= <herve.menager@pasteur.fr>
Date: Thu, 26 Dec 2019 14:48:56 +0100
Subject: [PATCH] fix bug introduced by removing "validated" from
 CompoundManager

bug introduced in 0ab3843134956137e028ff40686c742e2fda8a1b and
visible here: https://gitlab.pasteur.fr/ippidb/ippidb-web/-/jobs/46382
WIP on #68
---
 ippisite/ippidb/models.py           | 15 +++++++++++++++
 ippisite/ippidb/tests_contribute.py |  6 +++---
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/ippisite/ippidb/models.py b/ippisite/ippidb/models.py
index 6a886aea..d1d5f473 100644
--- a/ippisite/ippidb/models.py
+++ b/ippisite/ippidb/models.py
@@ -479,6 +479,11 @@ class PpiComplex(models.Model):
 
 class CompoundsManager(models.Manager):
     def for_user(self, current_user):
+        """
+        Get compounds visible to a given user
+        i.e. validated or created by the user or
+        all of them if the user is an admin
+        """
         qs = self.get_queryset()
         if current_user.is_anonymous:
             qs = qs.exclude(compoundaction__ppi__contribution__validated=False)
@@ -489,6 +494,16 @@ class CompoundsManager(models.Manager):
             )
         return qs
 
+    def validated(self):
+        """
+        Get validated compounds
+        """
+        return (
+            super()
+            .get_queryset()
+            .exclude(compoundaction__ppi__contribution__validated=False)
+        )
+
 
 class Compound(AutoFillableModel):
     """
diff --git a/ippisite/ippidb/tests_contribute.py b/ippisite/ippidb/tests_contribute.py
index fdb39cc1..385dcefd 100644
--- a/ippisite/ippidb/tests_contribute.py
+++ b/ippisite/ippidb/tests_contribute.py
@@ -131,8 +131,8 @@ class ContributionViewsTestCase(TestCase):
                 "Compounds count",
             ),
             (
-                models.Compound.validated.count,
-                models.Compound.validated.count(),
+                models.Compound.objects.validated().count,
+                models.Compound.objects.validated().count(),
                 "Validated Compounds count",
             ),
             (
@@ -164,7 +164,7 @@ class ContributionViewsTestCase(TestCase):
             self.assertEqual(fcn(), results, msg=msg)
         post_validation_expected_equals = [
             (
-                models.Compound.validated.count,
+                models.Compound.objects.validated().count,
                 models.Compound.objects.count(),
                 "Validated Compounds count",
             )
-- 
GitLab