]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Trader.git/commitdiff
Add logging at market instance creation
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Wed, 4 Apr 2018 10:02:13 +0000 (12:02 +0200)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Wed, 4 Apr 2018 10:38:28 +0000 (12:38 +0200)
.gitattributes [new file with mode: 0644]
market.py
store.py
test.py

diff --git a/.gitattributes b/.gitattributes
new file mode 100644 (file)
index 0000000..227f825
--- /dev/null
@@ -0,0 +1,2 @@
+*.py       diff=python
+/store.py  export-subst
index ac3aa14a9213ba817db4a431cbc3ddd0649e460e..10d1ad8936b3f671ca2ca7e9a1623a856dce29db 100644 (file)
--- a/market.py
+++ b/market.py
@@ -28,6 +28,9 @@ class Market:
         for key in ["user_id", "market_id", "report_path", "pg_config"]:
             setattr(self, key, kwargs.get(key, None))
 
+        self.report.log_market(self.args, self.user_id, self.market_id,
+                self.report_path, self.debug)
+
     @classmethod
     def from_config(cls, config, args, **kwargs):
         config["apiKey"] = config.pop("key", None)
index b3ada4567e38a28613efd0159dafd33ece105a0d..2b5c18a1a1a65eb241af2677d322195a5202d18d 100644 (file)
--- a/store.py
+++ b/store.py
@@ -209,6 +209,17 @@ class ReportStore:
             "action": action,
             })
 
+    def log_market(self, args, user_id, market_id, report_path, debug):
+        self.add_log({
+            "type": "market",
+            "commit": "$Format:%H$",
+            "args": vars(args),
+            "user_id": user_id,
+            "market_id": market_id,
+            "report_path": report_path,
+            "debug": debug,
+            })
+
 class BalanceStore:
     def __init__(self, market):
         self.market = market
diff --git a/test.py b/test.py
index a9a80c5714cda8e68312194e4e88a5dc50dd2f19..29403d46c6e48d53b15d61c4e5f9433594ccd329 100644 (file)
--- a/test.py
+++ b/test.py
@@ -1181,9 +1181,12 @@ class MarketTest(WebMockTestCase):
             with self.subTest(quiet=False):
                 m = market.Market(self.ccxt, self.market_args(quiet=False))
                 report_store.assert_called_with(m, verbose_print=True)
+                report_store().log_market.assert_called_once()
+            report_store.reset_mock()
             with self.subTest(quiet=True):
                 m = market.Market(self.ccxt, self.market_args(quiet=True))
                 report_store.assert_called_with(m, verbose_print=False)
+                report_store().log_market.assert_called_once()
 
     @mock.patch("market.ccxt")
     def test_from_config(self, ccxt):
@@ -4346,6 +4349,25 @@ class ReportStoreTest(WebMockTestCase):
             'response': 'Hey'
             })
 
+    @mock.patch.object(market.ReportStore, "add_log")
+    def test_log_market(self, add_log):
+        report_store = market.ReportStore(self.m)
+        class Args:
+            def __init__(self):
+                self.debug = True
+                self.quiet = False
+
+        report_store.log_market(Args(), 4, 1, "report", True)
+        add_log.assert_called_once_with({
+            "type": "market",
+            "commit": "$Format:%H$",
+            "args": { "debug": True, "quiet": False },
+            "user_id": 4,
+            "market_id": 1,
+            "report_path": "report",
+            "debug": True
+            })
+
     @mock.patch.object(market.ReportStore, "print_log")
     @mock.patch.object(market.ReportStore, "add_log")
     def test_log_error(self, add_log, print_log):