orionis 0.421.0__py3-none-any.whl → 0.423.0__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.
@@ -1,6 +1,6 @@
1
1
  from enum import Enum
2
2
 
3
- class EnvCastType(Enum):
3
+ class EnvironmentValueType(Enum):
4
4
  """
5
5
  Enum representing supported environment variable cast types.
6
6
 
@@ -31,12 +31,13 @@ class EnvCastType(Enum):
31
31
  An enumeration member representing the desired cast type.
32
32
  """
33
33
 
34
- PATH = 'path' # Represents a file system path
35
- STR = 'str' # Represents a string type
36
- INT = 'int' # Represents an integer type
37
- FLOAT = 'float' # Represents a floating-point type
38
- BOOL = 'bool' # Represents a boolean type
39
- LIST = 'list' # Represents a list type
40
- DICT = 'dict' # Represents a dictionary type
41
- TUPLE = 'tuple' # Represents a tuple type
42
- SET = 'set' # Represents a set type
34
+ BASE64 = 'base64' # Represents a base64 encoded type
35
+ PATH = 'path' # Represents a file system path
36
+ STR = 'str' # Represents a string type
37
+ INT = 'int' # Represents an integer type
38
+ FLOAT = 'float' # Represents a floating-point type
39
+ BOOL = 'bool' # Represents a boolean type
40
+ LIST = 'list' # Represents a list type
41
+ DICT = 'dict' # Represents a dictionary type
42
+ TUPLE = 'tuple' # Represents a tuple type
43
+ SET = 'set' # Represents a set type
@@ -1,5 +1,4 @@
1
1
  import os
2
- import base64
3
2
 
4
3
  class SecureKeyGenerator:
5
4
  """
@@ -14,24 +13,17 @@ class SecureKeyGenerator:
14
13
  @staticmethod
15
14
  def generate() -> str:
16
15
  """
17
- Generates a secure random key and encodes it in base64 format.
16
+ Generates a cryptographically secure random key and encodes it in hexadecimal format.
18
17
 
19
- This method creates a cryptographically secure random key of 32 bytes,
20
- encodes it using base64 encoding, and returns the result as a string
21
- prefixed with 'base64:'.
18
+ This method uses the operating system's cryptographic random number generator to
19
+ produce a 32-byte random value, which is then encoded as a hexadecimal string.
22
20
 
23
21
  Returns
24
22
  -------
25
23
  str
26
- A string in the format 'base64:<key>', where <key> is a base64-encoded
27
- representation of a securely generated 32-byte random key.
24
+ A 64-character hexadecimal string representing a 32-byte secure random key.
28
25
  """
29
26
 
30
- # Generate 32 bytes of cryptographically secure random data
31
- key = os.urandom(32)
32
-
33
- # Encode the random bytes using base64 and decode to a UTF-8 string
34
- encoded = base64.b64encode(key).decode('utf-8')
35
-
36
- # Return the key in the required format
37
- return f"base64:{encoded}"
27
+ # Generate 32 random bytes using a cryptographically secure RNG
28
+ # Encode the bytes as a hexadecimal string and return
29
+ return os.urandom(32).hex()
@@ -1,11 +1,11 @@
1
1
  import re
2
- from typing import Any, Union
3
- from orionis.services.environment.enums.cast_type import EnvCastType
2
+ from typing import Union
3
+ from orionis.services.environment.enums.value_type import EnvironmentValueType
4
4
  from orionis.services.environment.exceptions.value import OrionisEnvironmentValueError
5
5
 
6
6
  class __ValidateTypes:
7
7
 
8
- def __call__(self, value: Union[str, int, float, bool, list, dict, tuple, set], type_hint: str | EnvCastType = None) -> str:
8
+ def __call__(self, value: Union[str, int, float, bool, list, dict, tuple, set], type_hint: str | EnvironmentValueType = None) -> str:
9
9
 
10
10
  # Ensure the value is a valid type.
11
11
  if not isinstance(value, (str, int, float, bool, list, dict, tuple, set)):
@@ -14,23 +14,23 @@ class __ValidateTypes:
14
14
  )
15
15
 
16
16
  # If a type hint is provided, ensure it is valid.
17
- if type_hint and not isinstance(type_hint, (str, EnvCastType)):
17
+ if type_hint and not isinstance(type_hint, (str, EnvironmentValueType)):
18
18
  raise OrionisEnvironmentValueError(
19
- f"Type hint must be a string or EnvCastType, got {type(type_hint).__name__}."
19
+ f"Type hint must be a string or EnvironmentValueType, got {type(type_hint).__name__}."
20
20
  )
21
21
 
22
- # If type_hint is provided, convert it to a string if it's an EnvCastType.
22
+ # If type_hint is provided, convert it to a string if it's an EnvironmentValueType.
23
23
  if type_hint:
24
24
 
25
- # If type_hint is a string, convert it to EnvCastType if valid.
25
+ # If type_hint is a string, convert it to EnvironmentValueType if valid.
26
26
  if isinstance(type_hint, str):
27
27
  try:
28
- type_hint = EnvCastType[type_hint.upper()].value
28
+ type_hint = EnvironmentValueType[type_hint.upper()].value
29
29
  except KeyError:
30
30
  raise OrionisEnvironmentValueError(
31
- f"Invalid type hint: {type_hint}. Allowed types are {[e.value for e in EnvCastType]}"
31
+ f"Invalid type hint: {type_hint}. Allowed types are: {[e.value for e in EnvironmentValueType]}"
32
32
  )
33
- elif isinstance(type_hint, EnvCastType):
33
+ elif isinstance(type_hint, EnvironmentValueType):
34
34
  type_hint = type_hint.value
35
35
 
36
36
  # If no type hint is provided, use the type of the value.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: orionis
3
- Version: 0.421.0
3
+ Version: 0.423.0
4
4
  Summary: Orionis Framework – Elegant, Fast, and Powerful.
5
5
  Home-page: https://github.com/orionis-framework/framework
6
6
  Author: Raul Mauricio Uñate Castro
@@ -1,5 +1,3 @@
1
- environment/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- environment/test_services_environment.py,sha256=6UH3g2Z2DQYtGnyySCRnT35VCENlL-PQWHIdH6zA9rw,3767
3
1
  orionis/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
2
  orionis/_console/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
3
  orionis/_console/command_filter.py,sha256=bn0fcWfQg13DrQBaV4NopNxdP-6up0G54Qmhg7r_BKA,1211
@@ -187,7 +185,7 @@ orionis/foundation/providers/progress_bar_provider.py,sha256=WW3grNgH-yV2meSSTeO
187
185
  orionis/foundation/providers/testing_provider.py,sha256=iJSN2RIChbYIL-1ue6vmPmDMCSrvERDkti4Er9MPiLA,1102
188
186
  orionis/foundation/providers/workers_provider.py,sha256=kiQjQRyUEyiBX2zcbF_KmqRgvc7Bvxsvg5oMtIvYniM,1075
189
187
  orionis/metadata/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
190
- orionis/metadata/framework.py,sha256=Z_k5Op43n9NO2-4Tg4QDG9HjX9NK-Yi1CzWhnvOpkPg,4960
188
+ orionis/metadata/framework.py,sha256=4ObKf3_80JdUtm-5cIFr9tho1b7Xi1akA-66eblfV6g,4960
191
189
  orionis/metadata/package.py,sha256=tqLfBRo-w1j_GN4xvzUNFyweWYFS-qhSgAEc-AmCH1M,5452
192
190
  orionis/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
193
191
  orionis/services/asynchrony/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -199,26 +197,24 @@ orionis/services/asynchrony/exceptions/exception.py,sha256=yAVsjZ2lLAoFgNIiMcOtC
199
197
  orionis/services/environment/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
200
198
  orionis/services/environment/env.py,sha256=vKx9zO2DpUK089fL17qxQ4X4tLYzN3exGAKg3d-rp3c,2272
201
199
  orionis/services/environment/contracts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
200
+ orionis/services/environment/contracts/caster.py,sha256=f5OsgsUCu-cqjmfWF6fqyKmXocHZGIjZgXw7F7g05yw,1211
202
201
  orionis/services/environment/contracts/env.py,sha256=7lezGxABAG63pEEvzAmHXgr9izBI6TCp05Trx_SRvc4,2054
203
- orionis/services/environment/contracts/types.py,sha256=n0USxUblz0Ofbo1ef0hnGHGkuGjSiWk-SBWVPXv33mE,1994
204
202
  orionis/services/environment/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
205
- orionis/services/environment/core/dot_env.py,sha256=Dgkmy0juaFKZPEkv7nN7VvdYryX8fDs0JgRGOIHj7PM,10090
203
+ orionis/services/environment/core/dot_env.py,sha256=1371GV5mxkBH4iPFHccBz9V-6JoZZfy_hSukqJWQjdE,14278
206
204
  orionis/services/environment/dynamic/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
207
- orionis/services/environment/dynamic/types.py,sha256=nf7HJjm-1S-BH2YnuBQNNWvb3Aqu-QYPUTfJRgVYZ1Y,18336
205
+ orionis/services/environment/dynamic/caster.py,sha256=8j1yVcOhdS3WTTgzc19CzmxZFWyY6vRVGT__76mU5JI,35040
208
206
  orionis/services/environment/enums/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
209
- orionis/services/environment/enums/cast_type.py,sha256=hoZhljXHNn03VYbg6VTauGyppmcoRjaepylrOKSBvu8,1217
207
+ orionis/services/environment/enums/value_type.py,sha256=C-JQGGz1GtdoggKG-rBykUm9lUTS2JmU232D8lWTB2Q,1302
210
208
  orionis/services/environment/exceptions/__init__.py,sha256=YwLc8GsB0swlwu9T9Qt2vevaCoq5V2vmPUSlEUAqg2Q,199
211
209
  orionis/services/environment/exceptions/exception.py,sha256=NnxWmgoSca7LXi7GLDa95HSBPKotFfy8u729d1OAmCc,479
212
210
  orionis/services/environment/exceptions/value.py,sha256=Pe1qNHRrM9T0AzESN284CzA3GQYxzokfXPMOVqOTlyQ,475
213
211
  orionis/services/environment/helpers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
214
212
  orionis/services/environment/helpers/functions.py,sha256=MtlDTA1W8KVJu0cohh4TsuPg8CPcnySf36cp9E9tpJI,595
215
213
  orionis/services/environment/key/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
216
- orionis/services/environment/key/key_generator.py,sha256=BHvcFiPOmJHQotstMNkUdoEwb0mNxQk5iyvQU3JlJ94,1134
217
- orionis/services/environment/serializer/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
218
- orionis/services/environment/serializer/values.py,sha256=ERnQWgCAljhJ9pRSd-knnGD5i6ne5Ho-4bh93pgDtwY,364
214
+ orionis/services/environment/key/key_generator.py,sha256=uFHOPH0YtYU_vEG7Oc3a51O15QxZl1USD_KlYcS9SsQ,912
219
215
  orionis/services/environment/validators/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
220
216
  orionis/services/environment/validators/key_name.py,sha256=heMQoMY4vF9sIYAlET7noTQz383daGPvJnJOb62nxFo,1577
221
- orionis/services/environment/validators/types.py,sha256=AQvIZzBWxZ6-iJhzRkroim5CKBvWq2lTttRyXzc-6GU,1922
217
+ orionis/services/environment/validators/types.py,sha256=t3G-JlJz1jDcYKrS7iljBL2q3m-KpmcCFBGoQIhRtK0,2000
222
218
  orionis/services/introspection/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
223
219
  orionis/services/introspection/reflection.py,sha256=_Wdy8Wtt3RKXAqg9o5rvYa_Hyu-Z4674LKnNVg7u7pU,11467
224
220
  orionis/services/introspection/abstract/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -357,7 +353,7 @@ orionis/test/validators/web_report.py,sha256=-h3Fe9jY93_kzUhd2NBIqEfCcBpu-8Ei9x3
357
353
  orionis/test/validators/workers.py,sha256=LGffDKtK6SKixFKzIYPQpI5aFeQPAGXpv_LUtmEu6g4,1102
358
354
  orionis/test/view/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
359
355
  orionis/test/view/render.py,sha256=3ICz68l-WF3BtnYqH5m-ktN9UD00MELMbmMnyJDV74A,4768
360
- orionis-0.421.0.dist-info/licenses/LICENCE,sha256=-_4cF2EBKuYVS_SQpy1uapq0oJPUU1vl_RUWSy2jJTo,1111
356
+ orionis-0.423.0.dist-info/licenses/LICENCE,sha256=-_4cF2EBKuYVS_SQpy1uapq0oJPUU1vl_RUWSy2jJTo,1111
361
357
  tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
362
358
  tests/container/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
363
359
  tests/container/test_container.py,sha256=asv8TkkupVoex6SWod74NBl4dSs7wb9mLmu_glNdNy8,14815
@@ -389,6 +385,8 @@ tests/container/validators/test_is_not_subclass.py,sha256=1OCPtCRuysm7OKL6XhuXJP
389
385
  tests/container/validators/test_is_subclass.py,sha256=0Uc8uIR69ZX7G5Nrex0LMQXrueTdncdDxfQoila3h3U,5834
390
386
  tests/container/validators/test_is_valid_alias.py,sha256=egVf6IfSXurIdu8hKo03rwsM1P-bxGOFd1_9JjDHJIk,5657
391
387
  tests/container/validators/test_lifetime.py,sha256=5PequjXAcIcp0Q4TIki7THSU31XftGpI0u1mVGqHmpU,4692
388
+ tests/environment/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
389
+ tests/environment/test_services_environment.py,sha256=Xf61PQJHgZSmDuASwWZBuoVnB353cibClyo9_EC3X0k,9567
392
390
  tests/example/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
393
391
  tests/example/test_example.py,sha256=XJEcsro3vCO5m4zvMiWUGphvd0C7oIkBtUfQgTDsdUU,25568
394
392
  tests/foundation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -500,8 +498,8 @@ tests/testing/validators/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZ
500
498
  tests/testing/validators/test_testing_validators.py,sha256=QdcF0Vhnnl_kD-PzceHJbUYOqwPTB1Td7YaTv8LTr30,19612
501
499
  tests/testing/view/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
502
500
  tests/testing/view/test_render.py,sha256=-ghGG8rimyb2b2wtvMuSPPH7Zac5_NlVCiUcHRA5SNg,1172
503
- orionis-0.421.0.dist-info/METADATA,sha256=LuYV7Rv2dQBgwy1Ztkz-8mlxiodXlvEPpSJmEw8Gzx0,4772
504
- orionis-0.421.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
505
- orionis-0.421.0.dist-info/top_level.txt,sha256=0G1WIo0HbkZ6hNbKp6cdXLoKj1SfULEORhCuPIV_Dqw,26
506
- orionis-0.421.0.dist-info/zip-safe,sha256=frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN_XKdLCPjaYaY,2
507
- orionis-0.421.0.dist-info/RECORD,,
501
+ orionis-0.423.0.dist-info/METADATA,sha256=sCWDt2p6GoLQ8lvYWZvDwnfDE6ipPB1GC2Ae9L2t7wE,4772
502
+ orionis-0.423.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
503
+ orionis-0.423.0.dist-info/top_level.txt,sha256=2bdoHgyGZhOtLAXS6Om8OCTmL24dUMC_L1quMe_ETbk,14
504
+ orionis-0.423.0.dist-info/zip-safe,sha256=frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN_XKdLCPjaYaY,2
505
+ orionis-0.423.0.dist-info/RECORD,,
@@ -1,3 +1,2 @@
1
- environment
2
1
  orionis
3
2
  tests
@@ -0,0 +1,227 @@
1
+ from pathlib import Path
2
+ from orionis.services.environment.env import Env
3
+ from orionis.test.cases.asynchronous import AsyncTestCase
4
+ import os
5
+ from orionis.services.environment.core.dot_env import DotEnv
6
+ from orionis.services.environment.enums.value_type import EnvironmentValueType
7
+ from orionis.services.environment.core.dot_env import DotEnv
8
+
9
+ class TestServicesEnvironment(AsyncTestCase):
10
+
11
+ async def testSetAndGetConstants(self):
12
+ """
13
+ Stores and retrieves framework metadata constants using Env.set and Env.get.
14
+
15
+ This test imports several metadata constants from the `orionis.metadata.framework` module,
16
+ sets each constant in the Env storage using `Env.set`, and verifies that the operation succeeds.
17
+ It then retrieves each constant using `Env.get` and asserts that the retrieved value matches
18
+ the original constant.
19
+
20
+ Parameters
21
+ ----------
22
+ self : TestServicesEnvironment
23
+ The test case instance.
24
+
25
+ Returns
26
+ -------
27
+ None
28
+ This method does not return a value. Assertions are used to validate behavior.
29
+
30
+ Notes
31
+ -----
32
+ - Ensures that `Env.set` returns True for each constant.
33
+ - Ensures that `Env.get` returns the correct value for each constant.
34
+ """
35
+ from orionis.metadata.framework import (
36
+ NAME, VERSION, AUTHOR, AUTHOR_EMAIL, DESCRIPTION,
37
+ SKELETON, FRAMEWORK, DOCS, API, PYTHON_REQUIRES
38
+ )
39
+
40
+ # Prepare a dictionary of constant names and their values
41
+ constants = {
42
+ "NAME": NAME,
43
+ "VERSION": VERSION,
44
+ "AUTHOR": AUTHOR,
45
+ "AUTHOR_EMAIL": AUTHOR_EMAIL,
46
+ "DESCRIPTION": DESCRIPTION,
47
+ "SKELETON": SKELETON,
48
+ "FRAMEWORK": FRAMEWORK,
49
+ "DOCS": DOCS,
50
+ "API": API,
51
+ "PYTHON_REQUIRES": PYTHON_REQUIRES
52
+ }
53
+
54
+ # Set each constant in the environment and assert the operation succeeds
55
+ for key, value in constants.items():
56
+ result = Env.set(key, value)
57
+ self.assertTrue(result)
58
+
59
+ # Retrieve each constant and assert the value matches the original
60
+ for key, value in constants.items():
61
+ retrieved = Env.get(key)
62
+ self.assertEqual(retrieved, value)
63
+
64
+ async def testGetNonExistentKey(self):
65
+ """
66
+ Test the behavior of `Env.get` when retrieving a non-existent environment key.
67
+
68
+ This test verifies that attempting to retrieve a value for a key that has not been set
69
+ in the environment returns `None`. This ensures that the environment behaves as expected
70
+ when queried for missing keys.
71
+
72
+ Parameters
73
+ ----------
74
+ self : TestServicesEnvironment
75
+ The test case instance.
76
+
77
+ Returns
78
+ -------
79
+ None
80
+ This method does not return a value. Assertions are used to validate that `Env.get`
81
+ returns `None` for a non-existent key.
82
+
83
+ Notes
84
+ -----
85
+ - Ensures that `Env.get` returns `None` when the specified key does not exist in the environment.
86
+ """
87
+
88
+ # Attempt to retrieve a value for a key that has not been set.
89
+ self.assertIsNone(Env.get("NON_EXISTENT_KEY"))
90
+
91
+ async def testDotEnvSetAndGetWithType(self):
92
+ """
93
+ Test DotEnv.set and DotEnv.get with explicit EnvironmentValueType for various data types.
94
+
95
+ This test verifies that the `DotEnv` class correctly stores and retrieves environment variables
96
+ when an explicit `EnvironmentValueType` is provided. For each supported data type, the test sets
97
+ a value using `DotEnv.set` with the corresponding `EnvironmentValueType`, then retrieves it using
98
+ `DotEnv.get` and asserts that the returned value is correctly prefixed or formatted according to
99
+ the specified type.
100
+
101
+ Parameters
102
+ ----------
103
+ self : TestServicesEnvironment
104
+ The test case instance.
105
+
106
+ Returns
107
+ -------
108
+ None
109
+ This method does not return a value. Assertions are used to validate the correct behavior
110
+ of `DotEnv.set` and `DotEnv.get` with explicit type information.
111
+
112
+ Notes
113
+ -----
114
+ - Ensures that values are stored and retrieved with the correct type prefixes or formatting.
115
+ - Covers all supported types: PATH, STR, INT, FLOAT, BOOL, LIST, DICT, TUPLE, SET, BASE64.
116
+ """
117
+
118
+ env = DotEnv()
119
+
120
+ # Set and assert a PATH value with explicit type
121
+ env.set("CAST_EXAMPLE_PATH", '/tests', EnvironmentValueType.PATH)
122
+ self.assertEqual(env.get("CAST_EXAMPLE_PATH"), Path(Path.cwd(), 'tests'))
123
+
124
+ # Set and assert a string value with explicit type
125
+ env.set("CAST_EXAMPLE_STR", 'hello', EnvironmentValueType.STR)
126
+ self.assertEqual(env.get("CAST_EXAMPLE_STR"), "hello")
127
+
128
+ # Set and assert an integer value with explicit type
129
+ env.set("CAST_EXAMPLE_INT", 123, EnvironmentValueType.INT)
130
+ self.assertEqual(env.get("CAST_EXAMPLE_INT"), 123)
131
+
132
+ # Set and assert a float value with explicit type
133
+ env.set("CAST_EXAMPLE_FLOAT", 3.14, EnvironmentValueType.FLOAT)
134
+ self.assertEqual(env.get("CAST_EXAMPLE_FLOAT"), 3.14)
135
+
136
+ # Set and assert a boolean value with explicit type
137
+ env.set("CAST_EXAMPLE_BOOL", True, EnvironmentValueType.BOOL)
138
+ self.assertEqual(env.get("CAST_EXAMPLE_BOOL"), True)
139
+
140
+ # Set and assert a list value with explicit type
141
+ env.set("CAST_EXAMPLE_LIST", [1, 2, 3], EnvironmentValueType.LIST)
142
+ self.assertEqual(env.get("CAST_EXAMPLE_LIST"), [1, 2, 3])
143
+
144
+ # Set and assert a dictionary value with explicit type
145
+ env.set("CAST_EXAMPLE_DICT", {"a": 1, "b": 2}, EnvironmentValueType.DICT)
146
+ self.assertEqual(env.get("CAST_EXAMPLE_DICT"), {"a": 1, "b": 2})
147
+
148
+ # Set and assert a tuple value with explicit type
149
+ env.set("CAST_EXAMPLE_TUPLE", (1, 2), EnvironmentValueType.TUPLE)
150
+ self.assertEqual(env.get("CAST_EXAMPLE_TUPLE"), (1, 2))
151
+
152
+ # Set and assert a set value with explicit type
153
+ env.set("CAST_EXAMPLE_SET", {1, 2, 3}, EnvironmentValueType.SET)
154
+ self.assertEqual(env.get("CAST_EXAMPLE_SET"), {1, 2, 3})
155
+
156
+ # Set and assert a base64 value with explicit type
157
+ ramdon_text = os.urandom(32).hex()
158
+ env.set("CAST_EXAMPLE_BASE64", ramdon_text, EnvironmentValueType.BASE64)
159
+ self.assertEqual(env.get("CAST_EXAMPLE_BASE64"), ramdon_text)
160
+
161
+ async def testDotEnvSetAndGetWithoutType(self):
162
+ """
163
+ Test DotEnv.set and DotEnv.get without explicit EnvironmentValueType for various data types.
164
+
165
+ This test verifies that the `DotEnv` class can store and retrieve environment variables of different
166
+ Python data types without specifying an explicit `EnvironmentValueType`. It checks that the values
167
+ are stored and retrieved as their string representations, and asserts the correctness of the returned
168
+ values for each data type.
169
+
170
+ Parameters
171
+ ----------
172
+ self : TestServicesEnvironment
173
+ The test case instance.
174
+
175
+ Returns
176
+ -------
177
+ None
178
+ This method does not return a value. Assertions are used to validate that the returned values
179
+ from `DotEnv.get` match the expected string representations for each data type.
180
+
181
+ Notes
182
+ -----
183
+ - Ensures that values are stored and retrieved as strings when no explicit type is provided.
184
+ - Covers various data types: path, str, int, float, bool, list, dict, tuple, set, and base64.
185
+ """
186
+
187
+ env = DotEnv()
188
+
189
+ # Set and get a path value without explicit type
190
+ env.set("EXAMPLE_PATH", '/tests')
191
+ self.assertEqual(env.get("EXAMPLE_PATH"), '/tests')
192
+
193
+ # Set and get a string value without explicit type
194
+ env.set("EXAMPLE_STR", 'hello')
195
+ self.assertEqual(env.get("EXAMPLE_STR"), 'hello')
196
+
197
+ # Set and get an integer value without explicit type
198
+ env.set("EXAMPLE_INT", 123)
199
+ self.assertEqual(env.get("EXAMPLE_INT"), 123)
200
+
201
+ # Set and get a float value without explicit type
202
+ env.set("EXAMPLE_FLOAT", 3.14)
203
+ self.assertEqual(env.get("EXAMPLE_FLOAT"), 3.14)
204
+
205
+ # Set and get a boolean value without explicit type
206
+ env.set("EXAMPLE_BOOL", True)
207
+ self.assertEqual(env.get("EXAMPLE_BOOL"), True)
208
+
209
+ # Set and get a list value without explicit type
210
+ env.set("EXAMPLE_LIST", [1, 2, 3])
211
+ self.assertEqual(env.get("EXAMPLE_LIST"), [1, 2, 3])
212
+
213
+ # Set and get a dictionary value without explicit type
214
+ env.set("EXAMPLE_DICT", {"a": 1, "b": 2})
215
+ self.assertEqual(env.get("EXAMPLE_DICT"), {"a": 1, "b": 2})
216
+
217
+ # Set and get a tuple value without explicit type
218
+ env.set("EXAMPLE_TUPLE", (1, 2))
219
+ self.assertEqual(env.get("EXAMPLE_TUPLE"), (1, 2))
220
+
221
+ # Set and get a set value without explicit type
222
+ env.set("EXAMPLE_SET", {1, 2, 3})
223
+ self.assertEqual(env.get("EXAMPLE_SET"), {1, 2, 3})
224
+
225
+ # Set and get a base64 value without explicit type
226
+ env.set("EXAMPLE_BASE64", "T3Jpb25pcyBGcmFtZXdvcms=")
227
+ self.assertEqual(env.get("EXAMPLE_BASE64"), 'T3Jpb25pcyBGcmFtZXdvcms=')
@@ -1,93 +0,0 @@
1
- from orionis.services.environment.env import Env
2
- from orionis.test.cases.asynchronous import AsyncTestCase
3
-
4
- class TestServicesEnvironment(AsyncTestCase):
5
-
6
- async def testSetAndGetConstants(self):
7
- """
8
- Test storing and retrieving framework metadata constants using Env.set and Env.get.
9
-
10
- Imports several metadata constants from the `orionis.metadata.framework` module, sets each constant
11
- in the Env storage using `Env.set`, and verifies that the operation succeeds. Then retrieves each
12
- constant using `Env.get` and asserts that the retrieved value matches the original constant.
13
-
14
- Ensures
15
- -------
16
- - `Env.set` returns True for each constant.
17
- - `Env.get` returns the correct value for each constant.
18
- """
19
- from orionis.metadata.framework import (
20
- NAME, VERSION, AUTHOR, AUTHOR_EMAIL, DESCRIPTION,
21
- SKELETON, FRAMEWORK, DOCS, API, PYTHON_REQUIRES
22
- )
23
- constants = {
24
- "NAME": NAME,
25
- "VERSION": VERSION,
26
- "AUTHOR": AUTHOR,
27
- "AUTHOR_EMAIL": AUTHOR_EMAIL,
28
- "DESCRIPTION": DESCRIPTION,
29
- "SKELETON": SKELETON,
30
- "FRAMEWORK": FRAMEWORK,
31
- "DOCS": DOCS,
32
- "API": API,
33
- "PYTHON_REQUIRES": PYTHON_REQUIRES
34
- }
35
- for key, value in constants.items():
36
- result = Env.set(key, value)
37
- self.assertTrue(result)
38
- for key, value in constants.items():
39
- retrieved = Env.get(key)
40
- self.assertEqual(retrieved, value)
41
-
42
- async def testGetNonExistentKey(self):
43
- """
44
- Test that Env.get returns None for a non-existent environment key.
45
-
46
- Ensures
47
- -------
48
- - `Env.get` returns None when the key does not exist.
49
- """
50
- self.assertIsNone(Env.get("NON_EXISTENT_KEY"))
51
-
52
- async def testTypeHints(self):
53
- """
54
- Test that Env.set and Env.get correctly handle and preserve Python type hints.
55
-
56
- Sets environment variables with various data types (int, float, bool, str, list, dict, tuple, set)
57
- using the `Env.set` method, specifying the type as a string. Then retrieves each variable using
58
- `Env.get` and asserts that the returned value is of the expected Python type.
59
-
60
- Ensures
61
- -------
62
- - The returned value from `Env.get` matches the expected Python type for each variable.
63
- """
64
-
65
- # Set environment variables with type hints
66
- Env.set("TEST_INT", 42, 'int')
67
- Env.set("TEST_FLOAT", 3.14, 'float')
68
- Env.set("TEST_BOOL", True, 'bool')
69
- Env.set("TEST_STR", "Hello, World!", 'str')
70
- Env.set("TEST_LIST", [1, 2, 3], 'list')
71
- Env.set("TEST_DICT", {"key": "value"}, 'dict')
72
- Env.set("TEST_TUPLE", (1,2,3), 'tuple')
73
- Env.set("TEST_SET", {1, 2, 3}, 'set')
74
-
75
- # Retrieve and check types
76
- self.assertIsInstance(Env.get("TEST_INT"), int)
77
- self.assertIsInstance(Env.get("TEST_FLOAT"), float)
78
- self.assertIsInstance(Env.get("TEST_BOOL"), bool)
79
- self.assertIsInstance(Env.get("TEST_STR"), str)
80
- self.assertIsInstance(Env.get("TEST_LIST"), list)
81
- self.assertIsInstance(Env.get("TEST_DICT"), dict)
82
- self.assertIsInstance(Env.get("TEST_TUPLE"), tuple)
83
- self.assertIsInstance(Env.get("TEST_SET"), set)
84
-
85
- # Clean up environment variables after test
86
- Env.unset("TEST_INT")
87
- Env.unset("TEST_FLOAT")
88
- Env.unset("TEST_BOOL")
89
- Env.unset("TEST_STR")
90
- Env.unset("TEST_LIST")
91
- Env.unset("TEST_DICT")
92
- Env.unset("TEST_TUPLE")
93
- Env.unset("TEST_SET")