Skip to content

Commit

Permalink
Merge pull request #33 from MITLibraries/GH-ISS-32-dspace-connection-…
Browse files Browse the repository at this point in the history
…test-command

Gh iss 32 dspace connection test command
  • Loading branch information
ehanson8 committed Sep 8, 2023
2 parents b45930d + fb0700b commit 7c461a8
Show file tree
Hide file tree
Showing 7 changed files with 693 additions and 576 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,4 @@ dmypy.json

.DS_Store
cov_html

.vscode/
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,21 @@ publish-stage: ## Only use in an emergency
run-dev: ## Runs the task in dev - see readme for more info
aws ecs run-task --cluster DSS-SubmissionService-dev --task-definition DSS-SubmissionService-dev-task --network-configuration "awsvpcConfiguration={subnets=[subnet-0488e4996ddc8365b,subnet-022e9ea19f5f93e65],securityGroups=[sg-044033bf5f102c544],assignPublicIp=DISABLED}" --launch-type FARGATE --region us-east-1

verify-dspace-connection-dev: # Verify dev app can connect to DSpace
aws ecs run-task --cluster DSS-SubmissionService-dev --task-definition DSS-SubmissionService-dev-task --network-configuration "awsvpcConfiguration={subnets=[subnet-0488e4996ddc8365b,subnet-022e9ea19f5f93e65],securityGroups=[sg-044033bf5f102c544],assignPublicIp=DISABLED}" --launch-type FARGATE --region us-east-1 --overrides '{"containerOverrides": [ {"name": "DSS", "command": ["verify-dspace-connection"]}]}'

run-stage: ## Runs the task in stage - see readme for more info
aws ecs run-task --cluster DSS-SubmissionService-stage --task-definition DSS-SubmissionService-stage-task --network-configuration "awsvpcConfiguration={subnets=[subnet-05df31ac28dd1a4b0,subnet-04cfa272d4f41dc8a],securityGroups=[sg-0f64d9a1101d544d1],assignPublicIp=DISABLED}" --launch-type FARGATE --region us-east-1

verify-dspace-connection-stage: # Verify stage app can connect to DSpace
aws ecs run-task --cluster DSS-SubmissionService-stage --task-definition DSS-SubmissionService-stage-task --network-configuration "awsvpcConfiguration={subnets=[subnet-05df31ac28dd1a4b0,subnet-04cfa272d4f41dc8a],securityGroups=[sg-0f64d9a1101d544d1],assignPublicIp=DISABLED}" --launch-type FARGATE --region us-east-1 --overrides '{"containerOverrides": [ {"name": "DSS", "command": ["verify-dspace-connection"]}]}'

# run-prod: ## Runs the task in stage - see readme for more info
# Not yet deployed in production

# verify-dspace-connection-prod: # Verify prod app can connect to DSpace
# Not yet deployed in production

### Dependency commands ###
install: ## Install script and dependencies
pipenv install --dev
Expand Down
1,197 changes: 622 additions & 575 deletions Pipfile.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ integration testing with DSpace test, add an additional option to the command:
Warning: please do not run this against the production system or a bunch of junk records
will load into dspace

## Verifying DSpace connection
To verify that DSS can connect to the DSpace REST API, run `make verify-dspace-connection` and view the logs to see if the connection was successful or failed.

## Processing

`pipenv run submitter start` will loop through all of the data in the SQS input queue, process the queue,
Expand Down
21 changes: 21 additions & 0 deletions submitter/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import logging

import click
from dspace.client import DSpaceClient
from requests.exceptions import HTTPError

from submitter import CONFIG
from submitter.message import (
Expand Down Expand Up @@ -87,3 +89,22 @@ def create_queue(name):
"""Create queue with NAME supplied as argument"""
queue = create(name)
logger.info(queue.url)


@main.command()
def verify_dspace_connection():
client = DSpaceClient(CONFIG.DSPACE_API_URL, timeout=CONFIG.DSPACE_TIMEOUT)
try:
client.login(CONFIG.DSPACE_USER, CONFIG.DSPACE_PASSWORD)
except HTTPError:
logger.exception(
"Failed to authenticate to %s as %s",
CONFIG.DSPACE_API_URL,
CONFIG.DSPACE_USER,
)
else:
logger.info(
"Successfully authenticated to %s as %s",
CONFIG.DSPACE_API_URL,
CONFIG.DSPACE_USER,
)
7 changes: 7 additions & 0 deletions conftest.py → tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ def mocked_dspace():
yield m


@pytest.fixture(scope="function")
def mocked_dspace_auth_failure():
with requests_mock.Mocker() as m:
m.post("mock://dspace.edu/rest/login", status_code=401)
yield m


@pytest.fixture(scope="function")
def mocked_sqs(aws_credentials):
with mock_sqs():
Expand Down
30 changes: 30 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging

from click.testing import CliRunner

from submitter.cli import main
Expand Down Expand Up @@ -71,3 +73,31 @@ def test_cli_start(mocked_dspace, mocked_sqs):
assert len(sqs_messages) == 0
out_messages = result_queue.receive_messages()
assert len(out_messages) > 0


def test_verify_dspace_connection_success(mocked_dspace, caplog):
with caplog.at_level(logging.INFO):
runner = CliRunner()
result = runner.invoke(
main,
[
"verify-dspace-connection",
],
)
assert result.exit_code == 0
assert (
"Successfully authenticated to mock://dspace.edu/rest/ as test"
in caplog.text
)


def test_verify_dspace_connection_failed(mocked_dspace_auth_failure, caplog):
runner = CliRunner()
result = runner.invoke(
main,
[
"verify-dspace-connection",
],
)
assert result.exit_code == 0
assert "Failed to authenticate to mock://dspace.edu/rest/ as test" in caplog.text

0 comments on commit 7c461a8

Please sign in to comment.