Closed uktamjon-komilov closed 1 year ago
In tests.py
you should be able to simply do something like
from dynamic_preferences_registry import global_preferences
class UserRegistrationLoginViewTestCase(APITestCase):
def test_create_user_with_otp_enabled(self):
global_preferences['authentication__registration_otp_enabled'] = True
response = self.client.post(self.url, data=self.valid_payload)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertTrue("message" in response.data)
def test_create_user_with_otp_disabled(self):
global_preferences['authentication__registration_otp_enabled'] = False
response = self.client.post(self.url, data=self.valid_payload)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
self.assertTrue("access" in response.data)
Can you please try that and let me know if it works for you?
Closing because of inactivity, feel free to reopen if my suggestion doesn't work
@agateblue Maybe it would be helpful to have annotations like django provides.
In tests you can just write with self.modify_settings(..):
to alter settings for the context or @modify_settings(MYSETTING="xyz")
to overwrite for a function.
See here for current documentation: https://docs.djangoproject.com/en/5.1/topics/testing/tools/#overriding-settings
What are your thoughts?
dynamic_preferences_registry.py:
serializers.py:
views.py:
tests.py:
How to mock global preferences when testing OTP enabled and disabled situations in the last tests?