From 8a9bc3ea3eedf27940e9a3aa2eb284b4c16c7be8 Mon Sep 17 00:00:00 2001 From: Daniel McKnight <34697904+NeonDaniel@users.noreply.github.com> Date: Wed, 20 Dec 2023 12:20:55 -0800 Subject: [PATCH 1/7] Handle malformed `user_profiles` Message context with fallback to default user config (#492) Co-authored-by: Daniel McKnight --- neon_utils/user_utils.py | 8 ++++++-- tests/user_util_tests.py | 9 +++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/neon_utils/user_utils.py b/neon_utils/user_utils.py index ee4d4bb1..769d696e 100644 --- a/neon_utils/user_utils.py +++ b/neon_utils/user_utils.py @@ -102,9 +102,13 @@ def get_user_prefs(message: Message = None) -> dict: return default_user_config for profile in message.context.get(profile_key): - if profile["user"]["username"] == username: - return dict(dict_update_keys(profile, default_user_config)) + try: + if profile["user"]["username"] == username: + return dict(dict_update_keys(profile, default_user_config)) + except KeyError: + LOG.error(f"Malformed profile in message context: {profile}") LOG.warning(f"No preferences found for {username} in {message.context}") + default_user_config['user']['username'] = username return default_user_config diff --git a/tests/user_util_tests.py b/tests/user_util_tests.py index 63103fc1..b9c52a3c 100644 --- a/tests/user_util_tests.py +++ b/tests/user_util_tests.py @@ -66,6 +66,15 @@ def test_get_user_prefs(self): self.assertIn("address", user_2["user"]) self.assertEqual(test_message_2.context['user_profiles'][1], user_2) + missing_profile = get_user_prefs(Message("", {}, + {"username": "test", + "user_profiles": [{}]})) + self.assertEqual(missing_profile["user"]["username"], "test") + missing_profile_2 = get_user_prefs(Message("", {}, + {"username": "test2", + "user_profiles": [{}]})) + self.assertEqual(missing_profile_2["user"]["username"], "test2") + def wrapper(message, valid_dict): self.assertEqual(get_user_prefs(), valid_dict) From 29af8744622c42282f47175e4e916a0efdc82e14 Mon Sep 17 00:00:00 2001 From: NeonDaniel Date: Wed, 20 Dec 2023 20:21:13 +0000 Subject: [PATCH 2/7] Increment Version to 1.8.2a1 --- version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.py b/version.py index 7b0c30fe..79cb5a9c 100644 --- a/version.py +++ b/version.py @@ -26,4 +26,4 @@ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -__version__ = "1.8.1" +__version__ = "1.8.2a1" From 8be8082ace80c0e88098360d8b39d477c602af9d Mon Sep 17 00:00:00 2001 From: NeonDaniel Date: Wed, 20 Dec 2023 20:21:55 +0000 Subject: [PATCH 3/7] Update Changelog --- CHANGELOG.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 178ebf08..d5e0ae29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,12 @@ # Changelog -## [1.8.1a1](https://github.com/NeonGeckoCom/neon-utils/tree/1.8.1a1) (2023-12-15) +## [1.8.2a1](https://github.com/NeonGeckoCom/neon-utils/tree/1.8.2a1) (2023-12-20) -[Full Changelog](https://github.com/NeonGeckoCom/neon-utils/compare/1.8.0...1.8.1a1) +[Full Changelog](https://github.com/NeonGeckoCom/neon-utils/compare/1.8.1...1.8.2a1) **Merged pull requests:** -- Update `add_event` patching to work around FakeBus compat. [\#490](https://github.com/NeonGeckoCom/neon-utils/pull/490) ([NeonDaniel](https://github.com/NeonDaniel)) +- Better default profile handling [\#492](https://github.com/NeonGeckoCom/neon-utils/pull/492) ([NeonDaniel](https://github.com/NeonDaniel)) From 3379de61bcc58f6860c151ff577a6e1e95f70dbd Mon Sep 17 00:00:00 2001 From: Daniel McKnight <34697904+NeonDaniel@users.noreply.github.com> Date: Wed, 27 Dec 2023 12:03:20 -0800 Subject: [PATCH 4/7] Use OpenStreetMap geocoder to work around API changes (#493) Co-authored-by: Daniel McKnight --- neon_utils/location_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neon_utils/location_utils.py b/neon_utils/location_utils.py index 6cbb721a..0234030f 100644 --- a/neon_utils/location_utils.py +++ b/neon_utils/location_utils.py @@ -39,7 +39,7 @@ # geocode.maps.co nominatim.openstreetmap.org -_NOMINATIM_DOMAIN = "geocode.maps.co" +_NOMINATIM_DOMAIN = "nominatim.openstreetmap.org" def set_nominatim_domain(domain: str): From a40f4037b206835cf1d90843ff3039f020e052ef Mon Sep 17 00:00:00 2001 From: NeonDaniel Date: Wed, 27 Dec 2023 20:03:36 +0000 Subject: [PATCH 5/7] Increment Version to 1.8.2a2 --- version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.py b/version.py index 79cb5a9c..d8604c85 100644 --- a/version.py +++ b/version.py @@ -26,4 +26,4 @@ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -__version__ = "1.8.2a1" +__version__ = "1.8.2a2" From b13965f3d526935c08995310dbff848d0f77e8c1 Mon Sep 17 00:00:00 2001 From: NeonDaniel Date: Wed, 27 Dec 2023 20:04:29 +0000 Subject: [PATCH 6/7] Update Changelog --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d5e0ae29..249e4796 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## [1.8.2a2](https://github.com/NeonGeckoCom/neon-utils/tree/1.8.2a2) (2023-12-27) + +[Full Changelog](https://github.com/NeonGeckoCom/neon-utils/compare/1.8.2a1...1.8.2a2) + +**Merged pull requests:** + +- Use OpenStreetMap geocoder to work around maps.co API changes [\#493](https://github.com/NeonGeckoCom/neon-utils/pull/493) ([NeonDaniel](https://github.com/NeonDaniel)) + ## [1.8.2a1](https://github.com/NeonGeckoCom/neon-utils/tree/1.8.2a1) (2023-12-20) [Full Changelog](https://github.com/NeonGeckoCom/neon-utils/compare/1.8.1...1.8.2a1) From a61da612266b82c3d7a5c0c5be681592fb328cdf Mon Sep 17 00:00:00 2001 From: NeonDaniel Date: Wed, 27 Dec 2023 21:58:02 +0000 Subject: [PATCH 7/7] Increment Version to 1.8.2 --- version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.py b/version.py index d8604c85..c6ad4662 100644 --- a/version.py +++ b/version.py @@ -26,4 +26,4 @@ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -__version__ = "1.8.2a2" +__version__ = "1.8.2"