Skip to content

Commit

Permalink
Prefactor: Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kaapstorm committed Feb 27, 2024
1 parent 2691df2 commit f25042c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 3 additions & 1 deletion hq_superset/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ def get_valid_cchq_oauth_token():

# If token hasn't expired yet, return it
expires_at = oauth_response.get("expires_at")
if expires_at > int(time.time()):
# TODO: RFC-6749 specifies "expires_in", not "expires_at".
# https://www.rfc-editor.org/rfc/rfc6749#section-5.1
if expires_at is None or expires_at > int(time.time()):
return oauth_response

# If the token has expired, get a new token using refresh_token
Expand Down
9 changes: 4 additions & 5 deletions hq_superset/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def test_non_user_domain_cant_be_selected(self):
self.assertTrue('/domain/list' in response.request.path)
self.logout(client)

@patch('hq_superset.views.get_valid_cchq_oauth_token', return_value={})
@patch('hq_superset.oauth.get_valid_cchq_oauth_token', return_value={})
def test_datasource_list(self, *args):
def _do_assert(datasources):
self.assert_template_used("hq_datasource_list.html")
Expand Down Expand Up @@ -230,14 +230,13 @@ def test_datasource_upload(self, *args):
'ds1'
)

@patch('hq_superset.views.get_valid_cchq_oauth_token', return_value={})
@patch('hq_superset.oauth.get_valid_cchq_oauth_token', return_value={})
@patch('hq_superset.views.os.remove')
def test_trigger_datasource_refresh(self, *args):
from hq_superset.views import (
ASYNC_DATASOURCE_IMPORT_LIMIT_IN_BYTES,
trigger_datasource_refresh,
)

domain = 'test1'
ds_name = 'ds_name'
file_path = '/file_path'
Expand Down Expand Up @@ -277,7 +276,7 @@ def _test_sync_or_async(ds_size, routing_method, user_id):
None
)

@patch('hq_superset.views.get_valid_cchq_oauth_token', return_value={})
@patch('hq_superset.oauth.get_valid_cchq_oauth_token', return_value={})
def test_download_datasource(self, *args):
from ..services import download_datasource
ucr_id = self.oauth_mock.test1_datasources['objects'][0]['id']
Expand All @@ -287,7 +286,7 @@ def test_download_datasource(self, *args):
self.assertEqual(size, len(pickle.dumps(TEST_UCR_CSV_V1)))
os.remove(path)

@patch('hq_superset.views.get_valid_cchq_oauth_token', return_value={})
@patch('hq_superset.oauth.get_valid_cchq_oauth_token', return_value={})
def test_refresh_hq_datasource(self, *args):

client = self.app.test_client()
Expand Down

0 comments on commit f25042c

Please sign in to comment.