Skip to content

Commit 9355742

Browse files
Adding markdown document and docstrings for Load Properties Util
1 parent 52f204b commit 9355742

File tree

2 files changed

+70
-12
lines changed

2 files changed

+70
-12
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Utility Guide: Load Properties
2+
3+
The Load Properties Utility can be used to retrieve values from a properties file.
4+
5+
## Table of Contents
6+
7+
- [Utility Guide: Load Properties](#utility-guide-load-properties)
8+
- [Table of Contents](#table-of-contents)
9+
- [How This Works](#how-this-works)
10+
- [Using the Load Properties Utility](#using-the-load-properties-utility)
11+
- [Example usage](#example-usage)
12+
13+
## How This Works
14+
15+
This util uses the `jproperties` package to load the properties files.<br>
16+
There is a class `PropertiesFile`, containing the locations of both files:
17+
18+
1. `self.smokescreen_properties_file`: tests/smokescreen/bcss_smokescreen_tests.properties
19+
2. `self.general_properties_file`: tests/bcss_tests.properties
20+
21+
The method `get_properties()` will load either one of these based on the input provided.<br>
22+
To ensure that there are no mistakes when providing this input there are two additional methods to call that will do this for you:
23+
24+
1. `get_smokescreen_properties()`: Which will load `self.smokescreen_properties_file`
25+
2. `get_general_properties()`: Which will load `self.general_properties_file`
26+
27+
To add values to the properties file follow the format:
28+
29+
# ----------------------------------
30+
# EXAMPLE VALUES
31+
# ----------------------------------
32+
example_value_1=value1
33+
example_value_2=value2
34+
35+
## Using the Load Properties Utility
36+
37+
To use the this util in a test reference the pytest fixture in `conftest.py`.<br>
38+
There is no need to import anything as any fixtures in `conftest.py` will be automatically discovered by pytest.
39+
Here there are two fixtures:
40+
41+
1. `smokescreen_properties` - which is used to load the file: tests/smokescreen/bcss_smokescreen_tests.properties
42+
2. `get_general_properties` - which is used to load the file: tests/bcss_tests.properties
43+
44+
## Example usage
45+
46+
def test_example_1(page: Page, general_properties: dict) -> None:
47+
print(
48+
general_properties["example_value_1"]
49+
)

utils/load_properties_file.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,44 @@
22
import os
33

44

5-
class PropertiesFile():
5+
class PropertiesFile:
66
def __init__(self):
7-
self.smokescreen_properties_file = "tests/smokescreen/bcss_smokescreen_tests.properties"
7+
self.smokescreen_properties_file = (
8+
"tests/smokescreen/bcss_smokescreen_tests.properties"
9+
)
810
self.general_properties_file = "tests/bcss_tests.properties"
911

10-
1112
def get_properties(self, type_of_properties_file: str | None = None) -> dict:
1213
"""
1314
Reads the 'bcss_smokescreen_tests.properties' file or 'bcss_tests.properties' and populates a 'Properties' object depending on whether "smokescreen" is given
1415
Returns a dictionary of properties for use in tests.
1516
17+
Args:
18+
type_of_properties_file (str): the type of properties file you want to load. E.g. 'smokescreen' or 'general'
19+
1620
Returns:
1721
dict: A dictionary containing the values loaded from the 'bcss_smokescreen_tests.properties' file.
1822
"""
1923
configs = Properties()
20-
path = f"{os.getcwd()}/{self.smokescreen_properties_file if type_of_properties_file == "smokescreen" else self.general_properties_file}"
21-
with open(
22-
path, "rb"
23-
) as read_prop:
24+
path = f"{os.getcwd()}/{self.smokescreen_properties_file if type_of_properties_file == "smokescreen" else self.general_properties_file}"
25+
with open(path, "rb") as read_prop:
2426
configs.load(read_prop)
2527
return configs.properties
2628

27-
2829
def get_smokescreen_properties(self) -> dict:
29-
"This is used to get the `tests/smokescreen/bcss_smokescreen_tests.properties` file"
30-
return self.get_properties("smokescreen")
30+
"""
31+
This is used to get the `tests/smokescreen/bcss_smokescreen_tests.properties` file
3132
33+
Returns:
34+
dict: A dictionary containing the values loaded from the 'bcss_smokescreen_tests.properties' file.
35+
"""
36+
return self.get_properties("smokescreen")
3237

3338
def get_general_properties(self) -> dict:
34-
"This is used to get the `tests/bcss_tests.properties` file"
35-
return self.get_properties()
39+
"""
40+
This is used to get the `tests/bcss_tests.properties` file
3641
42+
Returns:
43+
dict: A dictionary containing the values loaded from the 'bcss_smokescreen_tests.properties' file.
44+
"""
45+
return self.get_properties()

0 commit comments

Comments
 (0)