Skip to content
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
23 changes: 23 additions & 0 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,26 @@ jobs:

- name: Run Black
uses: psf/black@stable

pytest:
name: Run pytest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install Python
uses: actions/setup-python@v5

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt

- name: Install openpaygo
run: pip install .

- name: Install pytest
run: pip install pytest

- name: Run pytest
run: pytest
39 changes: 39 additions & 0 deletions test/test_encoder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import json

import pytest

from openpaygo import OpenPAYGOTokenEncoder, TokenType

with open("test/test_tokens.jsonl") as f:
sample_data = [json.loads(line) for line in f]


@pytest.fixture
def encoder():
return OpenPAYGOTokenEncoder()


@pytest.fixture
def token_type_lookup():
return {
"ADD_TIME": TokenType.ADD_TIME,
"SET_TIME": TokenType.SET_TIME,
"DISABLE_PAYG": TokenType.DISABLE_PAYG,
"COUNTER_SYNC": TokenType.COUNTER_SYNC,
}


@pytest.mark.parametrize("data", sample_data)
def test_generate_token(encoder, token_type_lookup, data):
new_count, final_token = encoder.generate_token(
secret_key=data["key"],
count=data["count"],
value=data["value_raw"],
token_type=token_type_lookup[data["token_type"]],
starting_code=data["starting_code"],
restricted_digit_set=data["restricted_digit_set"],
extended_token=data["extended_token"],
)

assert new_count == data["new_count"]
assert final_token == data["token"]
Loading
Loading