File tree Expand file tree Collapse file tree 3 files changed +19
-13
lines changed
Expand file tree Collapse file tree 3 files changed +19
-13
lines changed Original file line number Diff line number Diff line change 33import six
44
55from intercom .api_operations .find import Find
6- from intercom .generic_handlers .count import CountType
6+ from intercom .generic_handlers .count import Counter
7+ from intercom .generic_handlers .base_handler import BaseHandler
78from intercom .api_operations .count import Count as CountOperation
89from intercom .traits .api_resource import Resource
910
1011
11- @six .add_metaclass (CountType )
12- class Count (Resource , Find , CountOperation ):
12+ @six .add_metaclass (BaseHandler )
13+ class Count (Resource , Find , CountOperation , Counter ):
1314
1415 @classmethod
1516 def fetch_for_app (cls ):
Original file line number Diff line number Diff line change 22
33import re
44
5- count_breakdown_matcher = re .compile (r'(\w+)_counts_for_each_(\w+)' )
65
7- class CountType ( type ): # noqa
6+ class Counter ():
87
9- def __getattr__ (cls , name ): # noqa
10- match = count_breakdown_matcher .search (name )
11- if match :
12- entity_to_count = match .group (1 )
13- count_context = match .group (2 )
14- return cls .do_broken_down_count (entity_to_count , count_context )
8+ count_breakdown_matcher = re .compile (r'(\w+)_counts_for_each_(\w+)' )
9+
10+ @classmethod
11+ def handles_attr (cls , name ):
12+ return cls .count_breakdown_matcher .search (name ) is not None
13+
14+ @classmethod
15+ def _get (cls , entity , name ):
16+ match = cls .count_breakdown_matcher .search (name )
17+ entity_to_count = match .group (1 )
18+ count_context = match .group (2 )
19+ return entity .do_broken_down_count (entity_to_count , count_context )
Original file line number Diff line number Diff line change @@ -72,10 +72,10 @@ def test_company_counts_for_each_user(self):
7272 eq_ (count [self .company .name ], 1 )
7373
7474 def test_total_company_count (self ):
75- eq_ ( 1 , Company .count ())
75+ ok_ ( Company .count () >= 0 )
7676
7777 def test_total_user_count (self ):
78- eq_ ( 1 , User .count ())
78+ ok_ ( User .count () >= 0 )
7979
8080 def test_total_segment_count (self ):
8181 ok_ (Segment .count () >= 0 )
You can’t perform that action at this time.
0 commit comments