Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add MWE unit/integ tests and gh actions #18

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ jobs:
run: hatch run lint:black --check --verbose src tests
- name: Run flake8 linter
run: hatch run lint:flake8
- name: Run unit and integrations tests
run: hatch run test:pytest --cov=maven_artifact --cov-report=xml --cov-report=html

8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@ A python library to download and resolve maven artifacts.

* Fork repo
* Before submitting a PR
* Perform formatting (black): `hatch run:lint black src tests`
* Run linter (flake8): `hatch run:flake8`
* Perform formatting (black): `hatch run lint:black src tests`
* Run linter (flake8): `hatch run lint:flake8`
* Run tests:
* all: `hatch run test:pytest --cov=maven_artifact`
* unit only: `hatch run test:pytest --cov=maven_artifact tests/unit`
* integration only: `hatch run test:pytest --cov=maven_artifact tests/integration`
8 changes: 4 additions & 4 deletions src/maven_artifact/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .requestor import Requestor, RequestException # noqa: F401
from .artifact import Artifact # noqa: F401
from .resolver import Resolver # noqa: F401
from .downloader import Downloader # noqa: F401
from maven_artifact.requestor import Requestor, RequestException # noqa: F401
from maven_artifact.artifact import Artifact # noqa: F401
from maven_artifact.resolver import Resolver # noqa: F401
from maven_artifact.downloader import Downloader # noqa: F401
2 changes: 1 addition & 1 deletion src/maven_artifact/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


class Downloader(object):
def __init__(self, base="http://repo1.maven.org/maven2", username=None, password=None):
def __init__(self, base="https://repo.maven.apache.org/maven2", username=None, password=None):
self.requestor = Requestor(username, password)
self.resolver = Resolver(base, self.requestor)

Expand Down
20 changes: 20 additions & 0 deletions tests/integration/maven_artifact/test_downloader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import os
import tempfile

from maven_artifact import Artifact, Downloader


def test_downloader_of_existing_artifact():
artifact = Artifact.parse("org.apache.solr:solr:war:3.5.0")

dl = Downloader()

tmpdirname = tempfile.TemporaryDirectory()

tmpfile = os.path.join(tmpdirname.name, "example.war")

dl.download(artifact, filename=tmpfile)

assert os.path.exists(tmpfile)

tmpdirname.cleanup()
19 changes: 19 additions & 0 deletions tests/unit/maven_artifact/test_artifact.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import pytest
from maven_artifact import Artifact


def test_artifact_missing_params():
with pytest.raises(TypeError):
Artifact()


def test_issnapshot():
artifact = Artifact(
group_id="com.example", artifact_id="example-artifact", version="0.0.1", classifier="javadoc", extension="zip"
)

assert artifact.is_snapshot() is False

artifact = artifact.with_version(_version="0.0.1-SNAPSHOT")

assert artifact.is_snapshot() is True