|
16 | 16 | """Test cases for the firebase_admin.dynamic_links module."""
|
17 | 17 |
|
18 | 18 | import json
|
| 19 | +from itertools import product |
19 | 20 | import pytest
|
20 | 21 |
|
| 22 | +from tests import testutils |
| 23 | + |
21 | 24 | import firebase_admin
|
22 | 25 | from firebase_admin import dynamic_links
|
23 | 26 | from firebase_admin import credentials
|
24 | 27 |
|
25 |
| -from tests import testutils |
26 | 28 |
|
27 | 29 | MOCK_SHORT_URL = 'https://fake1.app.goo.gl/uQWc'
|
28 | 30 | MOCK_GET_STATS_RESPONSE = testutils.resource('get_link_stats.json')
|
29 |
| -COMPARE_GET_STATS_VALS = testutils.resource('get_link_stats_vals.json') |
| 31 | +COMPARE_GET_STATS_JSON = json.loads(testutils.resource('get_link_stats_vals.json')) |
30 | 32 |
|
31 | 33 | MOCK_CREDENTIAL = credentials.Certificate(
|
32 | 34 | testutils.resource_filename('service_account.json'))
|
@@ -86,8 +88,8 @@ def test_get_stats(self, dynamic_links_test):
|
86 | 88 | for event_stat in link_stats.event_stats:
|
87 | 89 | assert isinstance(event_stat, dynamic_links.EventStats)
|
88 | 90 |
|
89 |
| - assert len(COMPARE_GET_STATS_VALS) == len(link_stats.event_stats) |
90 |
| - for (direct, returned) in zip(COMPARE_GET_STATS_VALS, link_stats.event_stats): |
| 91 | + assert len(COMPARE_GET_STATS_JSON) == len(link_stats.event_stats) |
| 92 | + for (direct, returned) in zip(COMPARE_GET_STATS_JSON, link_stats.event_stats): |
91 | 93 | assert returned.platform == direct['platform']
|
92 | 94 | assert returned.event == direct['event']
|
93 | 95 | assert returned.count == direct['count']
|
@@ -127,72 +129,58 @@ def test_get_stats_invalid_duration_days(self, invalid_duration):
|
127 | 129 |
|
128 | 130 |
|
129 | 131 | class TestEventStats(object):
|
130 |
| - @pytest.mark.parametrize('platform', dynamic_links.EventStats._platforms.keys()) |
131 |
| - def test_valid_platform_values(self, platform): |
| 132 | + @pytest.mark.parametrize('platform, event', |
| 133 | + product(dynamic_links._platforms.keys(), |
| 134 | + dynamic_links._event_types.keys())) |
| 135 | + def test_valid_platform_values(self, platform, event): |
132 | 136 | event_stats = dynamic_links.EventStats(
|
133 |
| - platform=dynamic_links.EventStats._platforms[platform], |
134 |
| - event=dynamic_links.EVENT_TYPE_CLICK, |
135 |
| - count=1) |
136 |
| - assert event_stats.platform == dynamic_links.EventStats._platforms[platform] |
| 137 | + platform=platform, |
| 138 | + event=event, |
| 139 | + count='1') |
| 140 | + assert event_stats.platform == dynamic_links._platforms[platform] |
| 141 | + assert event_stats.event == dynamic_links._event_types[event] |
| 142 | + assert event_stats.count == 1 |
137 | 143 |
|
138 | 144 | @pytest.mark.parametrize('arg', INVALID_STRINGS + ['unrecognized'])
|
139 | 145 | def test_invalid_platform_values(self, arg):
|
140 | 146 | with pytest.raises(ValueError) as excinfo:
|
141 | 147 | dynamic_links.EventStats(
|
142 | 148 | platform=arg,
|
143 |
| - event=dynamic_links.EVENT_TYPE_CLICK, |
144 |
| - count=1) |
145 |
| - assert 'not recognized' in str(excinfo.value) |
| 149 | + event='CLICK', |
| 150 | + count='1') |
| 151 | + assert 'Invalid Platform value' in str(excinfo.value) |
146 | 152 |
|
147 |
| - @pytest.mark.parametrize('arg', dynamic_links.EventStats._platforms.keys()) |
148 |
| - def test_raw_platform_values_invalid(self, arg): |
149 |
| - with pytest.raises(ValueError) as excinfo: |
150 |
| - dynamic_links.EventStats( |
151 |
| - platform=arg, |
152 |
| - event=dynamic_links.EVENT_TYPE_CLICK, |
153 |
| - count=1) |
154 |
| - assert 'Raw string' in str(excinfo.value) |
155 |
| - |
156 |
| - @pytest.mark.parametrize('event', dynamic_links.EventStats._event_types.keys()) |
| 153 | + @pytest.mark.parametrize('event', dynamic_links._event_types.keys()) |
157 | 154 | def test_valid_event_values(self, event):
|
158 | 155 | event_stats = dynamic_links.EventStats(
|
159 |
| - platform=dynamic_links.PLATFORM_ANDROID, |
160 |
| - event=dynamic_links.EventStats._event_types[event], |
161 |
| - count=1) |
162 |
| - assert event_stats.event == dynamic_links.EventStats._event_types[event] |
| 156 | + platform='ANDROID', |
| 157 | + event=event, |
| 158 | + count='1') |
| 159 | + assert event_stats.event == dynamic_links._event_types[event] |
163 | 160 |
|
164 | 161 | @pytest.mark.parametrize('arg', INVALID_STRINGS + ['unrecognized'])
|
165 | 162 | def test_invalid_event_values(self, arg):
|
166 | 163 | with pytest.raises(ValueError) as excinfo:
|
167 | 164 | dynamic_links.EventStats(
|
168 |
| - platform=dynamic_links.PLATFORM_ANDROID, |
169 |
| - event=arg, |
170 |
| - count=1) |
171 |
| - assert 'not recognized' in str(excinfo.value) |
172 |
| - |
173 |
| - @pytest.mark.parametrize('arg', dynamic_links.EventStats._event_types.keys()) |
174 |
| - def test_raw_event_values_invalid(self, arg): |
175 |
| - with pytest.raises(ValueError) as excinfo: |
176 |
| - dynamic_links.EventStats( |
177 |
| - platform=dynamic_links.PLATFORM_ANDROID, |
| 165 | + platform='ANDROID', |
178 | 166 | event=arg,
|
179 |
| - count=1) |
180 |
| - assert 'Raw string' in str(excinfo.value) |
| 167 | + count='1') |
| 168 | + assert 'Invalid Event Type value' in str(excinfo.value) |
181 | 169 |
|
182 | 170 | @pytest.mark.parametrize('count', [1, 123, 1234])
|
183 | 171 | def test_valid_count_values(self, count):
|
184 | 172 | event_stats = dynamic_links.EventStats(
|
185 |
| - platform=dynamic_links.PLATFORM_ANDROID, |
186 |
| - event=dynamic_links.EVENT_TYPE_CLICK, |
| 173 | + platform='ANDROID', |
| 174 | + event='CLICK', |
187 | 175 | count=count)
|
188 | 176 | assert event_stats.count == count
|
189 | 177 |
|
190 | 178 | @pytest.mark.parametrize('arg', INVALID_NON_NEGATIVE_NUMS)
|
191 | 179 | def test_invalid_count_values(self, arg):
|
192 | 180 | with pytest.raises(ValueError) as excinfo:
|
193 | 181 | dynamic_links.EventStats(
|
194 |
| - platform=dynamic_links.PLATFORM_ANDROID, |
195 |
| - event=dynamic_links.EVENT_TYPE_CLICK, |
| 182 | + platform='ANDROID', |
| 183 | + event='CLICK', |
196 | 184 | count=arg)
|
197 | 185 | assert 'must be a non negative int' in str(excinfo.value)
|
198 | 186 |
|
|
0 commit comments