Added Python unit testing
This commit is contained in:
@@ -2,3 +2,4 @@ pillow
|
||||
pyzbar
|
||||
qrcode
|
||||
protobuf
|
||||
pytest
|
||||
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
28
tests/test_gauth_reencoder.py
Normal file
28
tests/test_gauth_reencoder.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import pytest
|
||||
from gauth_reencoder import decode_totp
|
||||
from gauth_reencoder import generate_new_url
|
||||
|
||||
@pytest.mark.parametrize("url, account, issuer, secret, algorithm, digits", [
|
||||
("otpauth://totp/DEF?algorithm=&digits=&issuer=ABC&secret=jidowio390u20", "DEF", "ABC", "jidowio390u20", "", ""),
|
||||
("otpauth://totp/Label?secret=jidowio390u20&issuer=Issuer", "Label", "Issuer", "jidowio390u20", "", ""),
|
||||
])
|
||||
def test_decode_totp(url: str, account: str, issuer: str, secret: str, algorithm: str, digits: str):
|
||||
decoded = decode_totp(url)
|
||||
assert decoded["account"] == account
|
||||
assert decoded["issuer"] == issuer
|
||||
assert decoded["secret"] == secret
|
||||
assert decoded["algorithm"] == algorithm
|
||||
assert decoded["digits"] == digits
|
||||
|
||||
@pytest.mark.parametrize("url, account, issuer, secret, algorithm, digits", [
|
||||
("otpauth://totp/DEF?algorithm=&digits=&issuer=ABC&secret=jidowio390u20", "DEF", "ABC", "jidowio390u20", "", ""),
|
||||
])
|
||||
def test_generate_new_url(url: str, account: str, issuer: str, secret: str, algorithm: str, digits: str):
|
||||
decoded = dict()
|
||||
decoded["account"] = account
|
||||
decoded["issuer"] = issuer
|
||||
decoded["secret"] = secret
|
||||
decoded["algorithm"] = algorithm
|
||||
decoded["digits"] = digits
|
||||
new_url = generate_new_url(decoded)
|
||||
assert new_url == url
|
||||
Reference in New Issue
Block a user