From f166bf3bf4b145b4bfc616fca229f6c780cba3c8 Mon Sep 17 00:00:00 2001 From: Miguel Ballesteros Date: Tue, 10 Sep 2024 15:07:13 -0500 Subject: [PATCH] Added test skips to avoid throttling --- test/auth/test_oauthuser.py | 3 +++ test/auth/test_userkey.py | 7 +++++++ test/snapshots/test_explain.py | 12 ++++++++++++ test/snapshots/test_extraction.py | 12 ++++++++++++ test/snapshots/test_timeseries.py | 14 +++++++++++++- test/taxonomy/test_factivataxonomy.py | 8 ++++++++ 6 files changed, 55 insertions(+), 1 deletion(-) diff --git a/test/auth/test_oauthuser.py b/test/auth/test_oauthuser.py index 60ee944..fdbab18 100755 --- a/test/auth/test_oauthuser.py +++ b/test/auth/test_oauthuser.py @@ -5,6 +5,7 @@ from factiva.analytics import OAuthUser from factiva.analytics.common import config +GITHUB_CI = config.load_environment_value('CI', False) FACTIVA_CLIENTID = config.load_environment_value("FACTIVA_CLIENTID") FACTIVA_USERNAME = config.load_environment_value("FACTIVA_USERNAME") FACTIVA_PASSWORD = config.load_environment_value("FACTIVA_PASSWORD") @@ -50,6 +51,8 @@ def test_wrong_credentials(): Creates an object from the provided string The key is invalid and this should validate how the error is processed """ + if GITHUB_CI: + pytest.skip("Not to be tested in GitHub Actions") with pytest.raises(PermissionError, match=r'Invalid user credentials'): o = OAuthUser(client_id='client_id_value', username='username_value', diff --git a/test/auth/test_userkey.py b/test/auth/test_userkey.py index 6504f6c..b7db60b 100755 --- a/test/auth/test_userkey.py +++ b/test/auth/test_userkey.py @@ -5,6 +5,7 @@ from factiva.analytics import UserKey from factiva.analytics.common import config +GITHUB_CI = config.load_environment_value('CI', False) FACTIVA_USERKEY = config.load_environment_value("FACTIVA_USERKEY") DUMMY_KEY = 'abcd1234abcd1234abcd1234abcd1234' @@ -13,6 +14,8 @@ def test_userkey_from_env(): """ Creates an empty object from the ENV variable with a value only for the key property """ + if GITHUB_CI: + pytest.skip("Not to be tested in GitHub Actions") usr = UserKey() assert usr.key == FACTIVA_USERKEY assert isinstance(usr.cloud_token, dict) @@ -22,6 +25,8 @@ def test_user_with_parameter_and_stats(): """ API Key is passed as a string and stats=True """ + if GITHUB_CI: + pytest.skip("Not to be tested in GitHub Actions") usr = UserKey(FACTIVA_USERKEY) assert usr.key == FACTIVA_USERKEY assert isinstance(usr.cloud_token, dict) @@ -32,6 +37,8 @@ def test_invalid_key(): Creates an object from the provided string and request the usage details to the API service The key is invalid and this should validate how the error is processed """ + if GITHUB_CI: + pytest.skip("Not to be tested in GitHub Actions") with pytest.raises(ValueError, match=r'Factiva User-Key does not exist or inactive.'): UserKey(DUMMY_KEY) diff --git a/test/snapshots/test_explain.py b/test/snapshots/test_explain.py index 8c6ee74..614dbf4 100644 --- a/test/snapshots/test_explain.py +++ b/test/snapshots/test_explain.py @@ -13,6 +13,8 @@ # Test operations before any API request def test_create_from_envuser(): + if GITHUB_CI: + pytest.skip("Not to be tested in GitHub Actions") se = SnapshotExplain() assert isinstance(se, SnapshotExplain) assert se.user_key.key == ENVIRONMENT_USER_KEY @@ -23,6 +25,8 @@ def test_create_from_envuser(): } def test_create_from_user_param(): + if GITHUB_CI: + pytest.skip("Not to be tested in GitHub Actions") se = SnapshotExplain(user_key=VALID_USER_KEY) assert isinstance(se, SnapshotExplain) assert se.user_key.key == VALID_USER_KEY @@ -33,6 +37,8 @@ def test_create_from_user_param(): } def test_create_from_userkey(): + if GITHUB_CI: + pytest.skip("Not to be tested in GitHub Actions") u = UserKey() assert isinstance(u, UserKey) se = SnapshotExplain(user_key=u) @@ -45,6 +51,8 @@ def test_create_from_userkey(): } def test_create_envuser_where(): + if GITHUB_CI: + pytest.skip("Not to be tested in GitHub Actions") se = SnapshotExplain(query=VALID_WHERE_STATEMENT) assert isinstance(se, SnapshotExplain) assert se.user_key.key == ENVIRONMENT_USER_KEY @@ -55,6 +63,8 @@ def test_create_envuser_where(): } def test_create_envuser_envwhere(): + if GITHUB_CI: + pytest.skip("Not to be tested in GitHub Actions") seq = SnapshotExplainQuery() assert isinstance(seq, SnapshotExplainQuery) se = SnapshotExplain(query=seq) @@ -67,6 +77,8 @@ def test_create_envuser_envwhere(): } def test_failed_where_and_jobid(): + if GITHUB_CI: + pytest.skip("Not to be tested in GitHub Actions") with pytest.raises(ValueError, match=r'The query and job_id parameters*'): se = SnapshotExplain(query=VALID_WHERE_STATEMENT, job_id='abcd1234-ab12-ab12-ab12-abcdef123456') assert isinstance(se, SnapshotExplain) diff --git a/test/snapshots/test_extraction.py b/test/snapshots/test_extraction.py index 361de87..91939ee 100644 --- a/test/snapshots/test_extraction.py +++ b/test/snapshots/test_extraction.py @@ -12,6 +12,8 @@ # Test operations before any API request def test_create_from_envuser(): + if GITHUB_CI: + pytest.skip("Not to be tested in GitHub Actions") se = SnapshotExtraction() assert isinstance(se, SnapshotExtraction) assert se.user_key.key == ENVIRONMENT_USER_KEY @@ -23,6 +25,8 @@ def test_create_from_envuser(): } def test_create_from_user_param(): + if GITHUB_CI: + pytest.skip("Not to be tested in GitHub Actions") se = SnapshotExtraction(user_key=VALID_USER_KEY) assert isinstance(se, SnapshotExtraction) assert se.user_key.key == VALID_USER_KEY @@ -34,6 +38,8 @@ def test_create_from_user_param(): } def test_create_from_userkey(): + if GITHUB_CI: + pytest.skip("Not to be tested in GitHub Actions") u = UserKey() assert isinstance(u, UserKey) se = SnapshotExtraction(user_key=u) @@ -47,6 +53,8 @@ def test_create_from_userkey(): } def test_create_envuser_where(): + if GITHUB_CI: + pytest.skip("Not to be tested in GitHub Actions") se = SnapshotExtraction(query=VALID_WHERE_STATEMENT) assert isinstance(se, SnapshotExtraction) assert se.user_key.key == ENVIRONMENT_USER_KEY @@ -58,6 +66,8 @@ def test_create_envuser_where(): } def test_create_envuser_envwhere(): + if GITHUB_CI: + pytest.skip("Not to be tested in GitHub Actions") seq = SnapshotExtractionQuery() assert isinstance(seq, SnapshotExtractionQuery) se = SnapshotExtraction(query=seq) @@ -71,6 +81,8 @@ def test_create_envuser_envwhere(): } def test_failed_where_and_jobid(): + if GITHUB_CI: + pytest.skip("Not to be tested in GitHub Actions") with pytest.raises(ValueError, match=r'The query and job_id parameters*'): se = SnapshotExtraction(query=VALID_WHERE_STATEMENT, job_id='abcd1234-ab12-ab12-ab12-abcdef123456') assert isinstance(se, SnapshotExtraction) diff --git a/test/snapshots/test_timeseries.py b/test/snapshots/test_timeseries.py index d24cc27..66e9c23 100644 --- a/test/snapshots/test_timeseries.py +++ b/test/snapshots/test_timeseries.py @@ -12,6 +12,8 @@ def test_create_from_envuser(): + if GITHUB_CI: + pytest.skip("Not to be tested in GitHub Actions") sts = SnapshotTimeSeries() assert isinstance(sts, SnapshotTimeSeries) assert sts.user_key.key == ENVIRONMENT_USER_KEY @@ -26,6 +28,8 @@ def test_create_from_envuser(): } def test_create_from_user_param(): + if GITHUB_CI: + pytest.skip("Not to be tested in GitHub Actions") sts = SnapshotTimeSeries(user_key=VALID_USER_KEY) assert isinstance(sts, SnapshotTimeSeries) assert sts.user_key.key == VALID_USER_KEY @@ -40,6 +44,8 @@ def test_create_from_user_param(): } def test_create_from_userkey(): + if GITHUB_CI: + pytest.skip("Not to be tested in GitHub Actions") u = UserKey() assert isinstance(u, UserKey) sts = SnapshotTimeSeries(user_key=u) @@ -56,6 +62,8 @@ def test_create_from_userkey(): } def test_create_envuser_where(): + if GITHUB_CI: + pytest.skip("Not to be tested in GitHub Actions") sts = SnapshotTimeSeries(query=VALID_WHERE_STATEMENT) assert isinstance(sts, SnapshotTimeSeries) assert sts.user_key.key == ENVIRONMENT_USER_KEY @@ -70,6 +78,8 @@ def test_create_envuser_where(): } def test_create_envuser_envwhere(): + if GITHUB_CI: + pytest.skip("Not to be tested in GitHub Actions") seq = SnapshotTimeSeriesQuery() assert isinstance(seq, SnapshotTimeSeriesQuery) sts = SnapshotTimeSeries(query=seq) @@ -86,6 +96,8 @@ def test_create_envuser_envwhere(): } def test_failed_where_and_jobid(): + if GITHUB_CI: + pytest.skip("Not to be tested in GitHub Actions") with pytest.raises(ValueError, match=r'The query and job_id parameters*'): sts = SnapshotTimeSeries(query=VALID_WHERE_STATEMENT, job_id='abcd1234-ab12-ab12-ab12-abcdef123456') assert isinstance(sts, SnapshotTimeSeries) @@ -93,7 +105,7 @@ def test_failed_where_and_jobid(): # Test operations sending requests to the API # These are only executed when running locally. For optimisation purposes -# no API tests are executed in the CI/CD (GitHub Actions) environment. +# no heavy API tests are executed in the CI/CD (GitHub Actions) environment. def test_job_envuser_envwhere(): if GITHUB_CI: diff --git a/test/taxonomy/test_factivataxonomy.py b/test/taxonomy/test_factivataxonomy.py index 48fb2c6..afe4475 100644 --- a/test/taxonomy/test_factivataxonomy.py +++ b/test/taxonomy/test_factivataxonomy.py @@ -1,8 +1,10 @@ import os +import pytest import pandas as pd from factiva.analytics import FactivaTaxonomy, FactivaTaxonomyCategories, UserKey from factiva.analytics.common import config +GITHUB_CI = config.load_environment_value('CI', False) FACTIVA_USERKEY = config.load_environment_value("FACTIVA_USERKEY") SAVE_PATH = os.getcwd() @@ -23,6 +25,8 @@ def test_create_taxonomy_instance_userkey_user(): def test_download_category_file(): + if GITHUB_CI: + pytest.skip("Not to be tested in GitHub Actions") t = FactivaTaxonomy() assert t.download_raw_category(FactivaTaxonomyCategories.INDUSTRIES, path=SAVE_PATH) assert t.download_raw_category(FactivaTaxonomyCategories.INDUSTRIES, path=SAVE_PATH, file_format='avro') @@ -34,6 +38,8 @@ def test_download_category_file(): def test_get_category_codes(): + if GITHUB_CI: + pytest.skip("Not to be tested in GitHub Actions") t = FactivaTaxonomy() industries = t.get_category_codes(FactivaTaxonomyCategories.INDUSTRIES) assert isinstance(industries, pd.DataFrame) @@ -43,6 +49,8 @@ def test_get_category_codes(): def test_lookup_code_good(): + if GITHUB_CI: + pytest.skip("Not to be tested in GitHub Actions") t = FactivaTaxonomy() assert t.all_subjects == None mcat = t.lookup_code('MCAT', FactivaTaxonomyCategories.SUBJECTS)