-
-
Notifications
You must be signed in to change notification settings - Fork 747
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4141 from StackStorm/better-st2api-logs
Log successful connections to mongo
- Loading branch information
Showing
2 changed files
with
35 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,6 +70,12 @@ def test_db_setup_connecting_info_logging(self, mock_log): | |
actual_message = mock_log.info.call_args_list[0][0][0] | ||
self.assertEqual(expected_message, actual_message) | ||
|
||
# Check for helpful error messages if the connection is successful | ||
expected_log_message = ('Successfully connected to database "st2" @ "localhost:27017" as ' | ||
'user "user_st2".') | ||
actual_log_message = mock_log.info.call_args_list[1][0][0] | ||
self.assertEqual(expected_log_message, actual_log_message) | ||
|
||
# 2. Password provided as part of uri string (single host) | ||
db_host = 'mongodb://user_st22:[email protected]:5555' | ||
username = None | ||
|
@@ -78,9 +84,14 @@ def test_db_setup_connecting_info_logging(self, mock_log): | |
password=password) | ||
|
||
expected_message = 'Connecting to database "st2" @ "127.0.0.2:5555" as user "user_st22".' | ||
actual_message = mock_log.info.call_args_list[1][0][0] | ||
actual_message = mock_log.info.call_args_list[2][0][0] | ||
self.assertEqual(expected_message, actual_message) | ||
|
||
expected_log_message = ('Successfully connected to database "st2" @ "127.0.0.2:5555" as ' | ||
'user "user_st22".') | ||
actual_log_message = mock_log.info.call_args_list[3][0][0] | ||
self.assertEqual(expected_log_message, actual_log_message) | ||
|
||
# 3. Password provided as part of uri string (single host) - username | ||
# provided as argument has precedence | ||
db_host = 'mongodb://user_st210:[email protected]:5555' | ||
|
@@ -90,9 +101,14 @@ def test_db_setup_connecting_info_logging(self, mock_log): | |
password=password) | ||
|
||
expected_message = 'Connecting to database "st2" @ "127.0.0.2:5555" as user "user_st23".' | ||
actual_message = mock_log.info.call_args_list[2][0][0] | ||
actual_message = mock_log.info.call_args_list[4][0][0] | ||
self.assertEqual(expected_message, actual_message) | ||
|
||
expected_log_message = ('Successfully connected to database "st2" @ "127.0.0.2:5555" as ' | ||
'user "user_st23".') | ||
actual_log_message = mock_log.info.call_args_list[5][0][0] | ||
self.assertEqual(expected_log_message, actual_log_message) | ||
|
||
# 4. Just host provided in the url string | ||
db_host = 'mongodb://127.0.0.2:5555' | ||
username = 'user_st24' | ||
|
@@ -101,9 +117,14 @@ def test_db_setup_connecting_info_logging(self, mock_log): | |
password=password) | ||
|
||
expected_message = 'Connecting to database "st2" @ "127.0.0.2:5555" as user "user_st24".' | ||
actual_message = mock_log.info.call_args_list[3][0][0] | ||
actual_message = mock_log.info.call_args_list[6][0][0] | ||
self.assertEqual(expected_message, actual_message) | ||
|
||
expected_log_message = ('Successfully connected to database "st2" @ "127.0.0.2:5555" as ' | ||
'user "user_st24".') | ||
actual_log_message = mock_log.info.call_args_list[7][0][0] | ||
self.assertEqual(expected_log_message, actual_log_message) | ||
|
||
# 5. Multiple hosts specified as part of connection uri | ||
db_host = 'mongodb://user6:pass6@host1,host2,host3' | ||
username = None | ||
|
@@ -113,9 +134,15 @@ def test_db_setup_connecting_info_logging(self, mock_log): | |
|
||
expected_message = ('Connecting to database "st2" @ "host1:27017,host2:27017,host3:27017 ' | ||
'(replica set)" as user "user6".') | ||
actual_message = mock_log.info.call_args_list[4][0][0] | ||
actual_message = mock_log.info.call_args_list[8][0][0] | ||
self.assertEqual(expected_message, actual_message) | ||
|
||
expected_log_message = ('Successfully connected to database "st2" @ ' | ||
'"host1:27017,host2:27017,host3:27017 ' | ||
'(replica set)" as user "user6".') | ||
actual_log_message = mock_log.info.call_args_list[9][0][0] | ||
self.assertEqual(expected_log_message, actual_log_message) | ||
|
||
|
||
class DbCleanupTest(DbTestCase): | ||
|
||
|