diff --git a/core/signals.py b/core/signals.py index c98db4e8e6..99f22c4cd1 100644 --- a/core/signals.py +++ b/core/signals.py @@ -18,7 +18,7 @@ def update_repository( log.info(f"Signal triggered for repository {instance.repoid}") created: bool = kwargs["created"] changes: Dict[str, Any] = instance.tracker.changed() - tracked_fields: List[str] = ["name", "upload_token"] + tracked_fields: List[str] = ["name", "upload_token", "activated", "active"] if created or any([field in changes for field in tracked_fields]): data = { diff --git a/core/tests/test_signals.py b/core/tests/test_signals.py index add2422f03..569959ee38 100644 --- a/core/tests/test_signals.py +++ b/core/tests/test_signals.py @@ -10,7 +10,9 @@ def test_shelter_repo_sync(mocker): publish = mocker.patch("google.cloud.pubsub_v1.PublisherClient.publish") # this triggers the publish via Django signals - repo = RepositoryFactory(repoid=91728376, author=OwnerFactory(ownerid=555)) + repo = RepositoryFactory( + repoid=91728376, author=OwnerFactory(ownerid=555), active=False, activated=False + ) # triggers publish on create publish.assert_has_calls( @@ -38,13 +40,27 @@ def test_shelter_repo_sync(mocker): b'{"type": "repo", "sync": "one", "id": 91728376}', ) + # Does not trigger another publish with untracked field repo.message = "foo" repo.save() publish_calls = publish.call_args_list - # does not trigger another publish assert len(publish_calls) == 3 + # Triggers call when active is changed + repo.active = True + repo.save() + + publish_calls = publish.call_args_list + assert len(publish_calls) == 4 + + # Triggers call when activated is changed + repo.activated = True + repo.save() + + publish_calls = publish.call_args_list + assert len(publish_calls) == 5 + @pytest.mark.django_db def test_shelter_commit_sync(mocker):