Skip to content

Commit 003ddca

Browse files
committed
add test for defence, fix code style
1 parent b265785 commit 003ddca

File tree

10 files changed

+44
-16
lines changed

10 files changed

+44
-16
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
commit b2657853dd73eec85467e10d690725179af160bd
2+
Author: Alexeev Bronislav <[email protected]>
3+
Date: Fri Jul 4 06:21:15 2025 +0700
4+
5+
fix routing bugs, fix tests
6+
17
commit 5e8bc165eba61837996728bc4171fff43fedffdf
28
Author: Alexeev Bronislav <[email protected]>
39
Date: Fri Jul 4 05:02:30 2025 +0700

examples/random_examples/simple_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def post(self, request, response, **kwargs):
3131
)
3232

3333

34-
@echonext.route_page('/{name}/')
34+
@echonext.route_page("/{name}/")
3535
def index(request, response, name):
3636
return name
3737

pyechonext/mvc/routes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,4 +249,4 @@ def resolve(
249249
if raise_404:
250250
raise URLNotFound(f'URL "{url}" not found.')
251251
else:
252-
return None, None
252+
return None, None

pyechonext/security/crypts.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def crypt(self, password: str) -> str:
4646
"""
4747
if not password:
4848
return ""
49-
49+
5050
crypted = " ".join(password).split()
5151
crypted = list(map(ord, crypted))
5252

@@ -64,6 +64,6 @@ def decrypt(self, crypted: str) -> str:
6464
"""
6565
if not crypted:
6666
return ""
67-
67+
6868
password = list(map(lambda x: int(x) // self.seed, crypted[::-1].split(".")))
6969
return "".join(list(map(chr, password)))

tests/test_cache.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# tests/test_cache.py
22
import time
3+
34
import pytest
4-
from pyechonext.cache import InMemoryCache, CacheEntry, Cacheable
5+
6+
from pyechonext.cache import Cacheable, CacheEntry, InMemoryCache
7+
58

69
class TestCacheEntry:
710
def test_entry_creation(self):
@@ -10,6 +13,7 @@ def test_entry_creation(self):
1013
assert entry.value == 42
1114
assert entry.expiry == 1000.0
1215

16+
1317
class TestInMemoryCache:
1418
@pytest.fixture
1519
def cache(self):
@@ -40,6 +44,7 @@ def test_clear(self, cache):
4044
cache.clear()
4145
assert not cache._cache
4246

47+
4348
class TestCacheable:
4449
@pytest.fixture
4550
def cacheable(self):
@@ -49,9 +54,9 @@ def cacheable(self):
4954
def test_cache_operations(self, cacheable):
5055
cacheable.save("key1", "value1")
5156
assert cacheable.cache.get("key1") == "value1"
52-
57+
5358
cacheable.update("key1", "value2")
5459
assert cacheable.cache.get("key1") == "value2"
55-
60+
5661
cacheable.clear_data("key1")
5762
assert cacheable.cache.get("key1") is None

tests/test_crypts.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# tests/test_crypts.py
22
import pytest
3+
34
from pyechonext.security.crypts import PSPCAlgorithm
45

6+
57
class TestPSPCAlgorithm:
68
@pytest.fixture
79
def algo(self):

tests/defence.py renamed to tests/test_defence.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# tests/test_defence.py
2+
import pytest
23
from pyechonext.security.defence import CSRFTokenManager
34

5+
46
class TestCSRFTokenManager:
57
@pytest.fixture
68
def manager(self):

tests/test_hashing.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# tests/test_hashing.py
22
import pytest
3-
from pyechonext.security.hashing import PlainHasher, SaltedHasher, HashAlgorithm
3+
4+
from pyechonext.security.hashing import HashAlgorithm, PlainHasher, SaltedHasher
5+
46

57
class TestHashing:
6-
@pytest.mark.parametrize("algorithm", [
7-
HashAlgorithm.SHA256,
8-
HashAlgorithm.SHA512,
9-
HashAlgorithm.MD5
10-
])
8+
@pytest.mark.parametrize(
9+
"algorithm", [HashAlgorithm.SHA256, HashAlgorithm.SHA512, HashAlgorithm.MD5]
10+
)
1111
def test_plain_hasher(self, algorithm):
1212
hasher = PlainHasher(algorithm)
1313
data = "password123"
@@ -20,7 +20,7 @@ def test_salted_hasher(self):
2020
data = "secure_data"
2121
hashed = hasher.hash(data)
2222
assert hasher.verify(data, hashed) is True
23-
23+
2424
# Different salt should produce different hash
2525
diff_salt_hasher = SaltedHasher(salt="different_salt")
2626
assert diff_salt_hasher.verify(data, hashed) is False

tests/test_stack.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# tests/test_stack.py
22
import pytest
3+
34
from pyechonext.utils.stack import LIFOStack
45

6+
57
class TestLIFOStack:
68
@pytest.fixture
79
def stack(self):

tests/test_trie.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
# tests/test_trie.py
22
import pytest
3+
34
from pyechonext.utils.trie import PrefixTree
45

6+
57
class TestPrefixTree:
68
@pytest.fixture
79
def trie(self):
810
trie = PrefixTree()
9-
words = ["apple", "app", "aposematic", "appreciate", "book", "bad", "bear", "bat"]
11+
words = [
12+
"apple",
13+
"app",
14+
"aposematic",
15+
"appreciate",
16+
"book",
17+
"bad",
18+
"bear",
19+
"bat",
20+
]
1021
for word in words:
1122
trie.insert(word)
1223
return trie
@@ -23,7 +34,7 @@ def test_starts_with(self, trie):
2334

2435
def test_size(self, trie):
2536
assert trie.size() > 0
26-
assert trie.size(trie.root.children['a']) == 20
37+
assert trie.size(trie.root.children["a"]) == 20
2738

2839
def test_empty_prefix(self, trie):
2940
assert len(trie.starts_with("")) == 8

0 commit comments

Comments
 (0)