Tests / Test (Go) (push) Successful in 1m46s
Tests / Test (Python) (push) Successful in 14s
Lint / Lint (Go) (push) Successful in 21s
Lint / Lint (Python) (push) Successful in 10s
Tests / Test (Node/Svelte) (push) Successful in 12s
Lint / Lint (Node/Svelte) (push) Successful in 40s
35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
import os
|
|
import unittest
|
|
|
|
from shared_backend.auth import hash_password, verify_password
|
|
from shared_backend.config import DatabaseConfig
|
|
from shared_backend.tokens import hash_token, new_session_token
|
|
|
|
|
|
class SharedBackendTests(unittest.TestCase):
|
|
def test_password_round_trip(self):
|
|
password_hash = hash_password("correct horse battery staple")
|
|
self.assertTrue(verify_password("correct horse battery staple", password_hash))
|
|
self.assertFalse(verify_password("wrong password", password_hash))
|
|
|
|
def test_session_token_hash(self):
|
|
token, token_hash = new_session_token()
|
|
self.assertNotEqual(token, token_hash)
|
|
self.assertEqual(hash_token(token), token_hash)
|
|
|
|
def test_database_config_from_environment(self):
|
|
config = DatabaseConfig.from_env(
|
|
{
|
|
**os.environ,
|
|
"DATABASE_URL": "postgresql://user:password@localhost:5432/app",
|
|
"DATABASE_MAX_CONNS": "7",
|
|
"DATABASE_MIN_CONNS": "2",
|
|
}
|
|
)
|
|
self.assertEqual(config.max_size, 7)
|
|
self.assertEqual(config.min_size, 2)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|