betodealmeida commented on a change in pull request #13441:
URL: https://github.com/apache/superset/pull/13441#discussion_r586912259



##########
File path: tests/event_logger_tests.py
##########
@@ -101,3 +106,29 @@ def test_func(arg1, add_extra_log_payload, karg1=1):
                 ],
             )
             self.assertGreaterEqual(payload["duration_ms"], 100)
+
+    def test_context_manager_log(self):
+        class DummyEventLogger(AbstractEventLogger):
+            def __init__(self):
+                self.records = []
+
+            def log(
+                self,
+                user_id: Optional[int],
+                action: str,
+                dashboard_id: Optional[int],
+                duration_ms: Optional[int],
+                slice_id: Optional[int],
+                referrer: Optional[str],
+                *args: Any,
+                **kwargs: Any,
+            ):
+                self.records.append(kwargs)

Review comment:
       You might want to store more stuff here, to check that `user_id` is set, 
for example.
   
   Another cool thing you might want to do is test that `duration` is computed 
correctly. There's a nice Python module called `freezegun` that allows you to 
do that. Something like this:
   
   ```python
   from freezegun import freeze_time
   
   # the first time datetime.now() is called returns 2020-01-14; subsequent 
calls
   # are incremented by 15 seconds
   @freeze_time("Jan 14th, 2020", auto_tick_seconds=15)
   def test_context_manager_log(self):
       ...
       # change `log()` to also store duration
       assert logger.records[0]["duration"] == timedelta(seconds=15)
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to