55
66
77import os
8+ import importlib
89from io import StringIO
910
1011from unittest import mock
1112from ddt import ddt
1213from django .contrib .sites .models import Site
1314from django .core .management import call_command
1415from django .core .management .base import CommandError
16+ from django .db .models import signals
1517from requests import exceptions
1618from requests .models import Response
1719
1820from openedx .core .djangolib .testing .utils import CacheIsolationTestCase , skip_unless_lms
21+ from common .djangoapps .third_party_auth .models import SAMLConfiguration
22+ from common .djangoapps .third_party_auth .signals import handlers
1923from common .djangoapps .third_party_auth .tests .factories import SAMLConfigurationFactory , SAMLProviderConfigFactory
2024
2125
@@ -60,6 +64,10 @@ def setUp(self):
6064 """
6165 super ().setUp ()
6266
67+ # Disconnect signal handlers to prevent automatic provider config updates during test setup
68+ # These tests manually create multiple versions of configs and expect specific counts
69+ signals .post_save .disconnect (sender = SAMLConfiguration )
70+
6371 self .stdout = StringIO ()
6472 self .site = Site .objects .get_current ()
6573 self .other_site = Site .objects .create (domain = 'other.example.com' , name = 'Other Site' )
@@ -81,6 +89,14 @@ def setUp(self):
8189 metadata_source = 'https://www.testshib.org/metadata/testshib-providers.xml' ,
8290 )
8391
92+ def tearDown (self ):
93+ """
94+ Reconnect signal handlers after tests complete.
95+ """
96+ # Reconnect signals - Django will automatically re-register the handlers
97+ importlib .reload (handlers )
98+ super ().tearDown ()
99+
84100 def _setup_test_configs_for_run_checks (self ):
85101 """
86102 Helper method to create SAML configurations for run-checks tests.
0 commit comments