[Patchew-devel] [PATCH 2/3] change "maintainer" from property to many-to-many relation

Paolo Bonzini pbonzini at redhat.com
Fri Mar 9 07:11:25 UTC 2018


On 08/03/2018 10:39, Paolo Bonzini wrote:
> diff --git a/api/models.py b/api/models.py
> index 0c8688a..180d6e3 100644
> --- a/api/models.py
> +++ b/api/models.py
> @@ -75,6 +75,7 @@ class Project(models.Model):
>                                         project belongs to. The parent must be a
>                                         top project which has
>                                         parent_project=NULL""")
> +    maintainers = models.ManyToManyField(User,blank=True)
>  
>      def __str__(self):
>          return self.name
> @@ -125,7 +126,8 @@ class Project(models.Model):
>      def maintained_by(self, user):
>          if user.is_superuser:
>              return True
> -        if user.username in self.get_property("maintainers", []):
> +        if self.maintainers.filter(id=user.id).exists() or \
> +                self.get_property("maintainers", []):

I ate a "user.username in" here.  Since I've pushed patch 1 together
with your Travis check, I'll resend a new version today or next Monday.

Thanks,

Paolo

>              return True
>          return False
>  
> diff --git a/tests/patchewtest.py b/tests/patchewtest.py
> index 00ecddb..1b0a867 100644
> --- a/tests/patchewtest.py
> +++ b/tests/patchewtest.py
> @@ -55,6 +55,7 @@ class PatchewTestCase(django.test.LiveServerTestCase):
>          user = User.objects.create_superuser(username or self.user,
>                                               self.email,
>                                               password or self.password)
> +        return user
>  
>      def create_user(self, username=None, password=None, groups=[]):
>          user = User.objects.create_user(username or self.user,
> @@ -63,6 +64,7 @@ class PatchewTestCase(django.test.LiveServerTestCase):
>          if groups:
>              user.groups = [Group.objects.get_or_create(name=g)[0] for g in groups]
>              user.save()
> +        return user
>  
>      def cli(self, argv):
>          """Run patchew-cli command and return (retcode, stdout, stderr)"""
> diff --git a/tests/test_project.py b/tests/test_project.py
> index 63ca709..25b9661 100755
> --- a/tests/test_project.py
> +++ b/tests/test_project.py
> @@ -15,7 +15,7 @@ from patchewtest import PatchewTestCase, main
>  class ProjectTest(PatchewTestCase):
>  
>      def setUp(self):
> -        self.create_superuser()
> +        self.admin_user = self.create_superuser()
>  
>      def test_empty(self):
>          projects = self.get_projects()
> @@ -61,5 +61,23 @@ class ProjectTest(PatchewTestCase):
>          self.assertNotEqual(r, 0)
>          self.assertNotEqual(b, "")
>  
> +    def test_maintainers(self):
> +        p = self.add_project("TestProject")
> +        u1 = self.create_user(username='buddy', password='abc')
> +        u2 = self.create_user(username='mirage', password='def')
> +        u2.is_staff = True
> +        u2.save()
> +        p.maintainers.add(u1)
> +        self.assertTrue(p.maintained_by(self.admin_user))
> +        self.assertTrue(p.maintained_by(u1))
> +        self.assertFalse(p.maintained_by(u2))
> +        p.maintainers.add(u2)
> +        self.assertTrue(p.maintained_by(u1))
> +        self.assertTrue(p.maintained_by(u2))
> +        p.maintainers.clear()
> +        self.assertTrue(p.maintained_by(self.admin_user))
> +        self.assertFalse(p.maintained_by(u1))
> +        self.assertFalse(p.maintained_by(u2))
> +
>  if __name__ == '__main__':
>      main()
> 




More information about the Patchew-devel mailing list