From ade9709d6222c59ab193c367ed8039b5fb068bfc Mon Sep 17 00:00:00 2001 From: Matt Prahl Date: May 17 2017 20:10:23 +0000 Subject: Fix query get_watch_level_on_repo --- diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index 353b296..e978f06 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -3675,7 +3675,7 @@ def get_watch_level_on_repo(session, user, repo, repouser=None, ).filter( model.Watcher.user_id == user_obj.id ).filter( - model.Watcher.project_id == model.Project.id + model.Watcher.project_id == project.id ) watcher = query.first() diff --git a/tests/test_pagure_lib.py b/tests/test_pagure_lib.py index d49b038..5209584 100644 --- a/tests/test_pagure_lib.py +++ b/tests/test_pagure_lib.py @@ -3654,6 +3654,7 @@ class PagureLibtests(tests.Modeltests): self.test_add_group() project = pagure.lib._get_project(self.session, 'test') + project2 = pagure.lib._get_project(self.session, 'test2') # If user not logged in watch_level = pagure.lib.get_watch_level_on_repo( @@ -3738,6 +3739,27 @@ class PagureLibtests(tests.Modeltests): ) self.assertEqual(['issues', 'commits'], watch_level) + # Make sure that when a user watches more than one repo explicitly + # they get the correct watch status + msg = pagure.lib.update_watch_status( + session=self.session, + project=project2, + user='pingou', + watch='1', + ) + self.session.commit() + self.assertEqual( + msg, + 'You are now watching issues and PRs on this project') + + # From watchers table + watch_level = pagure.lib.get_watch_level_on_repo( + session=self.session, + user=user, + repo='test2', + ) + self.assertEqual(['issues'], watch_level) + # Entry into watchers table for just commits msg = pagure.lib.update_watch_status( session=self.session,