-
Notifications
You must be signed in to change notification settings - Fork 93
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
Verify the dict representation of a message has an isoformatted timestamp #2355
Conversation
message = Message.query.filter_by(text='**test message**').first() | ||
result = get_message_dict(message) | ||
assert result["message_type"] == MessageType.TEXT | ||
assert datetime.datetime.fromisoformat(result["time"]).year == datetime.datetime.now().year |
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.
that was missing for the isoformat change.
I think we should have both tests. That isoformat test was missing for the last change. |
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.
The linked issue describes a different thing that has already been fixed. The title of the PR does not match the changes (move vs add).
In my opinion we don't need a test for this get_message_dict
anyway, what it does assert is trivially true and the function is being exercised by broader tests already. If we do unit tests on a too fine-grained level (e.g. for private helper functions) we will get ourselves into a situation where any architectural change will break tests (e.g. because the tested function is removed/renamed/its interface changed).
In my opinion, the most valuable tests are those that test the public interface of the code (in our case that is the msui Qt app as well as the mscolab and mswms APIs, where the latter two are best tested through the UI) and we should thrive to get full coverage of the code base through those high level tests. Anything more fine-grained has to be considered individually for its value.
changed issue and title
Where do we have a test, that we now require isoformatted time strings with a tz information?
This tests a socket created chat message if it is conform to an iso formatted time string. How is that different to your last paragraph? |
What I said was primarily directed at the MessageType check and the entirety of MSS/tests/_test_mscolab/test_utils.py Lines 66 to 71 in 531cb75
We don't, and I don't think we should have one unless using the iso format is part of our public interface. What we should have is a test that sends and receives messages from a client, exercising the serialization between client and server and making sure that messages reach each end as they should. We might need to have two or more instances of msui available in a test to properly do this. As it is, I consider the format of these timestamps as an implementation detail that is not important to check. Whenever we split MSS into multiple packages this might change, since then mscolab would have a public API and these timestamps would be part of it. In that case we should also think about versioning the API, though. |
I moved it because I recognized that I can't use it in a common event based usecase. So it was only with that Message class a check for the definition of the model. And by that a test for the get_message_dict. I think we should not remove it yet but maybe at 80% coverage organize tests differently.
I think this different, when we haven't a test we need to communicate that often, while a test says "no, that is wrong". |
Yes, what I am saying is just that we should make a conscious decision on what we test, and why, because overdoing it on the details is a net-negative. If we want to declare that all timestamps must be encoded with isoformat, then that is fine to add as a test; it then becomes part of the expected interface instead of remaining an implementation detail. My stab at |
I am still not sure how this could be tested though. Just making sure that this one helper function does it right doesn't say much. |
In principle it does pinning the definition of the get_message_dict, not detailed enough to use it for a TDD approach. Also not the origin version. When the lib would have been defined by TDD we likly would have there also very different quality of these tests now. That is maybe also an interesting aspect for a talk about the tests life cycle of a project by TDD. How it looks like for a young project and envolves on a mature project. What we currently mostly do is to write tests afterwards for bugfixes or refactoring, for better understanding what it is doing and how and to get a coverage so it is harder for us to break something without realizing it. And important we continously improve. |
Co-authored-by: Matthias Riße <[email protected]>
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.
Seems OK to me. I think this ad-hoc Message-to-dict mapper should eventually be replaced by a real serialization/deserialization module that can be properly tested with e.g. property-based testing.
Purpose of PR?:
Fixes #2356