Skip to content

Commit 701a845

Browse files
Additional doc updates
1 parent ec784ed commit 701a845

File tree

6 files changed

+108
-4
lines changed

6 files changed

+108
-4
lines changed

.vscode/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
"cSpell.words": [
88
"addopts",
99
"codegen",
10+
"customisable",
11+
"customised",
1012
"initialise",
1113
"Licence",
1214
"organisation",

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ This blueprint also provides the following utility classes, that can be used to
7878
|-------|-----------|
7979
|[Axe](./docs/utility-guides/Axe.md)|Accessibility scanning using axe-core.|
8080
|[Date Time Utility](./docs/utility-guides/DateTimeUtility.md)|Basic functionality for managing date/times.|
81-
|NHSNumberTools|Basic tools for working with NHS numbers.|
81+
|[NHSNumberTools](./docs/utility-guides/NHSNumberTools.md)|Basic tools for working with NHS numbers.|
82+
|[User Tools](./docs/utility-guides/UserTools.md)|Basic user management tool.|
8283

8384
## Contributing
8485

docs/getting-started/2_Blueprint_File_Breakdown.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This guide outlines the breakdown of this blueprint, and specifically the files
99
- [Directories \& Files Directly Impacting Tests](#directories--files-directly-impacting-tests)
1010
- [`requirements.txt`](#requirementstxt)
1111
- [`pytest.ini`](#pytestini)
12+
- [`users.json`](#usersjson)
1213
- [`tests/`](#tests)
1314
- [`pages/`](#pages)
1415
- [`utils/`](#utils)
@@ -36,6 +37,11 @@ This file outlines the configuration of pytest, and ultimately how Playwright al
3637

3738
Any configuration you want to apply to all of your test executions should be placed in this file where possible, to ensure easy maintenance.
3839

40+
### `users.json`
41+
42+
This file outlines the users you may want to use as part of your testing, and is utilised by the User Tools utility. Further information on how this file is used
43+
can be found in the [User Tools Utility Guide](../utility-guides/UserTools.md).
44+
3945
### `tests/`
4046

4147
This directory is designed to house all of your tests intended for execution.
@@ -66,3 +72,4 @@ The following directories and files are specific for this repository, and may re
6672
- `scripts/`: This directory houses the scripts used by this repository, primarily as part of the CI/CD checks.
6773
- `tests_utils/`: This directory houses the unit tests for the utilities provided by this repository. You may want to copy these over if you want to ensure utilities are behaving as expected.
6874
- `.editorconfig`, `.gitattributes`, `.gitignore`, `.gitleaks.toml`, `.gitleaksignore`: These files are configuration for git, and quality and security checks provided via the CI/CD checks.
75+
- `Makefile`: This file is used to import some of the scripts for CI/CD checks, but can be customised per project if needed. The template this project is based from provides a more comprehensive example [here](https://github.com/nhs-england-tools/repository-template/blob/main/Makefile).
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Utility Guide: NHS Number Tools
2+
3+
The NHS Number Tools utility provided by this blueprint allows for the easy management of NHS numbers, and provides
4+
common functionality that may apply to many services in relation to NHS Number management.
5+
6+
## Table of Contents
7+
8+
- [Utility Guide: NHS Number Tools](#utility-guide-nhs-number-tools)
9+
- [Table of Contents](#table-of-contents)
10+
- [Using the NHS Number Tools class](#using-the-nhs-number-tools-class)
11+
- [`spaced_nhs_number()`: Return Spaced NHS Number](#spaced_nhs_number-return-spaced-nhs-number)
12+
- [Required Arguments](#required-arguments)
13+
- [Returns](#returns)
14+
15+
## Using the NHS Number Tools class
16+
17+
You can initialise the NHS Number Tools class by using the following code in your test file:
18+
19+
from utils.nhs_number_tools import NHSNumberTools
20+
21+
## `spaced_nhs_number()`: Return Spaced NHS Number
22+
23+
The `spaced_nhs_number()` method is designed to take the provided NHS number and return it in a formatted
24+
string of the format `nnn nnn nnnn`. It's a static method so can be used in the following way:
25+
26+
# Return formatted NHS number
27+
spaced_nhs_number = NHSNumberTools.spaced_nhs_number("1234567890")
28+
29+
### Required Arguments
30+
31+
The following are required for `NHSNumberTools.spaced_nhs_number()`:
32+
33+
| Argument | Format | Description |
34+
| ---------- | -------------- | ------------------------- |
35+
| nhs_number | `str` or `int` | The NHS number to format. |
36+
37+
### Returns
38+
39+
A `str` with the provided NHS number in `nnn nnn nnnn` format. For example, `NHSNumberTools.spaced_nhs_number(1234567890)` would return `123 456 7890`.

docs/utility-guides/UserTools.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ at the base of the repository.
99
- [Table of Contents](#table-of-contents)
1010
- [Using the User Tools class](#using-the-user-tools-class)
1111
- [Managing Users](#managing-users)
12+
- [Considering Security](#considering-security)
13+
- [`retrieve_user()`: Retrieve User Details](#retrieve_user-retrieve-user-details)
14+
- [Required Arguments](#required-arguments)
15+
- [Returns](#returns)
16+
- [Example Usage](#example-usage)
1217

1318
## Using the User Tools class
1419

@@ -32,3 +37,53 @@ For example, adding a record like so (this example shows the entire `users.json`
3237
"unique_id": 42
3338
}
3439
}
40+
41+
The data you require for these users can be completely customised for what information you need, so whilst the example shows `username`, `roles`
42+
and `unique_id` as possible values we may want to use, this is not an exhaustive list. The key that is used (so in this example, `"Documentation User"`)
43+
is also customisable and should be how you want to easily reference retrieving this user in your tests.
44+
45+
### Considering Security
46+
47+
An important note on managing users in this way is that passwords or security credentials should **never** be stored in the `users.json` file. These
48+
are considered secrets, and whilst it may be convenient to store them in this file, it goes against the
49+
[security principles outlined in the Software Engineering Quality Framework](https://github.com/NHSDigital/software-engineering-quality-framework/blob/main/practices/security.md#application-level-security).
50+
51+
With this in mind, it's recommended to do the following when it comes to managing these types of credentials:
52+
53+
- When running locally, store any secret values in a local configuration file and set this file in `.gitignore` so it is not committed to the codebase.
54+
- When running via a CI/CD process, store any secret values in an appropriate secret store and pass the values into pytest at runtime.
55+
56+
## `retrieve_user()`: Retrieve User Details
57+
58+
The `retrieve_user()` method is designed to easily retrieve the data for a specific user entry from the `users.json` file. This is a static method,
59+
so can be called using the following logic:
60+
61+
# Retrieving documentation user details from example
62+
user_details = UserTools.retrieve_user("Documentation User")
63+
64+
### Required Arguments
65+
66+
The following are required for `UserTools.retrieve_user()`:
67+
68+
| Argument | Format | Description |
69+
| -------- | ------ | ------------------------------------------------------- |
70+
| user | `str` | The key from `users.json` for the user details required |
71+
72+
### Returns
73+
74+
A Python `dict` object that contains the values associated with the provided user argument.
75+
76+
### Example Usage
77+
78+
When using a `users.json` file as set up in the example above:
79+
80+
from utils.user_tools import UserTools
81+
from playwright.sync_api import Page
82+
83+
def test_login(page: Page) -> None:
84+
# Retrieving documentation user details from example
85+
user_details = UserTools.retrieve_user("Documentation User")
86+
87+
# Use values to populate a form
88+
page.get_by_role("textbox", name="Username").fill(user_details["username"])
89+
page.get_by_role("textbox", name="ID").fill(user_details["unique_id"])

tests_utils/test_user_tools.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
def test_retrieve_user(monkeypatch: object) -> None:
1010
monkeypatch.setattr(utils.user_tools, "USERS_FILE", Path(__file__).parent / "resources" / "test_users.json")
1111

12-
test_user = UserTools().retrieve_user("Test User")
12+
test_user = UserTools.retrieve_user("Test User")
1313
assert test_user["username"] == "TEST_USER1"
1414
assert test_user["test_key"] == "TEST A"
1515

16-
test_user2 = UserTools().retrieve_user("Test User 2")
16+
test_user2 = UserTools.retrieve_user("Test User 2")
1717
assert test_user2["username"] == "TEST_USER2"
1818
assert test_user2["test_key"] == "TEST B"
1919

2020
with pytest.raises(UserToolsException, match=r'User \[Invalid User\] is not present in users.json'):
21-
UserTools().retrieve_user("Invalid User")
21+
UserTools.retrieve_user("Invalid User")

0 commit comments

Comments
 (0)