32
32
33
33
INVALID_STRINGS = [None , '' , 0 , 1 , True , False , list (), tuple (), dict (), object ()]
34
34
INVALID_NON_NEGATIVE_NUMS = [None , '' , 'foo' , - 1 , True , False , list (), tuple (), dict (), object ()]
35
+ INVALID_LISTS = [None , 'foo' , 0 , 1 , True , False , dict (), object ()]
36
+
35
37
36
38
class DLFixture (object ):
37
39
def __init__ (self , name = None ):
@@ -42,7 +44,6 @@ def __init__(self, name=None):
42
44
self .links_service = dynamic_links ._get_link_service (self .app )
43
45
44
46
def _instrument_dynamic_links (self , payload , status = 200 ):
45
-
46
47
request_url = dynamic_links ._LINKS_BASE_URL
47
48
recorder = []
48
49
self .links_service ._client .session .mount (request_url ,
@@ -70,7 +71,6 @@ def teardown_module():
70
71
firebase_admin .delete_app (firebase_admin .get_app ('testDLApp' ))
71
72
72
73
73
-
74
74
class TestGetStats (object ):
75
75
def test_get_stats (self , dltest ):
76
76
dltest ._instrument_dynamic_links (payload = MOCK_GET_STATS_RESPONSE )
@@ -103,23 +103,22 @@ def test_get_stats_invalid_url(self, dltest, invalid_url):
103
103
with pytest .raises (ValueError ) as excinfo :
104
104
dynamic_links .get_link_stats (invalid_url , options , app = dltest .app )
105
105
assert 'Url must be a string and begin with "https://".' in excinfo .value .message
106
-
106
+
107
107
@pytest .mark .parametrize ('invalid_options' , INVALID_STRINGS )
108
108
def test_get_stats_invalid_options (self , dltest , invalid_options ):
109
109
with pytest .raises (ValueError ) as excinfo :
110
110
dynamic_links .get_link_stats (_MOCK_SHORT_URL , invalid_options , app = dltest .app )
111
111
assert 'Options must be of type StatOptions.' in excinfo .value .message
112
-
112
+
113
113
@pytest .mark .parametrize ('invalid_duration' , [0 ] + INVALID_NON_NEGATIVE_NUMS )
114
114
def test_get_stats_invalid_duration_days (self , dltest , invalid_duration ):
115
115
options = dynamic_links .StatOptions (duration_days = invalid_duration )
116
116
with pytest .raises (ValueError ) as excinfo :
117
117
dynamic_links .get_link_stats (_MOCK_SHORT_URL , options , app = dltest .app )
118
118
assert 'duration_days' in excinfo .value .message
119
119
assert 'must be positive int' in excinfo .value .message
120
-
121
120
122
-
121
+
123
122
class TestEventStats (object ):
124
123
@pytest .mark .parametrize ('platform' , dynamic_links .EventStats ._platforms .keys ())
125
124
def test_valid_platform_values (self , platform ):
@@ -189,3 +188,17 @@ def test_invalid_count_values(self, arg):
189
188
event = dynamic_links .EVENT_TYPE_CLICK ,
190
189
count = arg )
191
190
assert 'must be a non negative int' in excinfo .value .message
191
+
192
+
193
+ class TestLinkStatsCreation (object ):
194
+ @pytest .mark .parametrize ('arg' , INVALID_LISTS )
195
+ def test_invalid_event_stats_list (self , arg ):
196
+ with pytest .raises (ValueError ) as excinfo :
197
+ dynamic_links .LinkStats (arg )
198
+ assert 'Must be a list or tuple' in excinfo .value .message
199
+
200
+ @pytest .mark .parametrize ('arg' , [list ([1 ,2 ]), list ('asdf' ), tuple ([1 ,2 ])])
201
+ def test_empty_event_stats_list (self , arg ):
202
+ with pytest .raises (ValueError ) as excinfo :
203
+ dynamic_links .LinkStats (arg )
204
+ assert 'elements of event stats must be "EventStats"' in excinfo .value .message
0 commit comments