square-administration 3.1.0__tar.gz → 3.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. {square_administration-3.1.0 → square_administration-3.2.0}/PKG-INFO +16 -1
  2. {square_administration-3.1.0 → square_administration-3.2.0}/README.md +15 -0
  3. {square_administration-3.1.0 → square_administration-3.2.0}/setup.py +2 -2
  4. {square_administration-3.1.0 → square_administration-3.2.0}/square_administration/configuration.py +11 -23
  5. {square_administration-3.1.0 → square_administration-3.2.0}/square_administration/data/config.ini +5 -0
  6. square_administration-3.2.0/square_administration/data/config.testing.ini +53 -0
  7. {square_administration-3.1.0 → square_administration-3.2.0}/square_administration/main.py +1 -1
  8. {square_administration-3.1.0 → square_administration-3.2.0}/square_administration/routes/authentication.py +6 -7
  9. {square_administration-3.1.0 → square_administration-3.2.0}/square_administration/routes/core.py +2 -2
  10. square_administration-3.2.0/square_administration/utils/common.py +36 -0
  11. {square_administration-3.1.0 → square_administration-3.2.0}/square_administration.egg-info/PKG-INFO +16 -1
  12. {square_administration-3.1.0 → square_administration-3.2.0}/square_administration.egg-info/SOURCES.txt +1 -0
  13. {square_administration-3.1.0 → square_administration-3.2.0}/square_administration.egg-info/requires.txt +1 -1
  14. square_administration-3.2.0/tests/conftest.py +61 -0
  15. square_administration-3.2.0/tests/test_1.py +10 -0
  16. square_administration-3.1.0/square_administration/utils/common.py +0 -14
  17. square_administration-3.1.0/tests/conftest.py +0 -11
  18. square_administration-3.1.0/tests/test_1.py +0 -16
  19. {square_administration-3.1.0 → square_administration-3.2.0}/setup.cfg +0 -0
  20. {square_administration-3.1.0 → square_administration-3.2.0}/square_administration/__init__.py +0 -0
  21. {square_administration-3.1.0 → square_administration-3.2.0}/square_administration/messages.py +0 -0
  22. {square_administration-3.1.0 → square_administration-3.2.0}/square_administration/pydantic_models/__init__.py +0 -0
  23. {square_administration-3.1.0 → square_administration-3.2.0}/square_administration/pydantic_models/authentication.py +0 -0
  24. {square_administration-3.1.0 → square_administration-3.2.0}/square_administration/pydantic_models/core.py +0 -0
  25. {square_administration-3.1.0 → square_administration-3.2.0}/square_administration/routes/__init__.py +0 -0
  26. {square_administration-3.1.0 → square_administration-3.2.0}/square_administration/utils/__init__.py +0 -0
  27. {square_administration-3.1.0 → square_administration-3.2.0}/square_administration.egg-info/dependency_links.txt +0 -0
  28. {square_administration-3.1.0 → square_administration-3.2.0}/square_administration.egg-info/top_level.txt +0 -0
  29. {square_administration-3.1.0 → square_administration-3.2.0}/tests/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: square_administration
3
- Version: 3.1.0
3
+ Version: 3.2.0
4
4
  Summary: common business layer for my personal server.
5
5
  Home-page: https://github.com/thepmsquare/square_administration
6
6
  Author: thePmSquare
@@ -32,6 +32,21 @@ pip install square_administration
32
32
 
33
33
  ## changelog
34
34
 
35
+ ### v3.2.0
36
+
37
+ - move global_int_app_id getting logic from configuration.py to utils->common
38
+ - env
39
+ - add DB_IP, DB_PORT, DB_USERNAME, DB_PASSWORD
40
+ - add config.testing.ini
41
+ - file path reading through os.path.join method.
42
+ - testing
43
+ - add conftest file to create and cleanup test database, also to patch config file.
44
+ - update existing tests to use the new fixtures.
45
+
46
+ ### v3.1.1
47
+
48
+ - bump square_logger to 2.0.0
49
+
35
50
  ### v3.1.0
36
51
 
37
52
  - add pytest as dependency.
@@ -16,6 +16,21 @@ pip install square_administration
16
16
 
17
17
  ## changelog
18
18
 
19
+ ### v3.2.0
20
+
21
+ - move global_int_app_id getting logic from configuration.py to utils->common
22
+ - env
23
+ - add DB_IP, DB_PORT, DB_USERNAME, DB_PASSWORD
24
+ - add config.testing.ini
25
+ - file path reading through os.path.join method.
26
+ - testing
27
+ - add conftest file to create and cleanup test database, also to patch config file.
28
+ - update existing tests to use the new fixtures.
29
+
30
+ ### v3.1.1
31
+
32
+ - bump square_logger to 2.0.0
33
+
19
34
  ### v3.1.0
20
35
 
21
36
  - add pytest as dependency.
@@ -4,7 +4,7 @@ package_name = "square_administration"
4
4
 
5
5
  setup(
6
6
  name=package_name,
7
- version="3.1.0",
7
+ version="3.2.0",
8
8
  packages=find_packages(),
9
9
  package_data={
10
10
  package_name: ["data/*"],
@@ -18,7 +18,7 @@ setup(
18
18
  "pytest>=8.0.0",
19
19
  "httpx>=0.27.2",
20
20
  "square_commons>=1.0.0",
21
- "square_logger>=1.0.0",
21
+ "square_logger>=2.0.0",
22
22
  "square_database_helper>=2.0.0",
23
23
  "square_database_structure>=1.0.0",
24
24
  "square_authentication_helper>=2.1.0",
@@ -3,20 +3,12 @@ import sys
3
3
 
4
4
  from square_authentication_helper import SquareAuthenticationHelper
5
5
  from square_commons import ConfigReader
6
- from square_database_helper import SquareDatabaseHelper, FiltersV0
7
- from square_database_helper.pydantic_models import FilterConditionsV0
8
- from square_database_structure.square import global_string_database_name
9
- from square_database_structure.square.public import global_string_schema_name
10
- from square_database_structure.square.public.tables import App
6
+ from square_database_helper import SquareDatabaseHelper
11
7
  from square_logger.main import SquareLogger
12
8
 
13
9
  try:
14
- config_file_path = (
15
- os.path.dirname(os.path.abspath(__file__))
16
- + os.sep
17
- + "data"
18
- + os.sep
19
- + "config.ini"
10
+ config_file_path = os.path.join(
11
+ os.path.dirname(os.path.abspath(__file__)), "data", "config.ini"
20
12
  )
21
13
  ldict_configuration = ConfigReader(config_file_path).read_configuration()
22
14
 
@@ -43,6 +35,13 @@ try:
43
35
  "SSL_KEY_FILE_PATH"
44
36
  ]
45
37
  config_str_cookie_domain = ldict_configuration["ENVIRONMENT"]["COOKIE_DOMAIN"]
38
+ config_str_db_ip = ldict_configuration["ENVIRONMENT"]["DB_IP"]
39
+
40
+ config_int_db_port = int(ldict_configuration["ENVIRONMENT"]["DB_PORT"])
41
+
42
+ config_str_db_username = ldict_configuration["ENVIRONMENT"]["DB_USERNAME"]
43
+
44
+ config_str_db_password = ldict_configuration["ENVIRONMENT"]["DB_PASSWORD"]
46
45
  # ===========================================
47
46
 
48
47
  # ===========================================
@@ -100,18 +99,7 @@ try:
100
99
  param_str_square_authentication_ip=config_str_square_authentication_ip,
101
100
  param_int_square_authentication_port=config_int_square_authentication_port,
102
101
  )
103
- # get app id
104
- global_int_app_id = global_object_square_database_helper.get_rows_v0(
105
- database_name=global_string_database_name,
106
- schema_name=global_string_schema_name,
107
- table_name=App.__tablename__,
108
- filters=FiltersV0(
109
- root={
110
- App.app_name.name: FilterConditionsV0(eq=config_str_app_name),
111
- }
112
- ),
113
- columns=[App.app_id.name],
114
- )["data"]["main"][0][App.app_id.name]
102
+
115
103
  except Exception as e:
116
104
  print(
117
105
  "\033[91mMissing or incorrect config.ini file.\n"
@@ -16,6 +16,11 @@ SSL_KEY_FILE_PATH = ssl.key
16
16
 
17
17
  COOKIE_DOMAIN = localhost
18
18
 
19
+ DB_IP = localhost
20
+ DB_PORT = 10001
21
+ DB_USERNAME = postgres
22
+ DB_PASSWORD = dummy
23
+
19
24
  [SQUARE_LOGGER]
20
25
 
21
26
  # | Log Level | Value |
@@ -0,0 +1,53 @@
1
+ [GENERAL]
2
+ MODULE_NAME = square_administration
3
+ APP_NAME = square_admin
4
+
5
+ [ENVIRONMENT]
6
+ HOST_IP = 0.0.0.0
7
+ HOST_PORT = 10111
8
+
9
+ LOG_FILE_NAME = square_administration
10
+
11
+ ADMIN_PASSWORD_HASH = $2b$12$tDw4ZR0guiF5s5oVve5PcuELhlWO.lUH.OChPoeWVn95ac7QJlndq
12
+
13
+ # absolute path (mandatory only for http)
14
+ SSL_CRT_FILE_PATH = ssl.crt
15
+ SSL_KEY_FILE_PATH = ssl.key
16
+
17
+ COOKIE_DOMAIN = localhost
18
+
19
+ DB_IP = raspi.thepmsquare.com
20
+ DB_PORT = 15432
21
+ DB_USERNAME = postgres
22
+ DB_PASSWORD = testing_password
23
+
24
+
25
+ [SQUARE_LOGGER]
26
+
27
+ # | Log Level | Value |
28
+ # | --------- | ----- |
29
+ # | CRITICAL | 50 |
30
+ # | ERROR | 40 |
31
+ # | WARNING | 30 |
32
+ # | INFO | 20 |
33
+ # | DEBUG | 10 |
34
+ # | NOTSET | 0 |
35
+
36
+ LOG_LEVEL = 20
37
+ # absolute or relative path
38
+ LOG_PATH = logs
39
+ # number of backup log files to keep during rotation
40
+ # if backupCount is zero, rollover never occurs.
41
+ LOG_BACKUP_COUNT = 3
42
+
43
+ [SQUARE_DATABASE_HELPER]
44
+
45
+ SQUARE_DATABASE_PROTOCOL = http
46
+ SQUARE_DATABASE_IP = raspi.thepmsquare.com
47
+ SQUARE_DATABASE_PORT = 20010
48
+
49
+ [SQUARE_AUTHENTICATION_HELPER]
50
+
51
+ SQUARE_AUTHENTICATION_PROTOCOL = http
52
+ SQUARE_AUTHENTICATION_IP = raspi.thepmsquare.com
53
+ SQUARE_AUTHENTICATION_PORT = 20011
@@ -30,7 +30,7 @@ app.include_router(authentication.router)
30
30
 
31
31
 
32
32
  @app.get("/")
33
- @global_object_square_logger.async_auto_logger
33
+ @global_object_square_logger.auto_logger()
34
34
  async def root():
35
35
  output_content = get_api_output_in_standard_format(log=config_str_module_name)
36
36
  return JSONResponse(status_code=status.HTTP_200_OK, content=output_content)
@@ -18,7 +18,6 @@ from square_administration.configuration import (
18
18
  global_object_square_logger,
19
19
  config_str_admin_password_hash,
20
20
  global_object_square_authentication_helper,
21
- global_int_app_id,
22
21
  config_str_cookie_domain,
23
22
  global_object_square_database_helper,
24
23
  )
@@ -28,7 +27,7 @@ from square_administration.pydantic_models.authentication import (
28
27
  LoginUsernameV0,
29
28
  RemoveAppForSelfV0,
30
29
  )
31
- from square_administration.utils.common import is_https
30
+ from square_administration.utils.common import is_https, global_int_app_id
32
31
 
33
32
  router = APIRouter(
34
33
  tags=["authentication"],
@@ -36,7 +35,7 @@ router = APIRouter(
36
35
 
37
36
 
38
37
  @router.post("/register_username/v0")
39
- @global_object_square_logger.async_auto_logger
38
+ @global_object_square_logger.auto_logger()
40
39
  async def register_username_v0(
41
40
  body: RegisterUsernameV0,
42
41
  ):
@@ -137,7 +136,7 @@ async def register_username_v0(
137
136
 
138
137
 
139
138
  @router.post("/login_username/v0")
140
- @global_object_square_logger.async_auto_logger
139
+ @global_object_square_logger.auto_logger()
141
140
  async def login_username_v0(
142
141
  body: LoginUsernameV0,
143
142
  ):
@@ -221,7 +220,7 @@ async def login_username_v0(
221
220
 
222
221
 
223
222
  @router.patch("/remove_app_for_self/v0")
224
- @global_object_square_logger.async_auto_logger
223
+ @global_object_square_logger.auto_logger()
225
224
  async def remove_app_for_self_v0(
226
225
  access_token: Annotated[str, Header()],
227
226
  body: RemoveAppForSelfV0,
@@ -318,7 +317,7 @@ async def remove_app_for_self_v0(
318
317
 
319
318
 
320
319
  @router.delete("/logout/v0")
321
- @global_object_square_logger.async_auto_logger
320
+ @global_object_square_logger.auto_logger()
322
321
  async def logout_v0(request: Request):
323
322
 
324
323
  try:
@@ -401,7 +400,7 @@ async def logout_v0(request: Request):
401
400
 
402
401
 
403
402
  @router.get("/generate_access_token/v0")
404
- @global_object_square_logger.async_auto_logger
403
+ @global_object_square_logger.auto_logger()
405
404
  async def generate_access_token_v0(
406
405
  request: Request,
407
406
  ):
@@ -20,10 +20,10 @@ from square_administration.configuration import (
20
20
  global_object_square_logger,
21
21
  global_object_square_database_helper,
22
22
  global_object_square_authentication_helper,
23
- global_int_app_id,
24
23
  )
25
24
  from square_administration.messages import messages
26
25
  from square_administration.pydantic_models.core import GetAllGreetingsV0
26
+ from square_administration.utils.common import global_int_app_id
27
27
 
28
28
  router = APIRouter(
29
29
  tags=["core"],
@@ -31,7 +31,7 @@ router = APIRouter(
31
31
 
32
32
 
33
33
  @router.post("/get_all_greetings/v0")
34
- @global_object_square_logger.async_auto_logger
34
+ @global_object_square_logger.auto_logger()
35
35
  async def get_all_greetings_v0(
36
36
  access_token: Annotated[str, Header()], body: GetAllGreetingsV0
37
37
  ):
@@ -0,0 +1,36 @@
1
+ import os
2
+
3
+ from square_database_helper import FiltersV0
4
+ from square_database_helper.pydantic_models import FilterConditionsV0
5
+ from square_database_structure.square import global_string_database_name
6
+ from square_database_structure.square.public import global_string_schema_name
7
+ from square_database_structure.square.public.tables import App
8
+
9
+ from square_administration.configuration import (
10
+ config_str_ssl_key_file_path,
11
+ config_str_ssl_crt_file_path,
12
+ global_object_square_logger,
13
+ global_object_square_database_helper,
14
+ config_str_app_name,
15
+ )
16
+
17
+
18
+ @global_object_square_logger.auto_logger()
19
+ def is_https() -> bool:
20
+ return os.path.exists(config_str_ssl_key_file_path) and os.path.exists(
21
+ config_str_ssl_crt_file_path
22
+ )
23
+
24
+
25
+ # get app id
26
+ global_int_app_id = global_object_square_database_helper.get_rows_v0(
27
+ database_name=global_string_database_name,
28
+ schema_name=global_string_schema_name,
29
+ table_name=App.__tablename__,
30
+ filters=FiltersV0(
31
+ root={
32
+ App.app_name.name: FilterConditionsV0(eq=config_str_app_name),
33
+ }
34
+ ),
35
+ columns=[App.app_id.name],
36
+ )["data"]["main"][0][App.app_id.name]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: square-administration
3
- Version: 3.1.0
3
+ Version: 3.2.0
4
4
  Summary: common business layer for my personal server.
5
5
  Home-page: https://github.com/thepmsquare/square_administration
6
6
  Author: thePmSquare
@@ -32,6 +32,21 @@ pip install square_administration
32
32
 
33
33
  ## changelog
34
34
 
35
+ ### v3.2.0
36
+
37
+ - move global_int_app_id getting logic from configuration.py to utils->common
38
+ - env
39
+ - add DB_IP, DB_PORT, DB_USERNAME, DB_PASSWORD
40
+ - add config.testing.ini
41
+ - file path reading through os.path.join method.
42
+ - testing
43
+ - add conftest file to create and cleanup test database, also to patch config file.
44
+ - update existing tests to use the new fixtures.
45
+
46
+ ### v3.1.1
47
+
48
+ - bump square_logger to 2.0.0
49
+
35
50
  ### v3.1.0
36
51
 
37
52
  - add pytest as dependency.
@@ -10,6 +10,7 @@ square_administration.egg-info/dependency_links.txt
10
10
  square_administration.egg-info/requires.txt
11
11
  square_administration.egg-info/top_level.txt
12
12
  square_administration/data/config.ini
13
+ square_administration/data/config.testing.ini
13
14
  square_administration/pydantic_models/__init__.py
14
15
  square_administration/pydantic_models/authentication.py
15
16
  square_administration/pydantic_models/core.py
@@ -6,7 +6,7 @@ bcrypt>=4.2.0
6
6
  pytest>=8.0.0
7
7
  httpx>=0.27.2
8
8
  square_commons>=1.0.0
9
- square_logger>=1.0.0
9
+ square_logger>=2.0.0
10
10
  square_database_helper>=2.0.0
11
11
  square_database_structure>=1.0.0
12
12
  square_authentication_helper>=2.1.0
@@ -0,0 +1,61 @@
1
+ import os
2
+
3
+ import pytest
4
+ from fastapi.testclient import TestClient
5
+
6
+
7
+ def patched_join(*args):
8
+
9
+ *rest, last = args
10
+ if last == "config.ini":
11
+ last = "config.testing.ini"
12
+
13
+ return original_join(*rest, last)
14
+
15
+
16
+ original_join = os.path.join
17
+
18
+
19
+ @pytest.fixture
20
+ def get_patched_configuration(monkeypatch, tmp_path):
21
+ monkeypatch.setattr(os.path, "join", patched_join)
22
+ import square_administration.configuration
23
+
24
+ return square_administration.configuration
25
+
26
+
27
+ @pytest.fixture
28
+ def create_client_and_cleanup(get_patched_configuration):
29
+ from square_database_structure import create_database_and_tables
30
+
31
+ create_database_and_tables(
32
+ db_username=get_patched_configuration.config_str_db_username,
33
+ db_port=get_patched_configuration.config_int_db_port,
34
+ db_password=get_patched_configuration.config_str_db_password,
35
+ db_ip=get_patched_configuration.config_str_db_ip,
36
+ )
37
+ from square_administration.main import (
38
+ app,
39
+ )
40
+
41
+ client = TestClient(app)
42
+ yield client
43
+ from sqlalchemy import text, create_engine
44
+ from square_database_structure.main import global_list_create
45
+
46
+ local_str_postgres_url = (
47
+ f"postgresql://{get_patched_configuration.config_str_db_username}:{get_patched_configuration.config_str_db_password}@"
48
+ f"{get_patched_configuration.config_str_db_ip}:{str(get_patched_configuration.config_int_db_port)}/"
49
+ )
50
+
51
+ postgres_engine = create_engine(local_str_postgres_url)
52
+
53
+ with postgres_engine.connect() as postgres_connection:
54
+
55
+ postgres_connection.execute(text("commit"))
56
+
57
+ for database in global_list_create:
58
+
59
+ postgres_connection.execute(
60
+ text(f"DROP DATABASE {database['database']} WITH (FORCE)")
61
+ )
@@ -0,0 +1,10 @@
1
+ from square_commons import get_api_output_in_standard_format
2
+
3
+
4
+ def test_read_main(get_patched_configuration, create_client_and_cleanup):
5
+ client = create_client_and_cleanup
6
+ response = client.get("/")
7
+ assert response.status_code == 200
8
+ assert response.json() == get_api_output_in_standard_format(
9
+ log=get_patched_configuration.config_str_module_name
10
+ )
@@ -1,14 +0,0 @@
1
- import os
2
-
3
- from square_administration.configuration import (
4
- config_str_ssl_key_file_path,
5
- config_str_ssl_crt_file_path,
6
- global_object_square_logger,
7
- )
8
-
9
-
10
- @global_object_square_logger.auto_logger
11
- def is_https() -> bool:
12
- return os.path.exists(config_str_ssl_key_file_path) and os.path.exists(
13
- config_str_ssl_crt_file_path
14
- )
@@ -1,11 +0,0 @@
1
- import pytest
2
-
3
-
4
- @pytest.fixture
5
- def set_env(monkeypatch):
6
- monkeypatch.setenv("SQUARE_DATABASE_PROTOCOL", "http")
7
- monkeypatch.setenv("SQUARE_DATABASE_IP", "raspi.thepmsquare.com")
8
- monkeypatch.setenv("SQUARE_DATABASE_PORT", "20010")
9
- monkeypatch.setenv("SQUARE_AUTHENTICATION_PROTOCOL", "http")
10
- monkeypatch.setenv("SQUARE_AUTHENTICATION_IP", "raspi.thepmsquare.com")
11
- monkeypatch.setenv("SQUARE_AUTHENTICATION_PORT", "20011")
@@ -1,16 +0,0 @@
1
- from fastapi.testclient import TestClient
2
- from square_commons import get_api_output_in_standard_format
3
-
4
-
5
- def test_read_main(set_env):
6
- from square_administration.configuration import config_str_module_name
7
- from square_administration.main import (
8
- app,
9
- )
10
-
11
- client = TestClient(app)
12
- response = client.get("/")
13
- assert response.status_code == 200
14
- assert response.json() == get_api_output_in_standard_format(
15
- log=config_str_module_name
16
- )