-
-
Notifications
You must be signed in to change notification settings - Fork 461
Add QueryableFake gateway #293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,8 @@ General Settings | |
| Twilio_. | ||
| * ``'two_factor.gateways.fake.Fake'`` for development, recording tokens to the | ||
| default logger. | ||
| * ``'two_factor.gateways.fake.QueryableFake'`` for testing, recording tokens | ||
| to the ``QueryableFake`` singleton. | ||
|
|
||
| ``TWO_FACTOR_SMS_GATEWAY`` (default: ``None``) | ||
| Which gateway to use for sending text messages. Should be set to a module or | ||
|
|
@@ -28,6 +30,8 @@ General Settings | |
| Twilio_. | ||
| * ``'two_factor.gateways.fake.Fake'`` for development, recording tokens to the | ||
| default logger. | ||
| * ``'two_factor.gateways.fake.QueryableFake'`` for testing, recording tokens | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is merged, the text "Currently two gateways are bundled:" no longer holds. |
||
| to the ``QueryableFake`` singleton. | ||
|
|
||
| ``LOGIN_URL`` | ||
| Should point to the login view provided by this application as described in | ||
|
|
@@ -118,6 +122,10 @@ Fake Gateway | |
| ------------ | ||
| .. autoclass:: two_factor.gateways.fake.Fake | ||
|
|
||
| QueryableFake Gateway | ||
| ------------ | ||
| .. autoclass:: two_factor.gateways.fake.QueryableFake | ||
|
|
||
| .. _LOGIN_URL: https://docs.djangoproject.com/en/dev/ref/settings/#login-url | ||
| .. _LOGIN_REDIRECT_URL: https://docs.djangoproject.com/en/dev/ref/settings/#login-redirect-url | ||
| .. _LOGOUT_REDIRECT_URL: https://docs.djangoproject.com/en/dev/ref/settings/#logout-redirect-url | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,7 @@ | |
| from django.utils.six.moves.urllib.parse import urlencode | ||
| from phonenumber_field.phonenumber import PhoneNumber | ||
|
|
||
| from two_factor.gateways.fake import Fake | ||
| from two_factor.gateways.fake import Fake, QueryableFake | ||
| from two_factor.gateways.twilio.gateway import Twilio | ||
|
|
||
| try: | ||
|
|
@@ -117,3 +117,15 @@ def test_gateway(self, logger): | |
| fake.send_sms(device=Mock(number=PhoneNumber.from_string('+123')), token=code) | ||
| logger.info.assert_called_with( | ||
| 'Fake SMS to %s: "Your token is: %s"', '+123', code) | ||
|
|
||
|
|
||
| class QueryableFakeGatewayTest(TestCase): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More tests please. E.g. do |
||
| def test_gateway(self): | ||
| fake = QueryableFake() | ||
|
|
||
| for code in ['654321', '87654321']: | ||
| fake.make_call(device=Mock(number=PhoneNumber.from_string('+123')), token=code) | ||
| self.assertEqual(fake.call_tokens['+123'].pop(), code) | ||
|
|
||
| fake.send_sms(device=Mock(number=PhoneNumber.from_string('+123')), token=code) | ||
| self.assertEqual(fake.sms_tokens['+123'].pop(), code) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new gateway is not a singleton. I know what you're trying to say here (
sms_tokensandcall_tokensare initialised when the class is created not when an object is instantiated) but "singleton" would mean that things likeQueryableFake().sms_tokens = {}would affect other instances ofQueryableFakebecause there would only be one instance of the class.