-
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.
Merge pull request #6 from asfadmin/dms/feat/add-testing
Add Unit tests
- Loading branch information
Showing
6 changed files
with
142 additions
and
2 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 |
---|---|---|
|
@@ -3,4 +3,4 @@ max-line-length = 120 | |
extend-ignore = W503 | ||
inline-quotes = double | ||
|
||
exclude = .venv | ||
exclude = .venv, .tox |
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,19 @@ | ||
name: Test | ||
|
||
on: | ||
pull_request: | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.10" | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
python -m pip install "tox~=4.4" | ||
- run: tox |
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,2 @@ | ||
[pytest] | ||
pythonpath = src |
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,6 +1,6 @@ | ||
cumulus-message-adapter==2.0.3 | ||
cumulus-message-adapter-python==2.2.0 | ||
jsonpath-ng==1.4.2 | ||
jsonschema==2.6.0 | ||
jsonschema==4.17.3 | ||
mandible @ git+https://github.com/asfadmin/mandible@v0.4.0 | ||
ply==3.11 |
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,108 @@ | ||
import boto3 | ||
import pytest | ||
|
||
from granule_to_sns import generate_message, granule_to_sns | ||
|
||
|
||
@pytest.fixture | ||
def event(): | ||
return { | ||
"input": { | ||
"granules": [ | ||
{ | ||
"granuleId": "foo", | ||
"dataType": "bar", | ||
"version": "1.0", | ||
"provider": "ASFDAAC", | ||
"files": [ | ||
{ | ||
"size": 162946863, | ||
"bucket": "data-bucket", | ||
"key": "foo.h5", | ||
"source": "foo.h5", | ||
"fileName": "foo.h5", "type": "data", | ||
"checksumType": "md5", "checksum": "a88dda7180fc2738fe42af65721577d6", | ||
}, | ||
{ | ||
"size": 32, | ||
"bucket": "data-bucket", | ||
"key": "foo.h5.md5", | ||
"source": "foo.h5.md5", | ||
"fileName": "foo.h5.md5", | ||
"type": "metadata", "checksumType": "md5", "checksum": "228d1f939face34465b26fbf4056898f", | ||
}, | ||
{ | ||
"size": 200178, | ||
"bucket": "data-bucket", | ||
"key": "foo.iso.xml", | ||
"source": "foo.iso.xml", | ||
"fileName": "foo.iso.xml", | ||
"type": "metadata", "checksumType": "md5", "checksum": "b8d18182e9ec0c781430babcdeafaea9", | ||
}, | ||
{ | ||
"size": 32, | ||
"bucket": "data-bucket", | ||
"key": "foo.iso.xml.md5", | ||
"source": "foo.iso.xml.md5", | ||
"fileName": "foo.iso.xml.md5", | ||
"type": "metadata", "checksumType": "md5", "checksum": "aef479deb833175bbfcfb048a0f4d06e", | ||
}, | ||
{ | ||
"bucket": "data-bucket", | ||
"key": "UMMG/foo.cmr.json", | ||
"fileName": "foo.cmr.json", | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
} | ||
|
||
|
||
@pytest.fixture | ||
def message(): | ||
return { | ||
"identifier": "foo", | ||
"collection": "bar", | ||
"product": { | ||
"name": "foo", | ||
"files": [ | ||
{ | ||
"name": "foo.h5", | ||
"uri": "s3://data-bucket/foo.h5", | ||
}, | ||
{ | ||
"name": "foo.h5.md5", | ||
"uri": "s3://data-bucket/foo.h5.md5", | ||
}, | ||
{ | ||
"name": "foo.iso.xml", | ||
"uri": "s3://data-bucket/foo.iso.xml", | ||
}, | ||
{ | ||
"name": "foo.iso.xml.md5", | ||
"uri": "s3://data-bucket/foo.iso.xml.md5", | ||
}, | ||
{ | ||
"name": "foo.cmr.json", | ||
"uri": "s3://data-bucket/UMMG/foo.cmr.json", | ||
}, | ||
], | ||
}, | ||
} | ||
|
||
|
||
@pytest.fixture | ||
def sns_client(mocker): | ||
sns_client = boto3.client("sns", region_name="us-west-2") | ||
mocker.patch("boto3.client", return_value=sns_client) | ||
return sns_client | ||
|
||
|
||
def test_generate_message(event, message): | ||
assert generate_message(event["input"]["granules"][0]) == message | ||
|
||
|
||
def test_granule_to_sns(sns_client, event, mocker): | ||
mocker.patch.object(sns_client, "publish", return_value={}) | ||
assert granule_to_sns(event, None) == event |
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,11 @@ | ||
[tox] | ||
env_list = py310 | ||
minversion = 4.4.6 | ||
|
||
[testenv] | ||
deps = | ||
pytest>=7 | ||
pytest-mock>=3.14.0 | ||
-r src/requirements.txt | ||
commands = | ||
pytest {tty:--color=yes} {posargs} |