Repository navigation
fix: ValeofWhiteHorseCouncil: don't infer a collection date into a bank holiday week #2229
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
Closed
+180
−2
Closed
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
97 changes: 97 additions & 0 deletions
97
uk_bin_collection/tests/test_vale_of_white_horse_council.py
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,97 @@ | ||
| """Unit tests for the Vale of White Horse fortnightly roll-forward. | ||
|
|
||
| The council page publishes the current fortnight's pair of collections rather | ||
| than the next occurrence of each bin, so the scraper rolls a past date forward | ||
| by 14 days - except into a week with a bank holiday, when the council collects | ||
| on a different day and only the page knows which. | ||
| """ | ||
|
|
||
| from datetime import datetime as real_datetime | ||
| from types import SimpleNamespace | ||
| from unittest.mock import patch | ||
|
|
||
| from uk_bin_collection.uk_bin_collection.councils.ValeofWhiteHorseCouncil import ( | ||
| CouncilClass, | ||
| ) | ||
|
|
||
| MODULE_PATH = "uk_bin_collection.uk_bin_collection.councils.ValeofWhiteHorseCouncil" | ||
|
|
||
| PAGE = """ | ||
| <html><body> | ||
| <div class="bintxt">It's rubbish week</div> | ||
| <div class="binextra"><span>{rubbish}</span><span>grey bin, small electrical items and food bin</span></div> | ||
| <div class="bintxt">It's recycling week</div> | ||
| <div class="binextra"><span>{recycling}</span><span>food bin, green bin, textiles and garden waste bin</span></div> | ||
| </body></html> | ||
| """ | ||
|
|
||
|
|
||
| def parse_fixture(rubbish: str, recycling: str, now: real_datetime) -> dict: | ||
| """Run the parser against a page showing the given two panels, on `now`.""" | ||
|
|
||
| class FrozenDatetime(real_datetime): | ||
| @classmethod | ||
| def now(cls, tz=None): | ||
| return now | ||
|
|
||
| response = SimpleNamespace(text=PAGE.format(rubbish=rubbish, recycling=recycling)) | ||
| with patch(f"{MODULE_PATH}.requests.Session") as session, patch( | ||
| f"{MODULE_PATH}.datetime", FrozenDatetime | ||
| ): | ||
| session.return_value.get.return_value = response | ||
| return CouncilClass().parse_data("", uprn="100120000000") | ||
|
|
||
|
|
||
| def test_a_bin_collected_earlier_this_fortnight_rolls_forward_14_days(): | ||
| result = parse_fixture( | ||
| "Monday 3 August -", "Monday 10 August -", real_datetime(2026, 8, 8) | ||
| ) | ||
|
|
||
| assert result == { | ||
| "bins": [ | ||
| {"type": "Recycling", "collectionDate": "10/08/2026"}, | ||
| {"type": "Rubbish", "collectionDate": "17/08/2026"}, | ||
| ] | ||
| } | ||
|
|
||
|
|
||
| def test_no_roll_forward_into_a_bank_holiday_week(): | ||
| # 31 August 2026 is the late summer bank holiday, so 17 + 14 would be a | ||
| # day the council does not collect: the bin is left out until the page | ||
| # shows the real date. | ||
| result = parse_fixture( | ||
| "Monday 17 August -", "Monday 24 August -", real_datetime(2026, 8, 22) | ||
| ) | ||
|
|
||
| assert result == {"bins": [{"type": "Recycling", "collectionDate": "24/08/2026"}]} | ||
|
|
||
|
|
||
| def test_a_rescheduled_date_on_the_page_is_returned_as_is(): | ||
| result = parse_fixture( | ||
| "Tuesday 1 September -", "Monday 7 September -", real_datetime(2026, 8, 30) | ||
| ) | ||
|
|
||
| assert result["bins"] == [ | ||
| {"type": "Rubbish", "collectionDate": "01/09/2026"}, | ||
| {"type": "Recycling", "collectionDate": "07/09/2026"}, | ||
| ] | ||
|
|
||
|
|
||
| def test_roll_forward_crosses_the_year_boundary(): | ||
| result = parse_fixture( | ||
| "Monday 21 December -", "Monday 28 December -", real_datetime(2026, 12, 23) | ||
| ) | ||
|
|
||
| assert result["bins"] == [ | ||
| {"type": "Recycling", "collectionDate": "28/12/2026"}, | ||
| {"type": "Rubbish", "collectionDate": "04/01/2027"}, | ||
| ] | ||
|
|
||
|
|
||
| def test_no_roll_forward_into_christmas_week(): | ||
| # 14 + 14 = 28 December 2026, the observed Boxing Day holiday. | ||
| result = parse_fixture( | ||
| "Monday 14 December -", "Monday 21 December -", real_datetime(2026, 12, 19) | ||
| ) | ||
|
|
||
| assert result["bins"] == [{"type": "Recycling", "collectionDate": "21/12/2026"}] |
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
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.
Uh oh!
There was an error while loading. Please reload this page.