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 3
3
import six
4
4
5
5
from 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
7
8
from intercom .api_operations .count import Count as CountOperation
8
9
from intercom .traits .api_resource import Resource
9
10
10
11
11
- @six .add_metaclass (CountType )
12
- class Count (Resource , Find , CountOperation ):
12
+ @six .add_metaclass (BaseHandler )
13
+ class Count (Resource , Find , CountOperation , Counter ):
13
14
14
15
@classmethod
15
16
def fetch_for_app (cls ):
Original file line number Diff line number Diff line change 2
2
3
3
import re
4
4
5
- count_breakdown_matcher = re .compile (r'(\w+)_counts_for_each_(\w+)' )
6
5
7
- class CountType ( type ): # noqa
6
+ class Counter ():
8
7
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):
72
72
eq_ (count [self .company .name ], 1 )
73
73
74
74
def test_total_company_count (self ):
75
- eq_ ( 1 , Company .count ())
75
+ ok_ ( Company .count () >= 0 )
76
76
77
77
def test_total_user_count (self ):
78
- eq_ ( 1 , User .count ())
78
+ ok_ ( User .count () >= 0 )
79
79
80
80
def test_total_segment_count (self ):
81
81
ok_ (Segment .count () >= 0 )
You can’t perform that action at this time.
0 commit comments