-
Notifications
You must be signed in to change notification settings - Fork 58
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
fix: Solve error for running tests without Zulip API Key #102
fix: Solve error for running tests without Zulip API Key #102
Conversation
b9d1185
to
6d33f7c
Compare
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.
client = Client(config_file="download") | ||
|
||
|
||
def get_client(): |
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.
As in the CI, we need to test the code which uses the zulip_api
key.
For reference see this test: #94
How we are going to test this feature @devkapilbansal ?
This test requires download
file and the test will surely fail in CI.
Cc: @isabelcosta
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.
@codesankalp I think it is better to pass whole file in the client. If we are going to mock, then we can mock the whole function value as said by @isabelcosta here. That way we don't need Zulip Api keys in the github workflow
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 wonder if there is a cleaner way to do what I did in this PR
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 wrote the comments 3 days before this @devkapilbansal, You can ignore the above comments.
But what I want to say is that why don't we import it from settings.py
instead of utils.py
.
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.
You want to import client from settings or the whole functions. If talking about whole functions, then zulip_api.py
provides not only functions but there examples too and it will create a whole lot of mess if we import from settings.py
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 suggested because in many projects the client is always defined in the settings.py
. But if it will create a mess then leave this point.
Also, @devkapilbansal Is Zulip provides |
@devkapilbansal is this still a draft PR? |
Yes @isabelcosta I still don't know what can be the best approach for doing this. Actually getting data by passing fake/mocked key doesn't seems to work |
@devkapilbansal @isabelcosta If we use this we can access the secrets. |
Additionally, @devkapilbansal could you look into https://zulip.readthedocs.io/en/latest/testing/testing-with-django.html#why-is-mocking-useful this has a MagicMock() usage, where i think for Zulip, you can perhaps mock the return value of the call to Zulip. Let me know if you have any doubt. I can also look at this for a bit. |
I tried this: My steps: And when I created a pull request, the test is able to get zulip_api_key. Cc: @isabelcosta , @devkapilbansal |
I think I have figured out the solution to this problem. Github Actions Test Build on Pull Request: https://github.com/codesankalp/open-source-programs-backend/actions/runs/604945863 As both builds pass we can take this as the solution to this problem because it will be able to run tests based on zulip_key also. Cc: @isabelcosta , @devkapilbansal |
This is very interesting 👍🏾 But I am still wondering 🤔 should we use a real API key everytime we run the tests? I think, to test our zulip functions we should mock the Zulip client responses. We don't want to test Zulip API, we should assume that is covered by that project, we only want to test that our functions return appropriate response when receiving an appropriate response from the API. As an example, while testing So in this case we want to mock response of this call https://github.com/anitab-org/open-source-programs-backend/blob/develop/osp/utils/zulip_api.py#L40 taking into example what is on official docs: https://zulip.readthedocs.io/en/latest/testing/testing-with-django.html#why-is-mocking-useful
we can do the same for our
internally, the get_messages method will return that, and our function will respond correctly 🤔 |
Looks good. We can try this for testing Zulip APIs. Then we can remove the repository secret for |
Yes, we can do this @isabelcosta @devkapilbansal, and it looks more feasible method than calling the API for testing. |
I don't think so 🤔 |
6d33f7c
to
efc9207
Compare
Codecov Report
@@ Coverage Diff @@
## develop #102 +/- ##
===========================================
- Coverage 65.17% 64.85% -0.32%
===========================================
Files 64 64
Lines 1025 1030 +5
===========================================
Hits 668 668
- Misses 357 362 +5
Continue to review full report at Codecov.
|
@devkapilbansal I think it will be good if you create all functions mock which uses zulip_api in a new file inside tests directory so that whenever a test will be written in the future the contributor does not need to write the mock again. |
@codesankalp I can but there is already an open issue for writing users test. Therefore, either mocking should be done in that PR or I have to wait for that PR to be merged first using |
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.
Cool! Thank you for working on this @devkapilbansal
I hope we can follow up in an issue to test these zulip functions.
Thank you so much for working on this 🙌🏾 @devkapilbansal
I will merge since this is passing CI, but will create a follow-up to make sure we test the Zulip functions. |
Description
Fixes #82
Type of Change:
Code/Quality Assurance Only
How Has This Been Tested?
Checklist:
Code/Quality Assurance Only