-
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.
[CICO-6] added setup.py file, added __init__.py files, updated README…
…, updated .toml file, added some tests
- Loading branch information
Showing
8 changed files
with
253 additions
and
23 deletions.
There are no files selected for viewing
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,10 +1,28 @@ | ||
## Citesphere Connector | ||
# Citesphere Connector | ||
|
||
Python library to connect to Citephere using its [API](https://documenter.getpostman.com/view/19365454/UVeMJiyx). | ||
|
||
|
||
## SETUP | ||
## PyPi Package Installation | ||
|
||
`pip install citesphere-connector` | ||
|
||
|
||
## Developer Setup | ||
|
||
Create a python virtual environment outside of this project's root directory `python3 -m venv env` and activate it `source env/bin/activate` | ||
|
||
Navigate to the project root and download package dependencies `pip install -r requirements.txt` | ||
|
||
For retrieivng the Bearer access token required for endpoint method calls, please see the following OAuth2 [documentation] (https://diging.atlassian.net/wiki/spaces/OAC/pages/3533078792/Getting+OAuth2+Access+Token+in+Postman) for Citesphere | ||
|
||
|
||
## User Guide | ||
|
||
Retrieve Bearer access token required for endpoint method calls: [documentation] (https://diging.atlassian.net/wiki/spaces/OAC/pages/3533078792/Getting+OAuth2+Access+Token+in+Postman) | ||
|
||
### Downloading Files | ||
Use the 'Download' Jupyter notebook to download files from Citesphere to your local device. | ||
|
||
### Uploading Files | ||
Use the 'Upload' Jupyter notebook to upload files to Citesphere from your local device. |
Empty file.
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,7 @@ | ||
[build-system] | ||
requires = ["setuptools >= 61.0"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[project] | ||
name = "citesphere-connector" | ||
version = "1.0.0" | ||
|
@@ -15,25 +19,23 @@ dependencies = [ | |
] | ||
requires-python = ">= 3.9" | ||
authors = [ | ||
{name = "Digital Innovation Group", email = "[email protected]"}, | ||
{name = "Julia Damerow", email = "[email protected]"}, | ||
{name = "Julian Ophals", email = "[email protected]"}, | ||
{name = "Vishnu Vardhan Sanikommu", email = "[email protected]"}, | ||
{name = "Ajay Yadav", email = "[email protected]"}, | ||
] | ||
maintainers = [ | ||
{name = "Julia Damerow", email = "[email protected]"}, | ||
{name = "Julian Ophals", email = "[email protected]"}, | ||
] | ||
description = "Connect to Citesphere, an application that enables superior management of Zotero citations" | ||
readme = "README.md" | ||
license = {file = "LICENSE"} | ||
keywords = ["cite", "diging", "citesphere", "sphere", "zotero"] | ||
classifiers = [ | ||
"Development Status :: 4 - Beta", | ||
"Development Status :: 3 - Alpha", | ||
"Intended Audience :: Research Software Engineers, Researchers, Data Scientists, Developers", | ||
"Topic :: Reserach Software Engineering :: Citation Manager", | ||
"Programming Language :: Python", | ||
] | ||
|
||
[project.urls] | ||
"Citesphere API" = "https://documenter.getpostman.com/view/19365454/UVeMJiyx" | ||
"Citesphere" = "https://diging-dev.asu.edu/citesphere-review/" |
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,36 @@ | ||
"""A setuptools based setup module. | ||
See: | ||
https://packaging.python.org/guides/distributing-packages-using-setuptools/ | ||
https://github.com/pypa/sampleproject | ||
""" | ||
|
||
from setuptools import setup, find_packages | ||
import pathlib | ||
|
||
here = pathlib.Path(__file__).parent.resolve() | ||
|
||
long_description = (here / "README.md").read_text(encoding="utf-8") | ||
|
||
setup( | ||
name="citesphere-connector", | ||
version="1.0.0", | ||
description="Connect to Citesphere, an application that enables superior management of Zotero citations", | ||
url="https://github.com/diging/citesphere-connector", | ||
author="Digital Innovation Group", | ||
author_email="[email protected]", | ||
classifiers=[ | ||
"Development Status :: 3 - Alpha", | ||
"Intended Audience :: Research Software Engineers, Researchers, Data Scientists, Developers", | ||
"Topic :: Reserach Software Engineering :: Citation Manager", | ||
"Programming Language :: Python", | ||
], | ||
keywords="cite, diging, citesphere, sphere, zotero", | ||
package_dir={"": "src"}, | ||
packages=find_packages(where="src"), | ||
python_requires=">=3.9", | ||
project_urls={ | ||
"Citesphere API": "https://documenter.getpostman.com/view/19365454/UVeMJiyx", | ||
"Citesphere": "https://diging-dev.asu.edu/citesphere-review/", | ||
}, | ||
) |
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
Empty file.
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,5 +1,5 @@ | ||
import unittest | ||
from unittest.mock import Mock, patch | ||
from unittest.mock import patch, mock_open | ||
from src.CitesphereConnector import CitesphereConnector | ||
from src.authentication import AuthObject | ||
|
||
|
@@ -9,27 +9,200 @@ class EmptyObject: | |
|
||
|
||
class CitesphereConnectorTest(unittest.TestCase): | ||
def setUp(self): | ||
self.auth_object = AuthObject() | ||
self.auth_object.authType = "oauth" | ||
|
||
def tearDown(self): | ||
del self.auth_object | ||
|
||
def test_validate_method(self): | ||
auth_object = AuthObject() | ||
self.auth_object = AuthObject() | ||
with self.assertRaises(Exception): | ||
CitesphereConnector("example.com", auth_object) | ||
CitesphereConnector("example.com", self.auth_object) | ||
pass | ||
|
||
def test_validate_method_attribute_error(self): | ||
auth_object = EmptyObject() | ||
self.auth_object = EmptyObject() | ||
with self.assertRaises(AttributeError): | ||
CitesphereConnector("example.com", auth_object) | ||
pass | ||
|
||
@patch("CitesphereConnector.CitesphereConnector.get_groups") | ||
def test_api_called(self, mock_get_groups): | ||
auth_object = AuthObject() | ||
auth_object.authType = "oauth" | ||
mock_get_groups.return_value = Mock() | ||
mock_get_groups.return_value.json.return_value = [{"name": "vogon", "id": 1}] | ||
connector = CitesphereConnector("example.com", auth_object) | ||
print(connector.get_groups()) | ||
self.assertEqual(connector.get_groups()[0]["id"], 1) | ||
CitesphereConnector("example.com", self.auth_object) | ||
pass | ||
|
||
@patch("src.CitesphereConnector.CitesphereConnector.get_groups") | ||
def test_get_groups(self, mock_get_groups): | ||
mock_get_groups.return_value = [{"name": "vogon", "id": 1}] | ||
c = CitesphereConnector("test_get_groups.com", self.auth_object) | ||
result = c.get_groups() | ||
c.get_groups.assert_called_once() | ||
self.assertEqual(result[0]["id"], 1) | ||
self.assertEqual(result[0]["name"], "vogon") | ||
pass | ||
|
||
@patch("src.CitesphereConnector.CitesphereConnector.check_access") | ||
def test_check_access(self, mock_check_access): | ||
mock_check_access.return_value = "200 OK" | ||
c = CitesphereConnector("test_check_access.com", self.auth_object) | ||
result = c.check_access("example_doc_id") | ||
c.check_access.assert_called_once() | ||
self.assertEqual(result, "200 OK") | ||
pass | ||
|
||
@patch("src.CitesphereConnector.CitesphereConnector.get_user") | ||
def test_get_user(self, mock_get_user): | ||
mock_get_user.return_value = { | ||
"username": "test", | ||
"email": "[email protected]", | ||
"firstName": "get", | ||
"lastName": "user", | ||
} | ||
c = CitesphereConnector("test_get_user.com", self.auth_object) | ||
result = c.get_user() | ||
c.get_user.assert_called_once() | ||
self.assertEqual(result["username"], "test") | ||
self.assertEqual(result["email"], "[email protected]") | ||
self.assertEqual(result["firstName"], "get") | ||
self.assertEqual(result["lastName"], "user") | ||
pass | ||
|
||
@patch("src.CitesphereConnector.CitesphereConnector.get_group_info") | ||
def test_get_group_info(self, mock_get_group_info): | ||
mock_get_group_info.return_value = {"id": 1, "name": "test_get_group_info"} | ||
c = CitesphereConnector("test_get_group_info.com", self.auth_object) | ||
result = c.get_group_info(1) | ||
c.get_group_info.assert_called_once() | ||
self.assertEqual(result["id"], 1) | ||
self.assertEqual(result["name"], "test_get_group_info") | ||
pass | ||
|
||
@patch("src.CitesphereConnector.CitesphereConnector.get_group_items") | ||
def test_get_group_items(self, mock_get_group_items): | ||
mock_get_group_items.return_value = { | ||
"group": {"id": 1, "name": "test_get_group_items_group"}, | ||
"items": [ | ||
{"key": "TEST", "group": 1, "title": "test_get_group_items_item"} | ||
], | ||
} | ||
c = CitesphereConnector("test_get_group_items.com", self.auth_object) | ||
result = c.get_group_items(1) | ||
c.get_group_items.assert_called_once() | ||
self.assertEqual(result["group"]["id"], 1) | ||
self.assertEqual(result["group"]["name"], "test_get_group_items_group") | ||
self.assertEqual(result["items"][0]["key"], "TEST") | ||
self.assertEqual(result["items"][0]["group"], 1) | ||
self.assertEqual(result["items"][0]["title"], "test_get_group_items_item") | ||
pass | ||
|
||
@patch("src.CitesphereConnector.CitesphereConnector.get_collections") | ||
def test_get_collections(self, mock_get_collections): | ||
mock_get_collections.return_value = { | ||
"group": {"id": 1, "name": "test_get_collections_group"}, | ||
"collections": [ | ||
{ | ||
"id": {"timestamp": 1, "date": 1}, | ||
"key": "TEST", | ||
"groupId": 1, | ||
"name": "test_get_collections_collection", | ||
} | ||
], | ||
} | ||
c = CitesphereConnector("test_get_collections.com", self.auth_object) | ||
result = c.get_collections(1) | ||
c.get_collections.assert_called_once() | ||
self.assertEqual(result["group"]["id"], 1) | ||
self.assertEqual(result["group"]["name"], "test_get_collections_group") | ||
self.assertEqual(result["collections"][0]["id"]["timestamp"], 1) | ||
self.assertEqual(result["collections"][0]["key"], "TEST") | ||
self.assertEqual(result["collections"][0]["groupId"], 1) | ||
self.assertEqual( | ||
result["collections"][0]["name"], "test_get_collections_collection" | ||
) | ||
pass | ||
|
||
@patch("src.CitesphereConnector.CitesphereConnector.get_collection_items") | ||
def test_get_collection_items(self, mock_get_collection_items): | ||
mock_get_collection_items.return_value = { | ||
"group": {"id": 1, "name": "test_get_collection_items_group"}, | ||
"items": [ | ||
{"key": "TEST", "group": 1, "title": "test_get_collection_items_item"} | ||
], | ||
} | ||
c = CitesphereConnector("test_get_collection_items.com", self.auth_object) | ||
result = c.get_collection_items(1, 1) | ||
c.get_collection_items.assert_called_once() | ||
self.assertEqual(result["group"]["id"], 1) | ||
self.assertEqual(result["group"]["name"], "test_get_collection_items_group") | ||
self.assertEqual(result["items"][0]["key"], "TEST") | ||
self.assertEqual(result["items"][0]["group"], 1) | ||
self.assertEqual(result["items"][0]["title"], "test_get_collection_items_item") | ||
pass | ||
|
||
@patch("src.CitesphereConnector.CitesphereConnector.get_item_info") | ||
def test_get_item_info(self, mock_get_item_info): | ||
mock_get_item_info.return_value = { | ||
"item": {"key": "TEST", "group": "1", "title": "test_get_item_info_item"}, | ||
} | ||
c = CitesphereConnector("test_get_item_info.com", self.auth_object) | ||
result = c.get_item_info(1, 1) | ||
c.get_item_info.assert_called_once() | ||
self.assertEqual(result["item"]["key"], "TEST") | ||
self.assertEqual(result["item"]["group"], "1") | ||
self.assertEqual(result["item"]["title"], "test_get_item_info_item") | ||
pass | ||
|
||
@patch( | ||
"src.CitesphereConnector.CitesphereConnector.get_collections_by_collection_id" | ||
) | ||
def test_get_collections_by_collection_id( | ||
self, mock_get_collections_by_collection_id | ||
): | ||
mock_get_collections_by_collection_id.return_value = { | ||
"group": {"id": 1, "name": "test_get_collections_by_collection_id_group"}, | ||
"items": [ | ||
{ | ||
"key": "TEST", | ||
"group": 1, | ||
"title": "test_get_collections_by_collection_id_item", | ||
} | ||
], | ||
} | ||
c = CitesphereConnector( | ||
"test_get_collections_by_collection_id.com", self.auth_object | ||
) | ||
result = c.get_collections_by_collection_id(1, 1) | ||
c.get_collections_by_collection_id.assert_called_once() | ||
self.assertEqual(result["group"]["id"], 1) | ||
self.assertEqual( | ||
result["group"]["name"], "test_get_collections_by_collection_id_group" | ||
) | ||
self.assertEqual(result["items"][0]["key"], "TEST") | ||
self.assertEqual(result["items"][0]["group"], 1) | ||
self.assertEqual( | ||
result["items"][0]["title"], "test_get_collections_by_collection_id_item" | ||
) | ||
pass | ||
|
||
@patch("src.CitesphereConnector.CitesphereConnector.add_item") | ||
def test_add_item(self, mock_add_item): | ||
mock_add_item.return_value = { | ||
"key": "TEST", | ||
"group": "1", | ||
"title": "test_add_item", | ||
} | ||
c = CitesphereConnector("test_add_item.com", self.auth_object) | ||
result = c.add_item(1, {"data": "test"}, "path/to/file") | ||
c.add_item.assert_called_once() | ||
self.assertEqual(result["key"], "TEST") | ||
self.assertEqual(result["group"], "1") | ||
self.assertEqual(result["title"], "test_add_item") | ||
pass | ||
|
||
@patch("builtins.open", new_callable=mock_open) | ||
def test_add_item_exception(self, mock_open): | ||
mock_open.side_effect = Exception() | ||
c = CitesphereConnector("test_add_item_exception.com", self.auth_object) | ||
result = c.add_item(1, {"data": "test"}, "path/to/file") | ||
mock_open.assert_called_once_with("path/to/file", "rb") | ||
self.assertEqual(result, "Error loading/reading file") | ||
pass | ||
|
||
|
||
|
Empty file.