Skip to content

Commit 2abdb91

Browse files
committed
tests/fix/feat: add tests, fix bugs, add controller
1 parent b5a52ed commit 2abdb91

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+821
-457
lines changed

Doxyfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ PROJECT_NAME = "pyEchoNext"
4848
# could be handy for archiving the generated documentation or if some version
4949
# control system is used.
5050

51-
PROJECT_NUMBER = "0.6.12"
51+
PROJECT_NUMBER = "0.7.11"
5252

5353
# Using the PROJECT_BRIEF tag one can provide an optional one line description
5454
# for a project that appears at the top of each page and should give viewer a

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Welcome to **EchoNext**, where innovation meets simplicity! Are you tired of the
4545

4646
**Imagine** a lightweight framework that empowers you to create modern web applications with lightning speed and flexibility. With EchoNext, you're not just coding; you're building a masterpiece!
4747

48-
> Last stable version: 0.6.12 alpha
48+
> Last stable version: 0.7.11 alpha
4949
5050
> Next Big Update: ASYNC & unicorn support
5151
@@ -767,7 +767,7 @@ To test the web framework, PyTest with the pytest-cov plugin is used. You can lo
767767

768768
| Statements | Miss | Coverage |
769769
|------------|------------|----------|
770-
| 1327 | 997 | 28% |
770+
| 1327 | 936 | 34% |
771771

772772
## Documentation 🌍
773773
Extended documentation and framework specifications are available at the following links:

SECURITY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ currently being supported with security updates.
77

88
| Version | Supported |
99
| ------- | ------------------ |
10-
| 0.6.11 | :white_check_mark: |
10+
| 0.7.11 | :white_check_mark: |
1111
| 0.6.11 | :white_check_mark: |
1212
| 0.6.10 | :white_check_mark: |
1313
| 0.6.9 | :white_check_mark: |

examples/advanced_app.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,35 @@
33
from pyechonext.app import ApplicationType, EchoNext
44
from pyechonext.config import Settings
55
from pyechonext.middleware import middlewares
6-
from pyechonext.urls import URL, IndexView
7-
from pyechonext.views import View
6+
from pyechonext.mvc.controllers import PageController
7+
from pyechonext.urls import URL
88

99

10-
class UsersView(View):
11-
def get(self, request, response, **kwargs):
12-
return "users get"
10+
class UsersPageController(PageController):
11+
def get(self, request, response, **kwargs):
12+
return "users get"
1313

14-
def post(self, request, response, **kwargs):
15-
return "users post"
14+
def post(self, request, response, **kwargs):
15+
return "users post"
1616

1717

18-
url_patterns = [URL(url="/", view=IndexView), URL(url="/users", view=UsersView)]
18+
url_patterns = [URL(path="/users", controller=UsersPageController)]
1919
settings = Settings(
20-
BASE_DIR=os.path.dirname(os.path.abspath(__file__)), TEMPLATES_DIR="templates"
20+
BASE_DIR=os.path.dirname(os.path.abspath(__file__)), TEMPLATES_DIR="templates"
2121
)
2222
echonext = EchoNext(
23-
__name__,
24-
settings,
25-
middlewares,
26-
urls=url_patterns,
27-
application_type=ApplicationType.HTML,
23+
__name__,
24+
settings,
25+
middlewares,
26+
urls=url_patterns,
27+
application_type=ApplicationType.HTML,
2828
)
2929

3030

3131
@echonext.route_page("/book")
32-
class BooksResource(View):
33-
def get(self, request, response, **kwargs):
34-
return f"Books Page: {request.GET}"
32+
class BooksResource(PageController):
33+
def get(self, request, response, **kwargs):
34+
return f"Books Page: {request.GET}"
3535

36-
def post(self, request, response, **kwargs):
37-
return "Endpoint to create a book"
36+
def post(self, request, response, **kwargs):
37+
return "Endpoint to create a book"

examples/example_locale.py

Lines changed: 53 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,83 @@
1-
import os
2-
31
from pyechonext.apidoc_ui import APIDocUI, APIDocumentation
42
from pyechonext.app import ApplicationType, EchoNext
53
from pyechonext.config import SettingsConfigType, SettingsLoader
64
from pyechonext.middleware import middlewares
75
from pyechonext.mvc.controllers import PageController
8-
from pyechonext.response import Response
96
from pyechonext.static import StaticFile
107
from pyechonext.template_engine.jinja import render_template
118
from pyechonext.urls import URL
129
from pyechonext.utils.exceptions import MethodNotAllow
1310

1411

1512
class UsersView(PageController):
16-
def get(self, request, response, *args, **kwargs):
17-
return render_template(
18-
request,
19-
"index.html",
20-
user_name="User",
21-
session_id=request.session_id,
22-
friends=["Bob", "Anna", "John"],
23-
)
13+
def get(self, request, response, *args, **kwargs):
14+
return render_template(
15+
request,
16+
"index.html",
17+
user_name="User",
18+
session_id=request.session_id,
19+
friends=["Bob", "Anna", "John"],
20+
)
2421

25-
def post(self, request, response, *args, **kwargs):
26-
raise MethodNotAllow(f"Request {request.path}: method not allow")
22+
def post(self, request, response, *args, **kwargs):
23+
raise MethodNotAllow(f"Request {request.path}: method not allow")
2724

2825

2926
url_patterns = [URL(path="/users", controller=UsersView)]
3027
config_loader = SettingsLoader(SettingsConfigType.PYMODULE, "el_config.py")
3128
settings = config_loader.get_settings()
3229
static_files = [StaticFile(settings, "styles.css")]
3330
echonext = EchoNext(
34-
__name__,
35-
settings,
36-
middlewares,
37-
urls=url_patterns,
38-
application_type=ApplicationType.HTML,
39-
static_files=static_files,
31+
__name__,
32+
settings,
33+
middlewares,
34+
urls=url_patterns,
35+
application_type=ApplicationType.HTML,
36+
static_files=static_files,
4037
)
4138
apidoc = APIDocumentation(echonext)
4239

4340

4441
@echonext.route_page("/api-docs")
4542
def api_docs(request, response):
46-
ui = APIDocUI(apidoc.generate_spec())
47-
return ui.generate_html_page()
43+
ui = APIDocUI(apidoc.generate_spec())
44+
return ui.generate_html_page()
4845

4946

5047
@echonext.route_page("/book")
5148
class BooksResource(PageController):
52-
"""
53-
This class describes a books resource.
54-
"""
55-
56-
def get(self, request, response, **kwargs):
57-
"""
58-
get queries
59-
60-
:param request: The request
61-
:type request: Request
62-
:param response: The response
63-
:type response: Response
64-
:param kwargs: The keywords arguments
65-
:type kwargs: dictionary
66-
67-
:returns: result
68-
:rtype: str
69-
"""
70-
return echonext.i18n_loader.get_string("title %{name}", name=str(request.GET))
71-
72-
def post(self, request, response, **kwargs):
73-
"""
74-
post queries
75-
76-
:param request: The request
77-
:type request: Request
78-
:param response: The response
79-
:type response: Response
80-
:param kwargs: The keywords arguments
81-
:type kwargs: dictionary
82-
83-
:returns: result
84-
:rtype: str
85-
"""
86-
return echonext.l10n_loader.format_currency(1305.50)
49+
"""
50+
This class describes a books resource.
51+
"""
52+
53+
def get(self, request, response, **kwargs):
54+
"""
55+
get queries
56+
57+
:param request: The request
58+
:type request: Request
59+
:param response: The response
60+
:type response: Response
61+
:param kwargs: The keywords arguments
62+
:type kwargs: dictionary
63+
64+
:returns: result
65+
:rtype: str
66+
"""
67+
return echonext.i18n_loader.get_string("title %{name}", name=str(request.GET))
68+
69+
def post(self, request, response, **kwargs):
70+
"""
71+
post queries
72+
73+
:param request: The request
74+
:type request: Request
75+
:param response: The response
76+
:type response: Response
77+
:param kwargs: The keywords arguments
78+
:type kwargs: dictionary
79+
80+
:returns: result
81+
:rtype: str
82+
"""
83+
return echonext.l10n_loader.format_currency(1305.50)

examples/hashing.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from pyechonext.security.hashing import HashAlgorithm, PlainHasher, SaltedHasher
2+
3+
hasher = PlainHasher(HashAlgorithm.BLAKE2S)
4+
old_hash = hasher.hash("TEXT")
5+
new_hash = hasher.hash("TEXT")
6+
7+
if hasher.verify("TEXT", new_hash): # true
8+
print("Yes!")
9+
10+
if hasher.verify("TEXT2", old_hash): # false
11+
print("Yes!")
12+
13+
14+
hasher = SaltedHasher(HashAlgorithm.BLAKE2S, salt="bob")
15+
old_hash = hasher.hash("TEXT")
16+
new_hash = hasher.hash("TEXT")
17+
18+
if hasher.verify("TEXT", new_hash): # true
19+
print("Yes!")
20+
21+
if hasher.verify("TEXT2", old_hash): # false
22+
print("Yes!")

examples/security.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from pyechonext.security.crypts import PSPCAlgorithm
22

3-
pspc = PSPCAlgorithm()
3+
pspc = PSPCAlgorithm(100)
44

55
passwords = ["AngryPassword", "S0mesd7623tds@&6^@_", "PassWord", "Pass"]
66

77
for password in passwords:
8-
print("Base:", password)
9-
print("Crypted:", pspc.crypt(password))
10-
print("Decrypted:", pspc.decrypt(pspc.crypt(password)))
11-
print()
8+
print("Base:", password)
9+
print("Crypted:", pspc.crypt(password))
10+
print("Decrypted:", pspc.decrypt(pspc.crypt(password)))
11+
print()

examples/simple_api.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,38 @@
33
from pyechonext.app import ApplicationType, EchoNext
44
from pyechonext.config import Settings
55
from pyechonext.middleware import middlewares
6+
from pyechonext.mvc.controllers import PageController
67
from pyechonext.response import Response
7-
from pyechonext.urls import URL, IndexView
8-
from pyechonext.views import View
8+
from pyechonext.urls import URL
99

1010

11-
class UsersView(View):
12-
def get(self, request, response, **kwargs):
13-
return Response(request, body={"users": "get"})
11+
class UsersPageController(PageController):
12+
def get(self, request, response, **kwargs):
13+
return Response(request, body={"users": "get"})
1414

15-
def post(self, request, response, **kwargs):
16-
return {"users": "post"}
15+
def post(self, request, response, **kwargs):
16+
return {"users": "post"}
1717

1818

19-
url_patterns = [URL(url="/", view=IndexView), URL(url="/users", view=UsersView)]
19+
url_patterns = [URL(path="/users", controller=UsersPageController)]
2020

2121
settings = Settings(
22-
BASE_DIR=os.path.dirname(os.path.abspath(__file__)), TEMPLATES_DIR="templates"
22+
BASE_DIR=os.path.dirname(os.path.abspath(__file__)), TEMPLATES_DIR="templates"
2323
)
2424

2525
echonext = EchoNext(
26-
__name__,
27-
settings,
28-
middlewares,
29-
urls=url_patterns,
30-
application_type=ApplicationType.JSON,
26+
__name__,
27+
settings,
28+
middlewares,
29+
urls=url_patterns,
30+
application_type=ApplicationType.JSON,
3131
)
3232

3333

3434
@echonext.route_page("/book")
35-
class BooksResource(View):
36-
def get(self, request, response, **kwargs):
37-
return {"params": {request.GET}, "page": "books"}
35+
class BooksResource(PageController):
36+
def get(self, request, response, **kwargs):
37+
return {"params": request.GET, "page": "books"}
3838

39-
def post(self, request, response, **kwargs):
40-
return {"params": {request.POST}, "page": "books"}
39+
def post(self, request, response, **kwargs):
40+
return {"params": request.POST, "page": "books"}

examples/simple_app.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,35 @@
88
from pyechonext.middleware import middlewares
99

1010
settings = Settings(
11-
BASE_DIR=os.path.dirname(os.path.abspath(__file__)), TEMPLATES_DIR="templates"
11+
BASE_DIR=os.path.dirname(os.path.abspath(__file__)), TEMPLATES_DIR="templates"
1212
)
1313
echonext = EchoNext(
14-
__name__, settings, middlewares, application_type=ApplicationType.HTML
14+
__name__, settings, middlewares, application_type=ApplicationType.HTML
1515
)
1616
session = SQLiteSession("echonext.db")
1717

1818

1919
class User(SessionModel):
20-
__tablename__ = "Users"
20+
__tablename__ = "Users"
2121

22-
id = IntegerField(primary_key=True)
23-
name = TextField(null=False)
24-
cash = RealField(null=False, default=0.0)
22+
id = IntegerField(primary_key=True)
23+
name = TextField(null=False)
24+
cash = RealField(null=False, default=0.0)
2525

26-
def __repr__(self):
27-
return f"<User {self.pk}>"
26+
def __repr__(self):
27+
return f"<User {self.pk}>"
2828

2929

3030
@echonext.route_page("/")
3131
def home(request, response):
32-
user = User(name="John", cash=100.0)
33-
session.add(user)
34-
session.commit()
35-
return "Hello from the HOME page"
32+
user = User(name="John", cash=100.0)
33+
session.add(user)
34+
session.commit()
35+
return "Hello from the HOME page"
3636

3737

3838
@echonext.route_page("/users")
3939
def about(request, response):
40-
users = session.get_all_by_model(User)
40+
users = session.get_all_by_model(User)
4141

42-
return f"Users: {[f'{user.name}: {user.cash}$' for user in users]}"
42+
return f"Users: {[f'{user.name}: {user.cash}$' for user in users]}"

0 commit comments

Comments
 (0)