square-administration 3.1.0__py3-none-any.whl → 3.2.1__py3-none-any.whl

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.
@@ -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
 
@@ -31,6 +23,9 @@ try:
31
23
  # environment
32
24
  config_str_host_ip = ldict_configuration["ENVIRONMENT"]["HOST_IP"]
33
25
  config_int_host_port = int(ldict_configuration["ENVIRONMENT"]["HOST_PORT"])
26
+ config_list_allow_origins = eval(
27
+ ldict_configuration["ENVIRONMENT"]["ALLOW_ORIGINS"]
28
+ )
34
29
  config_str_log_file_name = ldict_configuration["ENVIRONMENT"]["LOG_FILE_NAME"]
35
30
  config_str_admin_password_hash = ldict_configuration["ENVIRONMENT"][
36
31
  "ADMIN_PASSWORD_HASH"
@@ -43,6 +38,10 @@ try:
43
38
  "SSL_KEY_FILE_PATH"
44
39
  ]
45
40
  config_str_cookie_domain = ldict_configuration["ENVIRONMENT"]["COOKIE_DOMAIN"]
41
+ config_str_db_ip = ldict_configuration["ENVIRONMENT"]["DB_IP"]
42
+ config_int_db_port = int(ldict_configuration["ENVIRONMENT"]["DB_PORT"])
43
+ config_str_db_username = ldict_configuration["ENVIRONMENT"]["DB_USERNAME"]
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"
@@ -5,6 +5,7 @@ APP_NAME = square_admin
5
5
  [ENVIRONMENT]
6
6
  HOST_IP = 0.0.0.0
7
7
  HOST_PORT = 10111
8
+ ALLOW_ORIGINS = ["http://localhost:10111"]
8
9
 
9
10
  LOG_FILE_NAME = square_administration
10
11
 
@@ -16,6 +17,11 @@ SSL_KEY_FILE_PATH = ssl.key
16
17
 
17
18
  COOKIE_DOMAIN = localhost
18
19
 
20
+ DB_IP = localhost
21
+ DB_PORT = 10001
22
+ DB_USERNAME = postgres
23
+ DB_PASSWORD = dummy
24
+
19
25
  [SQUARE_LOGGER]
20
26
 
21
27
  # | Log Level | Value |
@@ -0,0 +1,54 @@
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
+ ALLOW_ORIGINS = ["http://localhost:10111"]
9
+
10
+ LOG_FILE_NAME = square_administration
11
+
12
+ ADMIN_PASSWORD_HASH = $2b$12$tDw4ZR0guiF5s5oVve5PcuELhlWO.lUH.OChPoeWVn95ac7QJlndq
13
+
14
+ # absolute path (mandatory only for http)
15
+ SSL_CRT_FILE_PATH = ssl.crt
16
+ SSL_KEY_FILE_PATH = ssl.key
17
+
18
+ COOKIE_DOMAIN = localhost
19
+
20
+ DB_IP = raspi.thepmsquare.com
21
+ DB_PORT = 15432
22
+ DB_USERNAME = postgres
23
+ DB_PASSWORD = testing_password
24
+
25
+
26
+ [SQUARE_LOGGER]
27
+
28
+ # | Log Level | Value |
29
+ # | --------- | ----- |
30
+ # | CRITICAL | 50 |
31
+ # | ERROR | 40 |
32
+ # | WARNING | 30 |
33
+ # | INFO | 20 |
34
+ # | DEBUG | 10 |
35
+ # | NOTSET | 0 |
36
+
37
+ LOG_LEVEL = 20
38
+ # absolute or relative path
39
+ LOG_PATH = logs
40
+ # number of backup log files to keep during rotation
41
+ # if backupCount is zero, rollover never occurs.
42
+ LOG_BACKUP_COUNT = 3
43
+
44
+ [SQUARE_DATABASE_HELPER]
45
+
46
+ SQUARE_DATABASE_PROTOCOL = http
47
+ SQUARE_DATABASE_IP = raspi.thepmsquare.com
48
+ SQUARE_DATABASE_PORT = 20010
49
+
50
+ [SQUARE_AUTHENTICATION_HELPER]
51
+
52
+ SQUARE_AUTHENTICATION_PROTOCOL = http
53
+ SQUARE_AUTHENTICATION_IP = raspi.thepmsquare.com
54
+ SQUARE_AUTHENTICATION_PORT = 20011
@@ -11,6 +11,7 @@ from square_administration.configuration import (
11
11
  config_str_module_name,
12
12
  config_str_ssl_key_file_path,
13
13
  config_str_ssl_crt_file_path,
14
+ config_list_allow_origins,
14
15
  )
15
16
  from square_administration.routes import core, authentication
16
17
  from square_administration.utils.common import is_https
@@ -20,7 +21,7 @@ app = FastAPI()
20
21
  app.add_middleware(
21
22
  CORSMiddleware,
22
23
  allow_credentials=True,
23
- allow_origins=["*"],
24
+ allow_origins=config_list_allow_origins,
24
25
  allow_methods=["*"],
25
26
  allow_headers=["*"],
26
27
  )
@@ -30,7 +31,7 @@ app.include_router(authentication.router)
30
31
 
31
32
 
32
33
  @app.get("/")
33
- @global_object_square_logger.async_auto_logger
34
+ @global_object_square_logger.auto_logger()
34
35
  async def root():
35
36
  output_content = get_api_output_in_standard_format(log=config_str_module_name)
36
37
  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
  ):
@@ -1,14 +1,36 @@
1
1
  import os
2
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
+
3
9
  from square_administration.configuration import (
4
10
  config_str_ssl_key_file_path,
5
11
  config_str_ssl_crt_file_path,
6
12
  global_object_square_logger,
13
+ global_object_square_database_helper,
14
+ config_str_app_name,
7
15
  )
8
16
 
9
17
 
10
- @global_object_square_logger.auto_logger
18
+ @global_object_square_logger.auto_logger()
11
19
  def is_https() -> bool:
12
20
  return os.path.exists(config_str_ssl_key_file_path) and os.path.exists(
13
21
  config_str_ssl_crt_file_path
14
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.1
4
4
  Summary: common business layer for my personal server.
5
5
  Home-page: https://github.com/thepmsquare/square_administration
6
6
  Author: thePmSquare
@@ -21,7 +21,7 @@ Requires-Dist: bcrypt>=4.2.0
21
21
  Requires-Dist: pytest>=8.0.0
22
22
  Requires-Dist: httpx>=0.27.2
23
23
  Requires-Dist: square-commons>=1.0.0
24
- Requires-Dist: square-logger>=1.0.0
24
+ Requires-Dist: square-logger>=2.0.0
25
25
  Requires-Dist: square-database-helper>=2.0.0
26
26
  Requires-Dist: square-database-structure>=1.0.0
27
27
  Requires-Dist: square-authentication-helper>=2.1.0
@@ -44,6 +44,28 @@ pip install square_administration
44
44
 
45
45
  ## changelog
46
46
 
47
+ ### v3.2.1
48
+
49
+ - testing
50
+ - update get_patched_configuration and create_client_and_cleanup to be session scoped.
51
+ - env
52
+ - add ALLOW_ORIGINS
53
+
54
+ ### v3.2.0
55
+
56
+ - move global_int_app_id getting logic from configuration.py to utils->common
57
+ - env
58
+ - add DB_IP, DB_PORT, DB_USERNAME, DB_PASSWORD
59
+ - add config.testing.ini
60
+ - file path reading through os.path.join method.
61
+ - testing
62
+ - add conftest file to create and cleanup test database, also to patch config file.
63
+ - update existing tests to use the new fixtures.
64
+
65
+ ### v3.1.1
66
+
67
+ - bump square_logger to 2.0.0
68
+
47
69
  ### v3.1.0
48
70
 
49
71
  - add pytest as dependency.
@@ -0,0 +1,21 @@
1
+ square_administration/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ square_administration/configuration.py,sha256=kP2zfEvt-knzrzFIeINI1kz7260eXz_DbNjIjakByEY,4433
3
+ square_administration/main.py,sha256=vvKBMn4JkDp8B2L_zwBMIfYaSA41rXxhL3ZFsSv8ly8,1660
4
+ square_administration/messages.py,sha256=VYjJGW0Kvtjrx1Mw7ekksLVMoxcexLol2OckvqhZ3n0,1063
5
+ square_administration/data/config.ini,sha256=kkSbjJP7qR8ah44Oyv2IyCgYfmheYYh4zSU7wD7v3ec,1145
6
+ square_administration/data/config.testing.ini,sha256=vdW01yJdCqdI6uK-jXHfWa9B9IJVuecYdx0n3y7dS2k,1193
7
+ square_administration/pydantic_models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
+ square_administration/pydantic_models/authentication.py,sha256=QEfM5ezG45hc_qATXpFIPNPl4bjf8ICW_bY5tY4cqO4,259
9
+ square_administration/pydantic_models/core.py,sha256=HUMrBmfKrXeL-126gE5j2povdVmktn8XLg2tHEdeXTk,344
10
+ square_administration/routes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
+ square_administration/routes/authentication.py,sha256=-1B82WgFr78_p2Udq0WbOwD3jcgjK8jXHI7KvhtfuJA,16029
12
+ square_administration/routes/core.py,sha256=H5pfPuPDzSn8-HN40gyI7eDVxFW7821urYq0ceI_TDo,5271
13
+ square_administration/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
+ square_administration/utils/common.py,sha256=bnyBF10EDMLIYXnfV3ZZOApNKScHRmw-Jcj2zIFE8kE,1157
15
+ tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
+ tests/conftest.py,sha256=Lu7qQkrnSeV1WKlN0zVyNLLXRf3Sv8ghPlIWAByv1NQ,1921
17
+ tests/test_1.py,sha256=hikxL01-2dcax594y8ceanjRmLJXvuhLpcY-FMPIdY8,378
18
+ square_administration-3.2.1.dist-info/METADATA,sha256=NzJek8yM3W4b1tqj7kRkXvXxc7-HhWnvmcZN6PQQLQM,3011
19
+ square_administration-3.2.1.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
20
+ square_administration-3.2.1.dist-info/top_level.txt,sha256=tyroqpdXXQAiA7Y_V1wCqPPt6nnS_orcY9txLeHjm1s,28
21
+ square_administration-3.2.1.dist-info/RECORD,,
tests/conftest.py CHANGED
@@ -1,11 +1,65 @@
1
+ import importlib
2
+ import os
3
+
1
4
  import pytest
5
+ from fastapi.testclient import TestClient
6
+
7
+
8
+ @pytest.fixture(scope="session")
9
+ def get_patched_configuration():
10
+ def patched_join(*args):
11
+ *rest, last = args
12
+ if last == "config.ini":
13
+ last = "config.testing.ini"
14
+
15
+ return original_join(*rest, last)
16
+
17
+ original_join = os.path.join
18
+ os.path.join = patched_join
19
+
20
+ import square_administration.configuration
21
+
22
+ importlib.reload(square_administration.configuration)
23
+ config = square_administration.configuration
24
+
25
+ yield config
26
+
27
+ # cleanup
28
+ os.path.join = original_join
29
+
30
+
31
+ @pytest.fixture(scope="session")
32
+ def create_client_and_cleanup(get_patched_configuration):
33
+ from square_database_structure import create_database_and_tables
34
+
35
+ create_database_and_tables(
36
+ db_username=get_patched_configuration.config_str_db_username,
37
+ db_port=get_patched_configuration.config_int_db_port,
38
+ db_password=get_patched_configuration.config_str_db_password,
39
+ db_ip=get_patched_configuration.config_str_db_ip,
40
+ )
41
+ from square_administration.main import (
42
+ app,
43
+ )
44
+
45
+ client = TestClient(app)
46
+ yield client
47
+ from sqlalchemy import text, create_engine
48
+ from square_database_structure.main import global_list_create
49
+
50
+ local_str_postgres_url = (
51
+ f"postgresql://{get_patched_configuration.config_str_db_username}:{get_patched_configuration.config_str_db_password}@"
52
+ f"{get_patched_configuration.config_str_db_ip}:{str(get_patched_configuration.config_int_db_port)}/"
53
+ )
54
+
55
+ postgres_engine = create_engine(local_str_postgres_url)
56
+
57
+ with postgres_engine.connect() as postgres_connection:
58
+
59
+ postgres_connection.execute(text("commit"))
2
60
 
61
+ for database in global_list_create:
3
62
 
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")
63
+ postgres_connection.execute(
64
+ text(f"DROP DATABASE {database['database']} WITH (FORCE)")
65
+ )
tests/test_1.py CHANGED
@@ -1,16 +1,10 @@
1
- from fastapi.testclient import TestClient
2
1
  from square_commons import get_api_output_in_standard_format
3
2
 
4
3
 
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)
4
+ def test_read_main(get_patched_configuration, create_client_and_cleanup):
5
+ client = create_client_and_cleanup
12
6
  response = client.get("/")
13
7
  assert response.status_code == 200
14
8
  assert response.json() == get_api_output_in_standard_format(
15
- log=config_str_module_name
9
+ log=get_patched_configuration.config_str_module_name
16
10
  )
@@ -1,20 +0,0 @@
1
- square_administration/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- square_administration/configuration.py,sha256=k4ZxGB-RBvHLWQ5ksv-fj0UfAXJ25bSNu5uLNn_rnVc,4816
3
- square_administration/main.py,sha256=YHala3fQjbj4wQuIzCWEZ3xeeVsidPLHabCUsADr4tE,1613
4
- square_administration/messages.py,sha256=VYjJGW0Kvtjrx1Mw7ekksLVMoxcexLol2OckvqhZ3n0,1063
5
- square_administration/data/config.ini,sha256=sTWBnaNGXqLi0Ckk2cNzBC7pqrlboyU_ClLl04luOZY,1024
6
- square_administration/pydantic_models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
- square_administration/pydantic_models/authentication.py,sha256=QEfM5ezG45hc_qATXpFIPNPl4bjf8ICW_bY5tY4cqO4,259
8
- square_administration/pydantic_models/core.py,sha256=HUMrBmfKrXeL-126gE5j2povdVmktn8XLg2tHEdeXTk,344
9
- square_administration/routes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
- square_administration/routes/authentication.py,sha256=vOkuAmnPkTl-PSDmSkyui2tvhFxvo0WzMAAuz3st-QY,16053
11
- square_administration/routes/core.py,sha256=lKI1yAZG4LYKk-Z0pgdFwKW3wSl0ArziTylEKvp4DD0,5233
12
- square_administration/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
- square_administration/utils/common.py,sha256=Uk2clDugVI8U6-bgjs77fxC4DuqmJEJ_IznBs1jAtWc,350
14
- tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
- tests/conftest.py,sha256=WU4jzo4E6M0E2U-DkrnUAwlW8G54DmNS4KydLceDhiU,446
16
- tests/test_1.py,sha256=TKBO9xomDrIGJMKoBQsPK6TrJtAZp9aYv-d-SQNzgPA,479
17
- square_administration-3.1.0.dist-info/METADATA,sha256=b8vram0yxkRiAGxCxRmHTcuD-al-SIWadZ0-CoQNOww,2443
18
- square_administration-3.1.0.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
19
- square_administration-3.1.0.dist-info/top_level.txt,sha256=tyroqpdXXQAiA7Y_V1wCqPPt6nnS_orcY9txLeHjm1s,28
20
- square_administration-3.1.0.dist-info/RECORD,,