From add3baff745a276da424b3e73bcb7619ba5ca061 Mon Sep 17 00:00:00 2001 From: Bodnar Bogdan Date: Tue, 15 Aug 2017 17:52:12 +0200 Subject: [PATCH 1/3] Fix holding config variable in database through proxy objects A config variable may not necessarily be None when not configured. Can be stored in the database with the help of proxy objects, which can return the None value when accessed. For example, to integrate with jazzband/django-constance. --- analytical/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/analytical/utils.py b/analytical/utils.py index d915cf4..b0841cf 100644 --- a/analytical/utils.py +++ b/analytical/utils.py @@ -21,8 +21,8 @@ def get_required_setting(setting, value_re, invalid_msg): value = getattr(settings, setting) except AttributeError: raise AnalyticalException("%s setting: not found" % setting) - if value is None: - raise AnalyticalException("%s setting is set to None" % setting) + if not value: + raise AnalyticalException("%s setting is not set" % setting) value = str(value) if not value_re.search(value): raise AnalyticalException("%s setting: %s: '%s'" From 22403f9a039ff6ab81250f7ab73592f10ae16562 Mon Sep 17 00:00:00 2001 From: Bodnar Bogdan Date: Wed, 16 Aug 2017 10:20:13 +0200 Subject: [PATCH 2/3] Fix uservoice tests Rewrite test_empty_key in the same way as in the other modules. Delete test_overridden_empty_key, because the Node (In this case, the UserVoiceNode) should not be created if there is no configuration initially. --- analytical/tests/test_tag_uservoice.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/analytical/tests/test_tag_uservoice.py b/analytical/tests/test_tag_uservoice.py index d8f6a5b..8dab644 100644 --- a/analytical/tests/test_tag_uservoice.py +++ b/analytical/tests/test_tag_uservoice.py @@ -40,14 +40,7 @@ class UserVoiceTagTestCase(TagTestCase): @override_settings(USERVOICE_WIDGET_KEY='') def test_empty_key(self): - r = UserVoiceNode().render(Context()) - self.assertEqual(r, "") - - @override_settings(USERVOICE_WIDGET_KEY='') - def test_overridden_empty_key(self): - vars = {'uservoice_widget_key': 'bcdefghijklmnopqrstu'} - r = UserVoiceNode().render(Context(vars)) - self.assertIn("widget.uservoice.com/bcdefghijklmnopqrstu.js", r) + self.assertRaises(AnalyticalException, UserVoiceNode) def test_overridden_key(self): vars = {'uservoice_widget_key': 'defghijklmnopqrstuvw'} From 9df11828777701cc84ef25eafc06b69a8f3316d0 Mon Sep 17 00:00:00 2001 From: Bodnar Bogdan Date: Wed, 16 Aug 2017 10:27:11 +0200 Subject: [PATCH 3/3] Fix exception message --- analytical/tests/test_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/analytical/tests/test_utils.py b/analytical/tests/test_utils.py index 0f4ad58..c3b8049 100644 --- a/analytical/tests/test_utils.py +++ b/analytical/tests/test_utils.py @@ -29,11 +29,11 @@ class SettingDeletedTestCase(TestCase): # available in python >= 3.2 if hasattr(self, 'assertRaisesRegex'): - with self.assertRaisesRegex(AnalyticalException, "^USER_ID setting is set to None$"): + with self.assertRaisesRegex(AnalyticalException, "^USER_ID setting is not set$"): user_id = get_required_setting("USER_ID", "\d+", "invalid USER_ID") # available in python >= 2.7, deprecated in 3.2 elif hasattr(self, 'assertRaisesRegexp'): - with self.assertRaisesRegexp(AnalyticalException, "^USER_ID setting is set to None$"): + with self.assertRaisesRegexp(AnalyticalException, "^USER_ID setting is not set$"): user_id = get_required_setting("USER_ID", "\d+", "invalid USER_ID") else: self.assertRaises(AnalyticalException,