Skip to content

Commit afb0e23

Browse files
Adding markdown document and docstrings for Load Properties Util (#53)
<!-- markdownlint-disable-next-line first-line-heading --> ## Description <!-- Describe your changes in detail. --> Updating docstrings for the load properties util to be inline with the contribution guidelines. Creating a markdown doc for this util to explain how it works. ## Context <!-- Why is this change required? What problem does it solve? --> Ensuring the code follows the contribution guidelines. ## Type of changes <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply. --> - [x] Refactoring (non-breaking change) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would change existing functionality) - [ ] Bug fix (non-breaking change which fixes an issue) ## Checklist <!-- Go over all the following points, and put an `x` in all the boxes that apply. --> - [x] I am familiar with the [contributing guidelines](https://github.com/nhs-england-tools/playwright-python-blueprint/blob/main/CONTRIBUTING.md) - [x] I have followed the code style of the project - [ ] I have added tests to cover my changes (where appropriate) - [x] I have updated the documentation accordingly - [ ] This PR is a result of pair or mob programming --- ## Sensitive Information Declaration To ensure the utmost confidentiality and protect your and others privacy, we kindly ask you to NOT including [PII (Personal Identifiable Information) / PID (Personal Identifiable Data)](https://digital.nhs.uk/data-and-information/keeping-data-safe-and-benefitting-the-public) or any other sensitive data in this PR (Pull Request) and the codebase changes. We will remove any PR that do contain any sensitive information. We really appreciate your cooperation in this matter. - [x] I confirm that neither PII/PID nor sensitive data are included in this PR and the codebase changes.
1 parent 52f204b commit afb0e23

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 utility 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 this utility 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)