10000 rename duration days -> last n days. · ClarkDing/firebase-admin-python@df9e959 · GitHub
[go: up one dir, main page]

Skip to content

Commit df9e959

Browse files
committed
rename duration days -> last n days.
1 parent 3b102c1 commit df9e959

File tree

3 files changed

+28
-28
lines changed

3 files changed

+28
-28
lines changed

firebase_admin/dynamic_links.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def get_link_stats(short_link, stat_options, app=None):
7272
short_link: The string of the designated short link. e.g. https://abc12.app.goo.gl/link
7373
The credential with which the firebase.App is initialized must be associated
7474
with the project that the requested link belongs to.
75-
stat_options: An object containing a single field "duration_days" for which the statistics
75+
stat_options: An object containing a single field "last_n_days" for which the statistics
7676
are retrieved.
7777
app: A Firebase ``App instance`` (optional). (If missing uses default app.)
7878
@@ -82,7 +82,7 @@ def get_link_stats(short_link, stat_options, app=None):
8282
Raises:
8383
ValueError: If any of the arguments are invalid.
8484
``short_link`` must start with the "https" protocol.
85-
``stat_options`` must have duration_days > 0.
85+
``stat_options`` must have last_n_days > 0.
8686
"""
8787
return _get_link_service(app).get_stats(short_link, stat_options)
8888

@@ -179,17 +179,17 @@ def count(self):
179179

180180

181181
class StatOptions(object):
182-
def __init__(self, duration_days):
183-
if (isinstance(duration_days, bool)
184-
or not isinstance(duration_days, int)
185-
or duration_days < 1):
186-
raise ValueError('duration_days must be positive integer (got {})'
187-
.format(duration_days))
188-
self._duration_days = duration_days
182+
def __init__(self, last_n_days):
183+
if (isinstance(last_n_days, bool)
184+
or not isinstance(last_n_days, int)
185+
or last_n_days < 1):
186+
raise ValueError('last_n_days must be positive integer (got {})'
187+
.format(last_n_days))
188+
self._last_n_days = last_n_days
189189

190190
@property
191-
def duration_days(self):
192-
return self._duration_days
191+
def last_n_days(self):
192+
return self._last_n_days
193193

194194

195195
class _DynamicLinksService(object):
@@ -203,7 +203,7 @@ def __init__(self, app):
203203
self._request_string = '{0}/linkStats?durationDays={1}'
204204

205205
def _format_request_string(self, short_link, options):
206-
days = options.duration_days
206+
days = options.last_n_days
207207
# Complaints about the named second argument needed to replace "/"
208208
url_quoted = urllib.parse.quote(short_link, safe='') # pylint: disable=redundant-keyword-arg
209209
return self._request_string.format(url_quoted, days)

integration/test_dynamic_links.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ class TestEndToEnd(object):
3434
def test_get_stats(self):
3535
link_stats = dynamic_links.get_link_stats(
3636
dynamic_links_e2e_url,
37-
dynamic_links.StatOptions(duration_days=4000))
37+
dynamic_links.StatOptions(last_n_days=4000))
3838
assert isinstance(link_stats, dynamic_links.LinkStats)
3939
assert len(link_stats.event_stats) > 0
4040

4141
def test_get_stats_nonexistant_link(self):
4242
link_stats = dynamic_links.get_link_stats(
4343
dynamic_links_e2e_url + 'some_arbitary_unlikely_string_ZXCzxcASDasdQWEqwe',
44-
dynamic_links.StatOptions(duration_days=4000))
44+
dynamic_links.StatOptions(last_n_days=4000))
4545
assert isinstance(link_stats, dynamic_links.LinkStats)
4646
assert len(link_stats.event_stats) == 0
4747

@@ -50,7 +50,7 @@ def test_unauthorized(self):
5050
with pytest.raises(dynamic_links.ApiCallError) as excinfo:
5151
dynamic_links.get_link_stats(
5252
'https://fake1.app.goo.gl/uQWc',
53-
dynamic_links.StatOptions(duration_days=4000))
53+
dynamic_links.StatOptions(last_n_days=4000))
5454
assert excinfo.value.code == 'authentication-error'
5555

5656
@pytest.mark.skipif(not dynamic_links_e2e_url,
@@ -59,6 +59,6 @@ def test_bad_request(self):
5959
with pytest.raises(dynamic_links.ApiCallError) as excinfo:
6060
dynamic_links.get_link_stats(
6161
dynamic_links_e2e_url + '/too/many/slashes/in/shortlink',
62-
dynamic_links.StatOptions(duration_days=4000))
62+
dynamic_links.StatOptions(last_n_days=4000))
6363
assert excinfo.value.code == 'invalid-argument'
6464
assert 'Request contains an invalid argument' in str(excinfo.value)

tests/test_dynamic_links.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class TestGetStats(object):
7878
def test_get_stats(self, dynamic_links_test):
7979
_, recorder = dynamic_links_test._instrument_dynamic_links(
8080
payload=MOCK_GET_STATS_RESPONSE)
81-
options = dynamic_links.StatOptions(duration_days=9)
81+
options = dynamic_links.StatOptions(last_n_days=9)
8282
link_stats = dynamic_links.get_link_stats(
8383
MOCK_SHORT_URL, options, app=dynamic_links_test.app)
8484
assert recorder[0].url.startswith('https://firebasedynamiclinks.googleapis.com')
@@ -96,7 +96,7 @@ def test_get_stats(self, dynamic_links_test):
9696

9797
@pytest.mark.parametrize('error_code', [400, 401, 500])
9898
def test_server_error(self, dynamic_links_test, error_code):
99-
options = dynamic_links.StatOptions(duration_days=9)
99+
options = dynamic_links.StatOptions(last_n_days=9)
100100
dynamic_links_test._instrument_dynamic_links(
101101
payload=json.dumps({'error': {
102102
'status': 'INTERNAL_ERROR',
@@ -111,7 +111,7 @@ def test_server_error(self, dynamic_links_test, error_code):
111111

112112
@pytest.mark.parametrize('error_code', [400, 401, 500])
113113
def test_server_unformatted_error(self, dynamic_links_test, error_code):
114-
options = dynamic_links.StatOptions(duration_days=9)
114+
options = dynamic_links.StatOptions(last_n_days=9)
115115
dynamic_links_test._instrument_dynamic_links(
116116
payload='custom error message',
117117
status=error_code)
@@ -122,7 +122,7 @@ def test_server_unformatted_error(self, dynamic_links_test, error_code):
122122
assert excinfo.value.code == dynamic_links._UNKNOWN_ERROR
123123

124124
def test_server_non_payload_error(self, dynamic_links_test):
125-
options = dynamic_links.StatOptions(duration_days=9)
125+
options = dynamic_links.StatOptions(last_n_days=9)
126126
dynamic_links_test._instrument_dynamic_links(
127127
payload='',
128128
status=400)
@@ -135,30 +135,30 @@ def test_server_non_payload_error(self, dynamic_links_test):
135135

136136
@pytest.mark.parametrize('invalid_url', ['google.com'] + INVALID_STRINGS)
137137
def test_get_stats_invalid_url(self, dynamic_links_test, invalid_url):
138-
options = dynamic_links.StatOptions(duration_days=9)
138+
options = dynamic_links.StatOptions(last_n_days=9)
139139
with pytest.raises(ValueError) as excinfo:
140140
dynamic_links.get_link_stats(invalid_url, options, app=dynamic_links_test.app)
141141
assert 'short_link must be a string and begin with "https://".' in str(excinfo.value)
142-
142+
143143
@pytest.mark.parametrize('invalid_options', INVALID_STRINGS)
144144
def test_get_stats_invalid_options(self, dynamic_links_test, invalid_options):
145145
with pytest.raises(ValueError) as excinfo:
146146
dynamic_links.get_link_stats(
147147
MOCK_SHORT_URL, invalid_options, app=dynamic_links_test.app)
148148
assert 'stat_options must be of type StatOptions.' in str(excinfo.value)
149-
149+
150150
@pytest.mark.parametrize('invalid_duration', [0] + INVALID_NON_NEGATIVE_NUMS)
151-
def test_get_stats_invalid_duration_days(self, invalid_duration):
151+
def test_get_stats_invalid_last_n_days(self, invalid_duration):
152152
with pytest.raises(ValueError) as excinfo:
153-
dynamic_links.StatOptions(duration_days=invalid_duration)
154-
assert 'duration_days' in str(excinfo.value)
153+
dynamic_links.StatOptions(last_n_days=invalid_duration)
154+
assert 'last_n_days' in str(excinfo.value)
155155
assert 'must be positive int' in str(excinfo.value)
156156

157157

158158
class TestEventStats(object):
159159
@pytest.mark.parametrize('platform, event',
160-
itertools.product(dynamic_links._platforms.keys(),
161-
dynamic_links._event_types.keys()))
160+
itertools.product(dynamic_links._platforms.keys(),
161+
dynamic_links._event_types.keys()))
162162
def test_valid_platform_values(self, platform, event):
163163
event_stats = dynamic_links.EventStats(
164164
platform=platform,

0 commit comments

Comments
 (0)
0