Skip to content

Migrated get_next_unread_pm and tests to model. #1395

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

WladRamos
Copy link
Collaborator

What does this PR do, and why?

This pull request Migrates get_next_unread_pm & tests to model.
Created this new version to the pull request to make it cleaner by splitting the changes into two commits.
This is a precursor for improving the get_next_unread_pm method.
Fixes #1335

External discussion & connections

How did you test this?

  • Manually - Behavioral changes
  • Manually - Visual changes
  • Adapting existing automated tests
  • Adding automated tests for new behavior (or missing tests)
  • Existing automated tests should already cover this (only a refactor of tested code)

Self-review checklist for each commit

  • It is a minimal coherent idea
  • It has a commit summary following the documented style (title & body)
  • It has a commit summary describing the motivation and reasoning for the change
  • It individually passes linting and tests
  • It contains test additions for any new behavior
  • It flows clearly from a previous branch commit, and/or prepares for the next commit

@zulipbot zulipbot added the size: L [Automatic label added by zulipbot] label May 6, 2023
@zulipbot
Copy link
Member

zulipbot commented May 6, 2023

Hello @WladRamos, it seems like you have referenced #1335 in your pull request description, but you have not referenced them in your commit message description(s). Referencing an issue in a commit message automatically closes the corresponding issue when the commit is merged, which makes the issue tracker easier to manage.

Please run git commit --amend in your command line client to amend your commit message description with Fixes #1335..

An example of a correctly-formatted commit:

commit fabd5e450374c8dde65ec35f02140383940fe146
Author: zulipbot
Date:   Sat Mar 18 13:42:40 2017 -0700

    pull requests: Check PR commits reference when issue is referenced.

    Fixes #51.

To learn how to write a great commit message, please refer to our guide.

@zulipbot zulipbot added size: M [Automatic label added by zulipbot] and removed size: L [Automatic label added by zulipbot] labels May 10, 2023
@neiljp
Copy link
Collaborator

neiljp commented May 10, 2023

@WladRamos I just merged a slightly trimmed version of your first commit, and the other parts back to this PR. I'm going to make some notes in a moment.

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.

@WladRamos Thanks for working on this 👍

Here are the comments for the followup commits.

@@ -902,6 +903,21 @@ def get_next_unread_topic(self) -> Optional[Tuple[int, str]]:
next_topic = True
return None

def get_next_unread_pm(self) -> Optional[int]:
pms = sorted(self.unread_counts["unread_pms"].keys())
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should stay unsorted for this commit.

@@ -616,6 +616,7 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
recipient_emails=[email],
contextual_message_id=pm,
)
return key
Copy link
Collaborator

Choose a reason for hiding this comment

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

This change is small, but I split it out from the first commit since it's a distraction from the main refactor.

@@ -933,6 +934,7 @@ def test_keypress_NEXT_UNREAD_PM_no_pm(

return_value = mid_col_view.keypress(size, key)

assert not mid_col_view.controller.narrow_to_user.called
Copy link
Collaborator

Choose a reason for hiding this comment

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

Similarly this looks reasonable, but unrelated to that first commit (migration).

"unread_pms, last_unread_pm, next_unread_pm",
[
case(
{(1, "pm"), (2, "pm2")},
Copy link
Collaborator

Choose a reason for hiding this comment

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

Note that unread_pms are, based on the unread_counts definition, int->int, from sender-id to unread count, so these strings are misleading.

def test_get_next_unread_pm(
self, model, unread_pms, last_unread_pm, next_unread_pm
):
model.unread_counts = {"unread_pms": {stream_pm: 1 for stream_pm in unread_pms}}
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is stream_pm here?

),
case(
{(1, "pm"), (2, "pm2")},
(1, "pm"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Similarly in the test refactor here, this is setting model.last_unread_pm to a tuple, which is different.


unread_pm = model.get_next_unread_pm()

assert unread_pm == next_unread_pm
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 missing an assert?

@neiljp neiljp added PR awaiting update PR has been reviewed & is awaiting update or response to reviewer feedback area: tests area: refactoring labels May 10, 2023
@zulipbot
Copy link
Member

Hello @zulip/server-refactoring members, this pull request was labeled with the "area: refactoring" label, so you may want to check it out!

@WladRamos
Copy link
Collaborator Author

WladRamos commented May 10, 2023

@neiljp Thanks for the feedback, I'll take a look. 👍

@neiljp neiljp added PR completion candidate PR with reviews that may unblock merging and removed PR awaiting update PR has been reviewed & is awaiting update or response to reviewer feedback labels May 29, 2024
@neiljp
Copy link
Collaborator

neiljp commented May 29, 2024

As noted in #1335, the migration was complete in the merged commit, but this remains a useful refactor as part of #1336, so marking this as a PR completion candidate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: refactoring area: tests PR completion candidate PR with reviews that may unblock merging size: M [Automatic label added by zulipbot]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate get_next_unread_pm & tests to model
3 participants