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

bugfix/migration: Support API migration for muted topics #744

Closed
wants to merge 5 commits into from

Conversation

preetmishra
Copy link
Member

@preetmishra preetmishra commented Jul 28, 2020

This reflects the expected response change for muted_topics, from [stream_name, topic] to [stream_name, topic, date_muted] in Zulip version 3.0, Feature level 1 (see zulip/zulip@9340cd1).

Tests amended.

@zulipbot zulipbot added the size: M [Automatic label added by zulipbot] label Jul 28, 2020
@preetmishra preetmishra changed the title buttons/helper/model/utils: Support API migration for muted topics. migration: Support API migration for muted topics Jul 28, 2020
@preetmishra
Copy link
Member Author

Logged #745 to track related improvements.

@preetmishra preetmishra added the PR needs review PR requires feedback to proceed label Jul 28, 2020
Copy link
Collaborator

@neiljp neiljp left a comment

Choose a reason for hiding this comment

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

@preetmishra Thanks for taking this up - other than the bugfix, this has the potential to allow extra details be listed about the muting 👍

While I'm not averse to introducing another data-structure in the Model, if it's necessary I would prefer it be marked private (leading underscore) and access wrapped in a method - particularly since it's use seems to be one particular check that is essentially being duplicated in multiple locations.

A nice extension to this would be supporting events to update these data-structures from the server, and of course potentially a UI to interact locally (you have some of these in #745 👍).

@zulipbot zulipbot added size: XL [Automatic label added by zulipbot] and removed size: M [Automatic label added by zulipbot] labels Jul 28, 2020
@preetmishra
Copy link
Member Author

@neiljp Thanks for the review. I have updated the PR as per our discussion in the stream. This is larger than what we started with, but I believe the refactoring is worthwhile.

I have also added the proposed extension in #745.

zulipterminal/model.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@neiljp neiljp left a comment

Choose a reason for hiding this comment

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

@preetmishra Thanks for continuing to work on this; the new adjustments to allow testing against multiple versions may be the element making this more difficult to test.

The last commit is actually also a bugfix, right?

zulipterminal/model.py Outdated Show resolved Hide resolved
zulipterminal/ui_tools/buttons.py Show resolved Hide resolved
tests/ui/test_utils.py Outdated Show resolved Hide resolved
Comment on lines 97 to 100
model.is_in_muted_topics = mocker.Mock(return_value=(
[model.stream_dict[msg['stream_id']]['name'],
msg.get('subject', '')] in muted_topics
))
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems strange since it's basically reimplementing the function?

tests/model/test_model.py Outdated Show resolved Hide resolved
zulipterminal/model.py Outdated Show resolved Hide resolved
Comment on lines 118 to 121
# NOTE: The expected response has been upgraded from
# [stream_name, topic] to [stream_name, topic, date_muted] in
# 3.0, Feature level 1.
Copy link
Collaborator

Choose a reason for hiding this comment

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

It'd be useful to standardize our notes in the code for this; we could add that to the development section - this would make it easier to check for changes at different server versions and feature levels :)

@neiljp neiljp removed the PR needs review PR requires feedback to proceed label Aug 1, 2020
@preetmishra
Copy link
Member Author

@neiljp The first two commits make modification in the existing code to facilitate the migration. The last commit is the migration commit (should we call it a bugfix?). Note that the first two commits do not introduce any 'new' feature.

@preetmishra
Copy link
Member Author

@neiljp Thanks for the review. In the latest update, I have simplified the parameterize blocks to avoid unnecessary mocking wherever feasible, made muted_topics protected with an underscore, added _muted_topics_dict along with an assert, and addressed other in-line suggestions (excluding the standard comment that we are discussing in zulip-terminal > Comments for server versions).

@preetmishra preetmishra added the PR needs review PR requires feedback to proceed label Aug 1, 2020
@preetmishra
Copy link
Member Author

(Updated to rebase onto upstream/master.)

This decouples stream muting from is_muted_topic to allow independent
muted_topics lookups.

Additionally, this adds a docstring to clarify the method further.

The method had been here for a while without any use-case. Besides,
the current behaviour can easily be achieved by using is_muted_topic
with is_muted_stream at any point.

Test amended.
@preetmishra
Copy link
Member Author

Updated to resolve conflicts.

Copy link
Collaborator

@neiljp neiljp left a comment

Choose a reason for hiding this comment

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

@preetmishra It's good to see this simplification and needed update (bugfix!) - other than also simplifying the code, it should allow simplifying the tests too :)

tests/core/test_core.py Outdated Show resolved Hide resolved
], ids=[
# Assuming 'Django', 'topic1' is muted via muted_topics.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this information actually used in this test now? This may not belong in this commit and the test name isn't that clear, but isn't this test focused on ensuring mark_muted is called if topics are muted in the model?

Other tests may also be simplified in a similar way after this, potentially.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it is needed here to understand why the values are set to True/False for is_muted_topic_return_value. Though, I have added an additional refactor commit to simplify it.

The is_muted util test is simplified in this commit itself. We might want to discuss test_classify_unread_counts - how would we like it to be handled? Maybe as a separate issue.

zulipterminal/helper.py Outdated Show resolved Hide resolved
tests/model/test_model.py Outdated Show resolved Hide resolved
zulipterminal/model.py Outdated Show resolved Hide resolved
'server_feature_level:None',
]
)
def muted_topics_dict(request):
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is the parametrization of muted_topics in the Model only - we should likely have one for initial data from server, and a test for initial data -> model data, which we don't have? (that was in the previous iteration?)

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't have that test in the previous iteration. Thanks for pointing that out.

I have added the test in the latest update with a local parametrize block in Model.py. It wouldn't be needed in conftest as we'd only test against processed_muted_topics everywhere else.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm actually thinking we might move the server response fixtures into a separate fixture file specific to the model in a similar way. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

The ones that are already in conftest.py or also the ones that are used in test_model.py?

Copy link
Member Author

Choose a reason for hiding this comment

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

In any case, I believe it is reasonable.

@neiljp neiljp removed the PR needs review PR requires feedback to proceed label Aug 9, 2020
@preetmishra preetmishra changed the title migration: Support API migration for muted topics [WIP] migration: Support API migration for muted topics Aug 9, 2020
Tests amended with simplified parametrize blocks wherever feasible.
This reflects the expected server response change for muted_topics, from
[stream_name, topic] to [stream_name, topic, date_muted] in
Zulip version 3.0, Feature level 1 (see zulip/zulip@9340cd1).

Test updated along with the addition of processed_muted_topics() fixture
in conftest.py and added for muted topic's local conversion.
This simplifies the test parametrization and its body.
@preetmishra
Copy link
Member Author

@neiljp Thanks for the review. This is ready with improved assertion against server response, improved tests, an additional refactor commit and other in-line suggestions that you mentioned.

@preetmishra preetmishra changed the title [WIP] migration: Support API migration for muted topics migration: Support API migration for muted topics Aug 11, 2020
@preetmishra preetmishra added the PR needs review PR requires feedback to proceed label Aug 11, 2020
@zulipbot
Copy link
Member

Heads up @preetmishra, we just merged some commits that conflict with the changes your 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/master branch and resolve your pull request's merge conflicts accordingly.

@neiljp
Copy link
Collaborator

neiljp commented Aug 13, 2020

@preetmishra Thanks for this bugfix and compatibility change (as well as the refactors) 👍 As per PMs I've merged the first four 🎉

I think we can save the last commit for a separate set of changes to review separately. Other than unblocking the other PR, this also could be followed by:

  • a server-response fixture refactor (after discussion)
  • feature-level comments (we briefly discussed already)

@neiljp neiljp closed this Aug 13, 2020
@neiljp neiljp added this to the Next Release milestone Aug 13, 2020
@neiljp neiljp changed the title migration: Support API migration for muted topics bugfix/migration: Support API migration for muted topics Aug 13, 2020
@preetmishra preetmishra deleted the migration-muted-topics branch August 14, 2020 05:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has conflicts PR blocks other PR PR needs review PR requires feedback to proceed size: XL [Automatic label added by zulipbot]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants