Repository navigation
T351642: Discard canary events in Hashtags #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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import unittest | ||
|
|
||
| from common import is_canary | ||
|
|
||
|
|
||
| class IsCanaryTest(unittest.TestCase): | ||
| def test_canary_event(self): | ||
| self.assertTrue(is_canary({"meta": {"domain": "canary"}})) | ||
|
|
||
| def test_normal_event(self): | ||
| self.assertFalse(is_canary({"meta": {"domain": "en.wikipedia.org"}})) | ||
|
|
||
| def test_missing_meta(self): | ||
| self.assertFalse(is_canary({})) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I had to do some research, but it looks like if we add an empty
__init__.pyto the scripts/ directory, it will then be treated as a Python package and Django will look for the tests. However because the tests are ran from the root directory, it will thinkcommonis a top-level package when it's only part ofscripts. The fix there seems to be to add a parent-relative import:Then
docker compose exec app python manage.py test(and CI) should run the test. I think however the other files inscripts/need the same treatment to import locally, which doesn't look a huge change:from common→from .common,import db→import .dbfrom common→from .commonShould we go ahead and try that?
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.
Note again I'm not very experienced with Python so this may not be the right way to go about it. If there's any disagreement, I'm happy to defer to @jsnshrmn and sort out running the tests in a separate PR.
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 collector is started directly as
python collect_hashtags.py, so Python doesn't treat it as part of a package, andfrom .common import ...only works inside a package so things would break if we did that :) getting the test working isn't a big change but might be worth following up with instead I thinkThere 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.
Agreed; let's merge for now and consider this a coverage concern for future ci work.