-
-
Notifications
You must be signed in to change notification settings - Fork 447
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
Add QueryableFake gateway #293
base: master
Are you sure you want to change the base?
Add QueryableFake gateway #293
Conversation
ebfc9ed
to
26c56f5
Compare
Codecov Report
@@ Coverage Diff @@
## master #293 +/- ##
=========================================
+ Coverage 96.54% 96.6% +0.06%
=========================================
Files 39 39
Lines 1648 1681 +33
Branches 116 118 +2
=========================================
+ Hits 1591 1624 +33
Misses 35 35
Partials 22 22
Continue to review full report at Codecov.
|
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.
I've got a few comments and questions, especially around how the new gateway would work with multiple tests.
Thanks for adding to the documentation (not enough people do that!)
docs/configuration.rst
Outdated
@@ -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. |
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_tokens
and call_tokens
are initialised when the class is created not when an object is instantiated) but "singleton" would mean that things like QueryableFake().sms_tokens = {}
would affect other instances of QueryableFake
because there would only be one instance of the class.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
More tests please. E.g. do call_tokens
and sms_tokens
get reset properly after each testcase?
- Add the `QueryableFake.reset` method - Add unit test explaining how to reset the QueryableFake - Remove the mention of QueryableFake being a singleton
Thanks for the review @moggers87 - I've added commit cfc695d which addresses the issues you mentioned (or tries to at least). If you are happy with the changes, then I'll squash the commit and push. |
@@ -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 comment
The 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.
An alternative would be to just use fixed tokens instead. This would simplify the tests, while allowing the same use case. For example, it could work e.g. like this:
|
Thanks for the review @Bouke RE: The fixed tokens approach. I think that you're suggesting an approach where Is my understanding correct? |
@Bouke @christopherdcunha, is this still something worth pursuing? It sounds like there may need to be some consensus about whether this is the best approach to testing. |
Agreed. I personally prefer/use the approach I've suggested here, but I'm totally happy to close this PR if it doesn't make sense for the broader "library user base". |
Description
This change adds a fake gateway that can be queried programatically.
Motivation and Context
This allows my functional tests to receive tokens and complete the 2FA flow.
How Has This Been Tested?
This has been tested via the unittests in this PR and a functional test similar to the one in the docstring of the QueryableFake class.
Screenshots (if appropriate):
Documentation
configuration.html#general-settings
Documentation
configuration.html#queryablefake-gateway
Types of changes
Checklist: