8000 comments · ClarkDing/firebase-admin-python@79f9d61 · GitHub
[go: up one dir, main page]

Skip to content

Commit 79f9d61

Browse files
committed
comments
1 parent 8333d89 commit 79f9d61

File tree

4 files changed

+33
-42
lines changed

4 files changed

+33
-42
lines changed

CONTRIBUTING.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,18 @@ Now you can invoke the integration test suite as follows:
177177
pytest integration/ --cert path/to/service_acct.json --apikey path/to/apikey.txt
178178
```
179179

180+
### End to end testing for dynamic links.
181+
182+
To run end to end tests for Firebase dynamic follow these steps:
183+
184+
1. From the firebase console, create a short link under "Grow > Dynamic Links".
185+
2. From your broser or phone, go to that short link and see that it redirects as desired.
186+
3. Wait up to 36 hours for stats to show up on the console.
187+
4. Create a file named dynamic_links_e2e_url.txt under tests/data/.
188+
5. Populate that file with the short link you created in #1
189+
e.g. $ echo 'https://your1.app.goo.gl/suff' > tests/data/dynamic_links_e2e_url.txt
190+
191+
180192
### Test Coverage
181193

182194
To review the test coverage, run `pytest` with the `--cov` flag. To view a detailed line by line

firebase_admin/dynamic_links.py

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,23 @@ class EventStats(object):
116116

117117
def __init__(self, platform, event, count):
118118
"""Create new instance of EventStats(platform, event, count)"""
119-
self.platform = platform
120-
self.event = event
121-
self.count = count
119+
if isinstance(platform, six.string_types) and platform in self._platforms.keys():
120+
raise ValueError(('Raw string "{}" detected. Use a dynamic_links.PLATFORM_* constant' +
121+
' or the make_event_stat() method.').format(platform))
122+
if not isinstance(platform, six.string_types) or platform not in self._platforms.values():
123+
raise ValueError('platform {}, not recognized'.format(platform))
124+
self._platform = platform
125+
126+
if isinstance(event, six.string_types) and event in self._event_types.keys():
127+
raise ValueError(('Raw string {} detected. Use one of the dynamic_links.EVENT_TYPES_' +
128+
' constants, or the make_event_stat() method.').format(event))
129+
if not isinstance(event, six.string_types) or event not in self._event_types.values():
130+
raise ValueError('event_type {}, not recognized'.format(event))
131+
self._event = event
132+
133+
if not isinstance(count, int) or isinstance(count, bool) or count < 0:
134+
raise ValueError('Count: {} must be a non negative int'.format(count))
135+
self._count = count
122136

123137
def __repr__(self):
124138
return"EventStats(platform: '{}', event: '{}', count: '{}')".format(
@@ -136,38 +150,14 @@ def make_event_stat(cls, platform, event, count):
136150
def platform(self):
137151
return self._platform
138152

139-
@platform.setter
140-
def platform(self, platform):
141-
if isinstance(platform, six.string_types) and platform in self._platforms.keys():
142-
raise ValueError(('Raw string {} detected. Use one of the dynamic_links.PLATFORM_...' +
143-
' constants, or the make_event_stat() method.').format(platform))
144-
if not isinstance(platform, six.string_types) or platform not in self._platforms.values():
145-
raise ValueError('platform {}, not recognized'.format(platform))
146-
self._platform = platform
147-
148153
@property
149154
def event(self):
150155
return self._event
151156

152-
@event.setter
153-
def event(self, event):
154-
if isinstance(event, six.string_types) and event in self._event_types.keys():
155-
raise ValueError(('Raw string {} detected. Use one of the dynamic_links.EVENT_TYPES_' +
156-
' constants, or the make_event_stat() method.').format(event))
157-
if not isinstance(event, six.string_types) or event not in self._event_types.values():
158-
raise ValueError('event_type {}, not recognized'.format(event))
159-
self._event = event
160-
161157
@property
162158
def count(self):
163159
return self._count
164160

165-
@count.setter
166-
def count(self, count):
167-
if not isinstance(count, int) or isinstance(count, bool) or count < 0:
168-
raise ValueError('Count: {} must be a non negative int'.format(count))
169-
self._count = count
170-
171161

172162
class StatOptions(object):
173163
def __init__(self, duration_days):

integration/test_dynamic_links.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@
1515
"""Integration tests for firebase_admin.auth module."""
1616
import sys
1717

18-
import pytest
1918
import requests
20-
19+
import pytest
2120

2221
from firebase_admin import dynamic_links
2322

@@ -27,17 +26,7 @@
2726
try:
2827
dynamic_links_e2e_url = testutils.resource('dynamic_links_e2e_url.txt').strip()
2928
except IOError:
30-
sys.stderr.write("""
31-
==============================================================================================
32-
To run end to end tests you must do the following:
33-
1. From the firebase console, create a short link under "Grow > Dynamic Links".
34-
2. From your broser or phone, go to that short link and see that it redirects.
35-
3. Wait up to 36 hours.
36-
4. Create a file named dynamic_links_e2e_url.txt under tests/data/.
37-
5. Populate that file with the quoted link you created in 1 on the first and only line
38-
e.g. $ echo "https://your1.app.goo.gl/suff" > tests/data/dynamic_links_e2e_url.txt
39-
===============================================================================================
40-
""")
29+
sys.stderr.write("End to end tests not set up, see CONTRIBTING.md file.")
4130

4231
class TestEndToEnd(object):
4332
"""Runs an end to end test, see comment string for setup."""
@@ -52,7 +41,7 @@ def test_get_stats(self):
5241
assert len(link_stats.event_stats) > 0
5342

5443
def test_get_stats_nonexistant_link(self):
55-
if(dynamic_links_e2e_url) == 0:
44+
if not dynamic_links_e2e_url:
5645
return
5746
link_stats = dynamic_links.get_link_stats(
5847
dynamic_links_e2e_url + 'some_arbitary_unlikely_string_ZXCzxcASDasdQWEqwe',

tests/test_dynamic_links.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def test_invalid_count_values(self, arg):
194194
assert 'must be a non negative int' in str(excinfo.value)
195195

196196

197-
class TestLinkStatsCreation(object):
197+
class TestLinkStats(object):
198198
@pytest.mark.parametrize('arg', INVALID_LISTS)
199199
def test_invalid_event_stats_list(self, arg):
200200
with pytest.raises(ValueError) as excinfo:

0 commit comments

Comments
 (0)
0