-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* developed unit testing * fixed asynchronous errors * test action script * fix * test * fix * test * took out redundant workflow * took out debug * secret test * attempted fix * test * unmocking * fix
- Loading branch information
Showing
8 changed files
with
134 additions
and
81 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
name: "Test" | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Run Pytest | ||
env: | ||
CI_ZENODO_API_KEY: ${{ secrets.CI_ZENODO_API_KEY }} | ||
run: pytest zenodo_jupyterlab/server/tests | ||
shell: bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
jupyterlab>4,<5 | ||
notebook<7 | ||
eossr | ||
eossr | ||
pytest | ||
pytest-asyncio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
from unittest.mock import Mock, patch, AsyncMock | ||
from eossr.api.zenodo import search_records, search_communities, get_record | ||
import pytest | ||
from zenodo_jupyterlab.server.search import searchRecords, searchCommunities, recordInformation # Replace `your_module` with the actual module name | ||
|
||
@pytest.mark.asyncio | ||
@patch('zenodo_jupyterlab.server.search.search_records') | ||
async def test_searchRecords_success(mock_search_records): | ||
mock_search_records.return_value = [ | ||
Mock(id='1', title='Record One', metadata={'publication_date': '2022-01-01', 'resource_type': {'title': 'Dataset'}}), | ||
Mock(id='2', title='Record Two', metadata={'publication_date': '2023-01-01', 'resource_type': {'title': 'Article'}}) | ||
] | ||
|
||
response = await searchRecords('', 1) | ||
expected_response = [ | ||
{'id': '1', 'title': 'Record One', 'date': '2022-01-01', 'resource_type': 'Dataset'}, | ||
{'id': '2', 'title': 'Record Two', 'date': '2023-01-01', 'resource_type': 'Article'} | ||
] | ||
|
||
assert response == expected_response | ||
|
||
@pytest.mark.asyncio | ||
@patch('zenodo_jupyterlab.server.search.search_records') | ||
async def test_searchRecords_failure(mock_search_records): | ||
mock_search_records.side_effect = Exception('API Error') | ||
|
||
response = await searchRecords('test', 1) | ||
assert response == ["failed"] | ||
|
||
@pytest.mark.asyncio | ||
@patch('zenodo_jupyterlab.server.search.search_communities') | ||
async def test_searchCommunities_success(mock_search_communities): | ||
mock_search_communities.return_value = [ | ||
{'id': '1', 'metadata': {'title': 'Community One'}, 'created': '2022-01-01T00:00:00Z'}, | ||
{'id': '2', 'metadata': {'title': 'Community Two'}, 'created': '2023-01-01T00:00:00Z'} | ||
] | ||
|
||
response = await searchCommunities('test', 1) | ||
expected_response = [ | ||
{'id': '1', 'title': 'Community One', 'date': '2022-01-01'}, | ||
{'id': '2', 'title': 'Community Two', 'date': '2023-01-01'} | ||
] | ||
assert response == expected_response | ||
|
||
@pytest.mark.asyncio | ||
@patch('zenodo_jupyterlab.server.search.search_communities') | ||
async def test_searchCommunities_failure(mock_search_communities): | ||
mock_search_communities.side_effect = Exception('API Error') | ||
|
||
response = await searchCommunities('test', 1) | ||
assert response == ["failed"] | ||
|
||
@pytest.mark.asyncio | ||
@patch('zenodo_jupyterlab.server.search.get_record') | ||
async def test_recordInformation_success(mock_get_record): | ||
mock_get_record.return_value = AsyncMock( | ||
metadata={'creators': [{'name': 'Author One'}, {'name': 'Author Two'}]}, | ||
filelist=['file1.pdf', 'file2.pdf'] | ||
) | ||
|
||
response = await recordInformation('12345') | ||
expected_response = { | ||
'authors': [{'name': 'Author One'}, {'name': 'Author Two'}], | ||
'filelist': ['file1.pdf', 'file2.pdf'] | ||
} | ||
assert response == expected_response | ||
|
||
@pytest.mark.asyncio | ||
@patch('zenodo_jupyterlab.server.search.get_record') | ||
async def test_recordInformation_failure(mock_get_record): | ||
mock_get_record.side_effect = Exception('API Error') | ||
|
||
response = await recordInformation('12345') | ||
assert response == {'status': 'failed'} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import pytest | ||
from unittest.mock import patch, Mock | ||
from eossr.api.zenodo import ZenodoAPI | ||
import os | ||
from zenodo_jupyterlab.server.testConnection import checkZenodoConnection | ||
|
||
@pytest.mark.asyncio | ||
async def test_zenodo_connection_success(): | ||
# Mock the ZenodoAPI instance and its method | ||
""" mock_instance = MockZenodoAPI.return_value | ||
mock_instance.query_user_deposits = Mock() | ||
mock_instance.query_user_deposits.return_value.status_code = 200 """ | ||
|
||
# Mock the environment variable | ||
with patch.dict(os.environ, {'ZENODO_API_KEY': os.environ['CI_ZENODO_API_KEY']}): | ||
# Call the function to test | ||
status_code = await checkZenodoConnection(sandbox = True) | ||
|
||
print(f"Returned status code: {status_code}") | ||
|
||
# Assert the expected status code | ||
assert status_code == 200 | ||
|
||
@pytest.mark.asyncio | ||
async def test_zenodo_connection_failure(): | ||
# Mock the ZenodoAPI instance to raise an exception | ||
""" mock_instance = MockZenodoAPI.return_value | ||
mock_instance.query_user_deposits = Mock() | ||
mock_instance.query_user_deposits.side_effect = Exception('Failed') """ | ||
|
||
# Mock the environment variable | ||
with patch.dict('os.environ', {'ZENODO_API_KEY': 'fake_false_api_key'}): | ||
# Call the function to test | ||
status_code = await checkZenodoConnection(sandbox = True) | ||
|
||
# Assert the expected status code | ||
assert status_code == 0 |