From 7fffa7b5fbb2117ae3ed4857bc8fc1889af238f6 Mon Sep 17 00:00:00 2001 From: Ed Summers Date: Wed, 19 Jun 2024 17:23:19 -0400 Subject: [PATCH] Getting Dimensions tests to work --- .github/workflows/test.yml | 3 +++ rialto_airflow/harvest/dimensions.py | 7 ++++--- test/data/authors.csv | 11 +++++++++++ test/harvest/test_dimensions.py | 15 ++++++++------- 4 files changed, 26 insertions(+), 10 deletions(-) create mode 100644 test/data/authors.csv diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fde7a0c..bcce0cb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,3 +30,6 @@ jobs: - name: Run tests run: pytest + env: + AIRFLOW_VAR_DIMENSIONS_API_USER: ${{ secrets.AIRFLOW_VAR_DIMENSIONS_API_USER }} + AIRFLOW_VAR_DIMENSIONS_API_PASS: ${{ secrets.AIRFLOW_VAR_DIMENSIONS_API_PASS }} diff --git a/rialto_airflow/harvest/dimensions.py b/rialto_airflow/harvest/dimensions.py index 01633a9..926091e 100644 --- a/rialto_airflow/harvest/dimensions.py +++ b/rialto_airflow/harvest/dimensions.py @@ -11,8 +11,8 @@ dotenv.load_dotenv() dimcli.login( - os.environ.get("DIMENSIONS_API_USER"), - os.environ.get("DIMENSIONS_API_PASS"), + os.environ.get("AIRFLOW_VAR_DIMENSIONS_API_USER"), + os.environ.get("AIRFLOW_VAR_DIMENSIONS_API_PASS"), "https://app.dimensions.ai", ) @@ -65,7 +65,8 @@ def dimensions_doi_orcids_dict(org_data_file, pickle_file, limit=None): orcids = df[df["orcidid"].notna()]["orcidid"] orcid_dois = {} - for orcid in orcids[:limit]: + for orcid_url in orcids[:limit]: + orcid = orcid_url.replace("https://orcid.org/", "") dois = list(dimensions_dois_from_orcid(orcid)) orcid_dois.update({orcid: dois}) diff --git a/test/data/authors.csv b/test/data/authors.csv new file mode 100644 index 0000000..c669076 --- /dev/null +++ b/test/data/authors.csv @@ -0,0 +1,11 @@ +sunetid,orcidid +sunet1,https://orcid.org/0000-0001-8705-1000 +sunet2,https://orcid.org/0000-0003-2150-5828 +sunet3,https://orcid.org/0000-0003-2150-5828 +sunet4,https://orcid.org/0000-0002-0770-2940 +sunet5,https://orcid.org/0000-0002-5270-1197 +sunet6,https://orcid.org/0000-0002-7636-9758 +sunet7,https://orcid.org/0000-0003-4670-0347 +sunet8,https://orcid.org/0000-0002-5969-1251 +sunet9,https://orcid.org/0000-0002-0426-2134 +sunet10,https://orcid.org/0000-0002-0455-2086 diff --git a/test/harvest/test_dimensions.py b/test/harvest/test_dimensions.py index e28caf9..fe79300 100644 --- a/test/harvest/test_dimensions.py +++ b/test/harvest/test_dimensions.py @@ -7,8 +7,8 @@ dotenv.load_dotenv() -dimensions_user = os.environ.get("DIMENSIONS_API_USER") -dimensions_password = os.environ.get("DIMENSIONS_API_PASS") +dimensions_user = os.environ.get("AIRFLOW_VAR_DIMENSIONS_API_USER") +dimensions_password = os.environ.get("AIRFLOW_VAR_DIMENSIONS_API_PASS") no_auth = not (dimensions_user and dimensions_password) @@ -16,15 +16,16 @@ @pytest.mark.skipif(no_auth, reason="no dimensions key") def test_dimensions_doi_orcids_dict(tmpdir): pickle_file = tmpdir / "dimensions.pickle" - dimensions_doi_orcids_dict( - "data/rialto_app/authors_2024-03-18.csv", pickle_file, limit=5 - ) + dimensions_doi_orcids_dict("test/data/authors.csv", pickle_file, limit=5) assert pickle_file.isfile() with open(pickle_file, "rb") as handle: - doi_orcids_dict = pickle.load(handle) + doi_orcids = pickle.load(handle) - assert len(doi_orcids_dict.keys()) == len(set(doi_orcids_dict.keys())) + assert len(doi_orcids) > 0 + assert doi_orcids["https://doi.org/10.1109/lra.2018.2890209"] == [ + "0000-0002-0770-2940" + ] def test_invert_dict():