@@ -326,6 +326,60 @@ def test_session_query_include_counter_and_document(self):
326
326
327
327
self .assertEqual (1 , session .advanced .number_of_requests )
328
328
329
+ def test_session_query_include_all_counters (self ):
330
+ with self .store .open_session () as session :
331
+ session .store (Order (company = "companies/1-A" ), "orders/1-A" )
332
+ session .store (Order (company = "companies/2-A" ), "orders/2-A" )
333
+ session .store (Order (company = "companies/3-A" ), "orders/3-A" )
334
+
335
+ session .counters_for ("orders/1-A" ).increment ("Downloads" , 100 )
336
+ session .counters_for ("orders/2-A" ).increment ("Downloads" , 200 )
337
+ session .counters_for ("orders/3-A" ).increment ("Downloads" , 300 )
338
+
339
+ session .counters_for ("orders/1-A" ).increment ("Likes" , 1000 )
340
+ session .counters_for ("orders/2-A" ).increment ("Likes" , 2000 )
341
+
342
+ session .counters_for ("orders/1-A" ).increment ("Votes" , 10000 )
343
+ session .counters_for ("orders/3-A" ).increment ("Cats" , 5 )
344
+
345
+ session .save_changes ()
346
+
347
+ with self .store .open_session () as session :
348
+ query = session .query (object_type = Order ).include (lambda i : i .include_all_counters ())
349
+
350
+ self .assertEqual ("from 'Orders' include counters()" , query ._to_string ())
351
+
352
+ query_result = list (query )
353
+ self .assertEqual (1 , session .advanced .number_of_requests )
354
+
355
+ # included counters should be in cache
356
+ order = query_result [0 ]
357
+ self .assertEqual ("orders/1-A" , order .Id )
358
+
359
+ dic = session .counters_for_entity (order ).get_all ()
360
+ self .assertEqual (3 , len (dic ))
361
+ self .assertIn (("downloads" , 100 ), dic .items ())
362
+ self .assertIn (("likes" , 1000 ), dic .items ())
363
+ self .assertIn (("votes" , 10000 ), dic .items ())
364
+
365
+ order = query_result [1 ]
366
+ self .assertEqual ("orders/2-A" , order .Id )
367
+
368
+ dic = session .counters_for_entity (order ).get_all ()
369
+ self .assertEqual (2 , len (dic ))
370
+ self .assertIn (("downloads" , 200 ), dic .items ())
371
+ self .assertIn (("likes" , 2000 ), dic .items ())
372
+
373
+ order = query_result [2 ]
374
+ self .assertEqual ("orders/3-A" , order .Id )
375
+
376
+ dic = session .counters_for_entity (order ).get_all ()
377
+ self .assertEqual (2 , len (dic ))
378
+ self .assertIn (("downloads" , 300 ), dic .items ())
379
+ self .assertIn (("cats" , 5 ), dic .items ())
380
+
381
+ self .assertEqual (1 , session .advanced .number_of_requests )
382
+
329
383
def test_session_query_include_all_counters_of_document_and_of_related_document (self ):
330
384
with self .store .open_session () as session :
331
385
session .store (Order (employee = "employees/1-A" ), "orders/1-A" )
0 commit comments