Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Numan committed Dec 7, 2024
2 parents 0ebb013 + bf86f20 commit 2f25591
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 31 deletions.
22 changes: 8 additions & 14 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: Publish Python distribution to PyPI

on: push
on:
push:
tags:
- '*'

permissions:
contents: read
Expand All @@ -18,18 +21,11 @@ jobs:
with:
python-version: "3.x"

- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python - -y
- name: Update PATH
run: echo "$HOME/.local/bin" >> $GITHUB_PATH

- name: Update Poetry configuration
run: poetry config virtualenvs.create false

- name: Install dependencies
run: poetry install --sync --no-interaction
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install --sync --no-interaction
- name: Package project
run: poetry build
Expand All @@ -45,8 +41,6 @@ jobs:
name: Upload release to PyPI
runs-on: ubuntu-latest

if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes

needs:
- build

Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Tests](https://github.com/NumanIjaz/steuer-id/actions/workflows/run-tests.yml/badge.svg?branch=main)](https://github.com/NumanIjaz/steuer-id/actions/workflows/run-tests.yml)
[![Tests](https://github.com/NumanIjaz/steuerid/actions/workflows/run-tests.yml/badge.svg?branch=main)](https://github.com/NumanIjaz/steuer-id/actions/workflows/run-tests.yml)
[![Python versions](https://img.shields.io/pypi/pyversions/steuerid)](https://pypi.org/project/steuerid/)

# Steuer-ID
Expand All @@ -15,13 +15,13 @@ Based on the [official ELSTER documentation](https://download.elster.de/download
An example of how it can be used:

```python
from steuerid import SteuerIdValidator
from steuerid import SteuerId

validation_result = SteuerIdValidator.validate("02476291358")
validation_result = SteuerId.validate("02476291358")

print(validation_result) # (True, None) -> the provided input is a valid steuer id

validation_result = SteuerIdValidator.validate("x1234567890")
validation_result = SteuerId.validate("x1234567890")
print(validation_result) # (False, OnlyDigitsAllowedException) -> invalid input, only digits are allowed
```

Expand Down Expand Up @@ -51,7 +51,7 @@ pytest

- [Numan Ijaz](https://github.com/NumanIjaz)
- [Krzysztof Tomasz Zembrowski](https://github.com/zembrowski)
- [All Contributors](https://github.com/NumanIjaz/steuer-id/contributors)
- [All Contributors](https://github.com/NumanIjaz/steuerid/contributors)

## License

Expand Down
12 changes: 6 additions & 6 deletions steuerid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
STEUER_ID_LENGTH = 11
STEUERID_PRODUCTION_ENV = "STEUERID_PRODUCTION"

class SteuerIdValidator:
class SteuerId:
@staticmethod
def _validate_structure(steuer_id: str) -> None:
"""
Expand Down Expand Up @@ -129,7 +129,7 @@ def _validate_checksum_digit(steuer_id: str) -> None:
Raises:
InvalidChecksumDigit
"""
if steuer_id[-1] != str(SteuerIdValidator._get_checksum_digit(steuer_id)):
if steuer_id[-1] != str(SteuerId._get_checksum_digit(steuer_id)):
raise InvalidChecksumDigitException

@staticmethod
Expand All @@ -148,10 +148,10 @@ def validate(steuer_id: str) -> tuple[bool, None] | tuple[bool, SteuerIDValidati
the Exception object.
"""
try:
SteuerIdValidator._validate_structure(steuer_id)
SteuerIdValidator._validate_test_id(steuer_id)
SteuerIdValidator._validate_digit_repetitions(steuer_id)
SteuerIdValidator._validate_checksum_digit(steuer_id)
SteuerId._validate_structure(steuer_id)
SteuerId._validate_test_id(steuer_id)
SteuerId._validate_digit_repetitions(steuer_id)
SteuerId._validate_checksum_digit(steuer_id)

# input is a valid steuer id
return True, None
Expand Down
8 changes: 4 additions & 4 deletions tests/test_invalid.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from steuerid import SteuerIdValidator
from steuerid import SteuerId
from steuerid import STEUERID_PRODUCTION_ENV
from steuerid.exceptions import *

Expand All @@ -22,14 +22,14 @@ class TestInvalidSteuerId:
]
)
def test_invalid_with_exception(self, steuer_id, expected_exception):
is_valid, ex = SteuerIdValidator.validate(steuer_id)
is_valid, ex = SteuerId.validate(steuer_id)
assert not is_valid
assert isinstance(ex, expected_exception)

def test_no_test_id_allowed(self, monkeypatch):
monkeypatch.setenv(STEUERID_PRODUCTION_ENV, "True")

is_valid, ex = SteuerIdValidator.validate("01234567899")
is_valid, ex = SteuerId.validate("01234567899")
assert not is_valid
assert isinstance(ex, SteuerTestIdNotAllowedException)

Expand All @@ -54,5 +54,5 @@ def test_no_test_id_allowed(self, monkeypatch):
'123/456/78911',
])
def test_invalid_general(self, steuer_id):
is_valid, _ = SteuerIdValidator.validate(steuer_id)
is_valid, _ = SteuerId.validate(steuer_id)
assert not is_valid
4 changes: 2 additions & 2 deletions tests/test_valid.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from steuerid import SteuerIdValidator
from steuerid import SteuerId

class TestValidSteuerId:
@pytest.mark.parametrize("steuer_id", [
Expand All @@ -24,5 +24,5 @@ class TestValidSteuerId:
'12345678920',
])
def test_valid_general(self, steuer_id):
is_valid, _ = SteuerIdValidator.validate(steuer_id)
is_valid, _ = SteuerId.validate(steuer_id)
assert is_valid

0 comments on commit 2f25591

Please # to comment.