diff options
author | laixintao <laixintaoo@gmail.com> | 2022-06-26 00:36:44 +0800 |
---|---|---|
committer | laixintao <laixintaoo@gmail.com> | 2022-06-26 00:36:44 +0800 |
commit | 3c309b9757c5fa88ca1fb38f6fe412a3f67497a5 (patch) | |
tree | d5a4a0f3b0a7c2ae06800ede9bab5486e4fd4a78 | |
parent | b3b0b46105f400d087de5a3a16fe9112286e5e41 (diff) |
add tests for timestamp completers.
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | tests/unittests/test_completers.py | 79 |
2 files changed, 81 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index a0d7118..21c6014 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,8 +12,10 @@ - Feature: support new command: `GEOSEARCH`. - Feature: support new command: `GEOSEARCHRESTORE`. - Feature: support new command: `GETDEL`. +- Feature: support new command: `GETEX`. - Feature: `FLUSHDB` and `FLUSHALL` supports `SYNC` option. - Feature: `GEOADD` supports `CH XX NX` options. +- Feature: Timestamp Completers are now support completion for timestamp fields and milliseconds timestamp fields. - Deprecate: `GEORADIUS` is deprecated, no auto-complete for this command anymore. - Deprecate: `GEORADIUSBYMEMBER` is deprecated, no auto-complete for this command anymore. diff --git a/tests/unittests/test_completers.py b/tests/unittests/test_completers.py index 4405b9f..5441b0e 100644 --- a/tests/unittests/test_completers.py +++ b/tests/unittests/test_completers.py @@ -260,6 +260,85 @@ def test_timestamp_completer_humanize_time_completion(fake_now): ] +@patch("iredis.completers.pendulum.now") +def test_timestamp_completer_humanize_time_completion_seconds(fake_now): + fake_now.return_value = pendulum.from_timestamp(1578487013) + c = TimestampCompleter(is_milliseconds=False, future_time=False) + + fake_document = MagicMock() + fake_document.text = fake_document.text_before_cursor = "30" + completions = list(c.get_completions(fake_document, None)) + + assert completions == [ + Completion( + text="1575895013", + start_position=-2, + display=FormattedText([("", "1575895013")]), + display_meta="30 days ago (2019-12-09 12:36:53)", + ), + Completion( + text="1578379013", + start_position=-2, + display=FormattedText([("", "1578379013")]), + display_meta="30 hours ago (2020-01-07 06:36:53)", + ), + Completion( + text="1578485213", + start_position=-2, + display=FormattedText([("", "1578485213")]), + display_meta="30 minutes ago (2020-01-08 12:06:53)", + ), + Completion( + text="1578486983", + start_position=-2, + display=FormattedText([("", "1578486983")]), + display_meta="30 seconds ago (2020-01-08 12:36:23)", + ), + ] + + +@patch("iredis.completers.pendulum.now") +def test_timestamp_completer_humanize_time_completion_seconds_future_time(fake_now): + fake_now.return_value = pendulum.from_timestamp(1578487013) + c = TimestampCompleter(is_milliseconds=False, future_time=True) + + fake_document = MagicMock() + fake_document.text = fake_document.text_before_cursor = "30" + completions = list(c.get_completions(fake_document, None)) + + print(completions) + for c in completions: + print(c.text) + print(c.display) + print(c.display_meta) + assert completions == [ + Completion( + text="1578487043", + start_position=-2, + display=FormattedText([("", "1578487043")]), + display_meta="30 seconds later (2020-01-08 12:37:23)", + ), + Completion( + text="1578488813", + start_position=-2, + display=FormattedText([("", "1578488813")]), + display_meta="30 minutes later (2020-01-08 13:06:53)", + ), + Completion( + text="1578595013", + start_position=-2, + display=FormattedText([("", "1578595013")]), + display_meta="30 hours later (2020-01-09 18:36:53)", + ), + Completion( + text="1581079013", + start_position=-2, + display=FormattedText([("", "1581079013")]), + display_meta="30 days later (2020-02-07 12:36:53)", + ), + ] + + def test_timestamp_completer_datetime_format_time_completion(): c = TimestampCompleter(is_milliseconds=True, future_time=False) fake_document = MagicMock() |