-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
125 additions
and
5 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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import datetime | ||
from mock import patch | ||
from opal.core.test import OpalTestCase | ||
from elcid import utils | ||
|
||
|
||
class ModelMethodLoggingTestCase(OpalTestCase): | ||
|
||
def test_logging_method(self): | ||
class LoggingTest(object): | ||
id = 1 | ||
|
||
@utils.model_method_logging | ||
def some_method(self): | ||
return "some_var" | ||
a = LoggingTest() | ||
with patch.object(utils.logger, "info") as info: | ||
with patch("elcid.utils.timezone.now") as now: | ||
first_call = datetime.datetime(2018, 2, 3, 10, 21) | ||
second_call = first_call + datetime.timedelta(minutes=1) | ||
now.side_effect = [first_call, second_call] | ||
result = a.some_method() | ||
first_call = info.call_args_list[0][0][0] | ||
second_call = info.call_args_list[1][0][0] | ||
self.assertEqual( | ||
first_call, "2018-02-03 10:21:00 starting LoggingTest.some_method \ | ||
(id 1)" | ||
) | ||
self.assertEqual( | ||
second_call, | ||
"2018-02-03 10:22:00 finishing LoggingTest.some_method (id 1) for \ | ||
2018-02-03 10:21:00" | ||
) | ||
self.assertEqual( | ||
result, "some_var" | ||
) |
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
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
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