-
Notifications
You must be signed in to change notification settings - Fork 3
Set of small fixes #20
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,7 +32,8 @@ | |
| "type": "elastic", | ||
| "connection": [{"host": "127.0.0.1", "port": 9200}] | ||
| }, | ||
| "notify_backends": {} | ||
| "notify_backends": {}, | ||
| "logging": {"level": "INFO"} | ||
| } | ||
|
|
||
| CONF_SCHEMA = { | ||
|
|
@@ -69,23 +70,13 @@ | |
| "notify_backends": { | ||
| "type": "object", | ||
| "properties": { | ||
| "*": { | ||
| "type": "object", | ||
| "properties": { | ||
| "salesforce": { | ||
| "type": "object", | ||
| "properties": { | ||
| "atuh_url": {"type": "string"}, | ||
| "username": {"type": "string"}, | ||
| "password": {"type": "string"}, | ||
| "environment": {"type": "string"}, | ||
| "client_id": {"type": "string"}, | ||
| "client_secret": {"type": "string"}, | ||
| "organization_id": {"type": "string"} | ||
| } | ||
| } | ||
| } | ||
| } | ||
| "*": {"type": "object"} | ||
| } | ||
| }, | ||
| "logging": { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would suggest not to add this functionality right now and do it properly later by dying the appropriate configuration of logging throught
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This commit is already merged by another pull request (as dependency) so let's fix this later during integration with oss-lib |
||
| "type": "object", | ||
| "properties": { | ||
| "level": {"type": "string"} | ||
| } | ||
| } | ||
| }, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| # Copyright 2016: Mirantis Inc. | ||
| # All Rights Reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
| # not use this file except in compliance with the License. You may obtain | ||
| # a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| # License for the specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| import mock | ||
|
|
||
| from notify import driver | ||
| from notify.drivers import dummy_err | ||
| from notify.drivers import dummy_err_explained | ||
| from notify.drivers import dummy_fail | ||
| from notify.drivers import dummy_pass | ||
| from notify.drivers import dummy_random | ||
| from tests.unit import test | ||
|
|
||
|
|
||
| class DummyErrDriverTestCase(test.TestCase): | ||
|
|
||
| def test_notify(self): | ||
| e = self.assertRaises(ValueError, | ||
| dummy_err.Driver({}).notify, self.payload) | ||
| self.assertEqual("This error message is for logging only!", str(e)) | ||
|
|
||
|
|
||
| class DummyErrExplainedDriverTestCase(test.TestCase): | ||
|
|
||
| def test_notify(self): | ||
| e = self.assertRaises(driver.ExplainedError, | ||
| dummy_err_explained.Driver({}).notify, | ||
| self.payload) | ||
| self.assertEqual("This error message must appear in API response!", | ||
| str(e)) | ||
|
|
||
|
|
||
| class DummyFailDriverTestCase(test.TestCase): | ||
|
|
||
| def test_notify(self): | ||
| self.assertFalse(dummy_fail.Driver({}).notify(self.payload)) | ||
|
|
||
|
|
||
| class DummyPassDriverTestCase(test.TestCase): | ||
|
|
||
| def test_notify(self): | ||
| self.assertTrue(dummy_pass.Driver({}).notify(self.payload)) | ||
|
|
||
|
|
||
| class DummyRandomDriverTestCase(test.TestCase): | ||
|
|
||
| @mock.patch("notify.drivers.dummy_random.random.random") | ||
| def test_notify(self, mock_random): | ||
| drv = dummy_random.Driver({}) | ||
|
|
||
| mock_random.return_value = 0.49 | ||
| self.assertTrue(drv.notify(self.payload)) | ||
|
|
||
| mock_random.return_value = 0.51 | ||
| self.assertFalse(drv.notify(self.payload)) | ||
|
|
||
| drv = dummy_random.Driver({"probability": 0.53}) | ||
| self.assertTrue(drv.notify(self.payload)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
loggingitself formats the string and you should not do it explicitly becauseloggingdoes it according to the specified level and can skip the formatting if it is not necessary. So, instead ofyou should do:
Unfortunately,
loggingdoes not support the format style by default.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed all such occurrences in seecloud/availability#24 and other projects as well.