Skip to content

Add decoder unit tests #26

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
38 changes: 38 additions & 0 deletions test/test_decoder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import json

import pytest

from openpaygo import OpenPAYGOTokenDecoder, TokenType

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


@pytest.fixture
def decoder():
return OpenPAYGOTokenDecoder()


@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_parse_token(decoder, token_type_lookup, data):
token_value, token_type, new_count, _ = decoder.decode_token(
secret_key=data["key"],
starting_code=data["starting_code"],
restricted_digit_set=data["restricted_digit_set"],
token=data["token"],
count=data["count"],
)

assert token_value == data["value_raw"]
assert token_type == token_type_lookup[data["token_type"]]
assert new_count == data["new_count"]
Loading