Skip to content
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

zulip: Add tests for API functions. #682

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

LoopThrough-i-j
Copy link
Contributor

No description provided.

zulip/setup.py Outdated
@@ -65,6 +65,7 @@ def recur_expand(target_root: Any, dir: Any) -> Generator[Tuple[str, List[str]],

setuptools_info = dict(
install_requires=['requests[security]>=0.12.1',
'responses',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make this a development-only dependency, like mypy.

url=re.compile("{}v1/messages/([0-9]*)/reactions".format(self.base_url)),
json={'result': 'success', 'msg': ''},
status=200
)
Copy link
Member

@timabbott timabbott Apr 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to do this individually in each test, for just the endpoints we expect that test to call.

Additionally, I would configure it for the precise URL that the test is going to use, and assert what parameters were actually present in the HTTP request -- the goal here is to use this to verify that the API bindings made the precise request that we expected, not simulate a server (where the regular expression approach might be more appropriate).

@LoopThrough-i-j LoopThrough-i-j force-pushed the test-suite branch 3 times, most recently from 9c19d36 to aca98cc Compare May 5, 2021 17:06
@LoopThrough-i-j LoopThrough-i-j force-pushed the test-suite branch 2 times, most recently from e9633ac to 97ab5c6 Compare May 12, 2021 18:45
LoopThrough-i-j added a commit to LoopThrough-i-j/python-zulip-api that referenced this pull request May 12, 2021
Value of type "Optional[Any]" is not indexable error
was originated in PR zulip#682.
LoopThrough-i-j added a commit to LoopThrough-i-j/python-zulip-api that referenced this pull request May 12, 2021
Value of type "Optional[Any]" is not indexable error
was originated in PR zulip#682. This is due to request in Flask 2.0.
timabbott pushed a commit that referenced this pull request May 12, 2021
Value of type "Optional[Any]" is not indexable error
was originated in PR #682. This is due to request in Flask 2.0.
@LoopThrough-i-j
Copy link
Contributor Author

I was thinking of simulating an event queue for testing call_on_each_event but restricted myself from doing that thinking of the previous comments and from the prospects of setting up an integration test suite.

This is an unit test suite testing for payloads
and proper api calls.
@LoopThrough-i-j
Copy link
Contributor Author

@timabbott a review on this if possible would be great.

key, value = param.split("=")
params[key] = urllib.parse.unquote(value)
assert "emoji_name" in params or "emoji_code" in params
return (200, {}, json.dumps({'result': 'success', 'msg': ''}))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this function -- why do we need this parsing logic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function needs some work as well as I understand. This test is primarily for testing whether the payload provided is properly parsed, the URL is correct, and all the It accepts and sends a proper response, as a part of the normal API workflow.

This test makes sure all intermediate functions for an API call like do_api_query and call_endpoint, work correctly.

self.assertEqual(result, {'result': 'success', 'msg': ''})

@responses.activate
def test_call_on_each_event(self) -> None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this test could benefit from a comment or docstring explaining what we're trying to test here.

@LoopThrough-i-j
Copy link
Contributor Author

@timabbott thanks for the review I will update the PR shortly, with required comments and explanations as best as I can.

@zulipbot
Copy link
Member

Heads up @LoopThrough-i-j, we just merged some commits that conflict with the changes you made in this pull request! You can review this repository's recent commits to see where the conflicts occur. Please rebase your feature branch against the upstream/main branch and resolve your pull request's merge conflicts accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants