-
-
Notifications
You must be signed in to change notification settings - Fork 278
model: Improve reporting upon moving/splitting topic. #1178
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -834,78 +834,101 @@ def test_update_private_message( | |
], | ||
) | ||
@pytest.mark.parametrize( | ||
"req, old_topic, footer_updated", | ||
"req, old_topic, expected_report_success", | ||
[ | ||
( | ||
case( | ||
{ | ||
"message_id": 1, | ||
"propagate_mode": "change_one", | ||
"content": "hi!", | ||
"topic": "Some topic", | ||
}, | ||
"Some topic", | ||
False, | ||
None, # None as footer is not updated. | ||
), | ||
( | ||
case( | ||
{ | ||
"message_id": 1, | ||
"propagate_mode": "change_one", | ||
"topic": "Topic change", | ||
}, | ||
"Old topic", | ||
True, | ||
"You changed one message's topic from #stream > Old topic to #stream > Topic change.", | ||
), | ||
( | ||
{"message_id": 1, "propagate_mode": "change_all", "topic": "Old topic"}, | ||
case( | ||
{ | ||
"message_id": 1, | ||
"propagate_mode": "change_all", | ||
"topic": "Old topic", | ||
}, | ||
"Old topic", | ||
False, | ||
None, # None as footer is not updated. | ||
), | ||
( | ||
case( | ||
{ | ||
"message_id": 1, | ||
"propagate_mode": "change_later", | ||
"content": ":smile:", | ||
"topic": "terminal", | ||
}, | ||
"terminal", | ||
False, | ||
None, # None as footer is not updated. | ||
), | ||
( | ||
case( | ||
{ | ||
"message_id": 1, | ||
"propagate_mode": "change_later", | ||
"content": ":smile:", | ||
"topic": "new_terminal", | ||
}, | ||
"old_terminal", | ||
"You changed some messages' topic from #stream > old_terminal to #stream > new_terminal.", | ||
), | ||
case( | ||
{ | ||
"message_id": 1, | ||
"propagate_mode": "change_one", | ||
"content": "Hey!", | ||
"topic": "grett", | ||
}, | ||
"greet", | ||
True, | ||
"You changed one message's topic from #stream > greet to #stream > grett.", | ||
), | ||
( | ||
case( | ||
{ | ||
"message_id": 1, | ||
"propagate_mode": "change_all", | ||
"content": "Lets party!", | ||
"topic": "party", | ||
}, | ||
"lets_party", | ||
True, | ||
"You changed all messages' topic from #stream > lets_party to #stream > party.", | ||
), | ||
], | ||
) | ||
def test_update_stream_message( | ||
self, mocker, model, response, return_value, req, old_topic, footer_updated | ||
self, | ||
mocker, | ||
model, | ||
response, | ||
return_value, | ||
req, | ||
old_topic, | ||
expected_report_success, | ||
old_stream_name="stream", | ||
): | ||
self.client.update_message = mocker.Mock(return_value=response) | ||
model.index["messages"][req["message_id"]]["subject"] = old_topic | ||
|
||
model.index["messages"][req["message_id"]][ | ||
"display_recipient" | ||
] = old_stream_name | ||
result = model.update_stream_message(**req) | ||
|
||
self.client.update_message.assert_called_once_with(req) | ||
assert result == return_value | ||
self.display_error_if_present.assert_called_once_with(response, self.controller) | ||
report_success = model.controller.report_success | ||
if result and footer_updated: | ||
report_success.assert_called_once_with("You changed a message's topic.") | ||
if result and expected_report_success is not None: | ||
report_success.assert_called_once_with(expected_report_success) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I hope you can see how much cleaner this is 👍 |
||
else: | ||
report_success.assert_not_called() | ||
|
||
|
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.
Given the longer test here now, it would be useful to also add inline test ids.
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.
See my followup comment in the next review.
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.
OK, so you have the
case
around each set of test parameters; for the ids see other tests which use a named parameter tocase
(ie.pytest.param
), ie.id=some_description
).You might try running this test as it is with
-v
and using-k
to filter this test only, then see what happens when you add an id. What you see there is useful, in addition to it looking a little like a comment for that test parametrization.