Skip to content
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

Fix TestCustomQuery test that fails at beginning of year #6853

Merged
merged 2 commits into from
Jan 6, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions webapp/crashstats/supersearch/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,11 +492,14 @@ def test_search_custom_parameters(
# Assert the available indices are there
template = preferred_es_helper.get_index_template()
now = utc_now()
indices = [
(now - datetime.timedelta(days=7)).strftime(template),
now.strftime(template),
]
assert ",".join(indices) in smart_str(response.content)
indices = set()
# NOTE(willkg): we have to build the list of indices this way because
# the index name is based on the week number and this handles the
# end-of-year/beginning-of-year case correctly.
for i in range(7):
indices.add((now - datetime.timedelta(days=i)).strftime(template))
Copy link
Contributor

Choose a reason for hiding this comment

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

The old version used now and now–7d as the index names. The new version only goes back to now-6d. I can't tell whether that's intentional or not, or whether it matters.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops--I forgot that range is open-ended.

import datetime

def old_way(template, date):
    return [
        (date - datetime.timedelta(days=7)).strftime(template),
        date.strftime(template)
    ]

def new_way(template, date):
    indices = set()
    # NOTE(willkg): we have to build the list of indices this way because
    # the index name is based on the week number and this handles the
    # end-of-year/beginning-of-year case correctly.
    for i in range(7):
        indices.add((date - datetime.timedelta(days=i)).strftime(template))
    return sorted(indices)


template = "socorro%Y%W"

deltas = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

for i in deltas:
    date = datetime.date.today() + datetime.timedelta(days=i)
    print(f"{date}:  old way:{old_way(template, date)}  new way: {new_way(template, date)}")
2024-12-27:  old way:['socorro202451', 'socorro202452']  new way: ['socorro202451', 'socorro202452']
2024-12-28:  old way:['socorro202451', 'socorro202452']  new way: ['socorro202451', 'socorro202452']
2024-12-29:  old way:['socorro202451', 'socorro202452']  new way: ['socorro202452']
2024-12-30:  old way:['socorro202452', 'socorro202453']  new way: ['socorro202452', 'socorro202453']
2024-12-31:  old way:['socorro202452', 'socorro202453']  new way: ['socorro202452', 'socorro202453']
2025-01-01:  old way:['socorro202452', 'socorro202500']  new way: ['socorro202452', 'socorro202453', 'socorro202500']
2025-01-02:  old way:['socorro202452', 'socorro202500']  new way: ['socorro202452', 'socorro202453', 'socorro202500']
2025-01-03:  old way:['socorro202452', 'socorro202500']  new way: ['socorro202452', 'socorro202453', 'socorro202500']
2025-01-04:  old way:['socorro202452', 'socorro202500']  new way: ['socorro202452', 'socorro202453', 'socorro202500']
2025-01-05:  old way:['socorro202452', 'socorro202500']  new way: ['socorro202453', 'socorro202500']
2025-01-06:  old way:['socorro202453', 'socorro202501']  new way: ['socorro202453', 'socorro202500', 'socorro202501']
2025-01-07:  old way:['socorro202453', 'socorro202501']  new way: ['socorro202500', 'socorro202501']
2025-01-08:  old way:['socorro202500', 'socorro202501']  new way: ['socorro202500', 'socorro202501']
2025-01-09:  old way:['socorro202500', 'socorro202501']  new way: ['socorro202500', 'socorro202501']
2025-01-10:  old way:['socorro202500', 'socorro202501']  new way: ['socorro202500', 'socorro202501']
2025-01-11:  old way:['socorro202500', 'socorro202501']  new way: ['socorro202500', 'socorro202501']
2025-01-12:  old way:['socorro202500', 'socorro202501']  new way: ['socorro202501']
2025-01-13:  old way:['socorro202501', 'socorro202502']  new way: ['socorro202501', 'socorro202502']
2025-01-14:  old way:['socorro202501', 'socorro202502']  new way: ['socorro202501', 'socorro202502']
2025-01-15:  old way:['socorro202501', 'socorro202502']  new way: ['socorro202501', 'socorro202502']
2025-01-16:  old way:['socorro202501', 'socorro202502']  new way: ['socorro202501', 'socorro202502']

index_value = ",".join(sorted(indices))
assert index_value in smart_str(response.content)

def test_search_query(self, client, db, preferred_es_helper, user_helper):
user = user_helper.create_protected_plus_user()
Expand Down