Skip to content

Commit ec784ed

Browse files
updates
1 parent b9b9493 commit ec784ed

File tree

5 files changed

+60
-5
lines changed

5 files changed

+60
-5
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"cSpell.words": [
88
"addopts",
99
"codegen",
10+
"initialise",
1011
"Licence",
1112
"organisation",
1213
"pytest",

docs/utility-guides/UserTools.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Utility Guide: User Tools
2+
3+
The User Tools utility provided by this blueprint allows for the easy management of test users via a json file included
4+
at the base of the repository.
5+
6+
## Table of Contents
7+
8+
- [Utility Guide: User Tools](#utility-guide-user-tools)
9+
- [Table of Contents](#table-of-contents)
10+
- [Using the User Tools class](#using-the-user-tools-class)
11+
- [Managing Users](#managing-users)
12+
13+
## Using the User Tools class
14+
15+
You can initialise the User Tools class by using the following code in your test file:
16+
17+
from utils.user_tools import UserTools
18+
19+
This module has been designed as a static class, so you do not need to instantiate it when you want to retrieve any user information.
20+
21+
## Managing Users
22+
23+
For this class, users are managed via the [users.json](../../users.json) file provided with this repository. For any new users you need to
24+
add, the idea is to just add a new record, with any appropriate metadata you need for the user whilst they interact with your application.
25+
26+
For example, adding a record like so (this example shows the entire `users.json` file):
27+
28+
{
29+
"Documentation User": {
30+
"username": "DOC_USER",
31+
"roles": ["Example Role A"],
32+
"unique_id": 42
33+
}
34+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"Test User": {
3+
"username": "TEST_USER1",
4+
"test_key": "TEST A"
5+
},
6+
"Test User 2": {
7+
"username": "TEST_USER2",
8+
"test_key": "TEST B"
9+
}
10+
}

tests_utils/test_nhs_number_tools.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,3 @@ def test_nhs_number_checks() -> None:
1616
def test_spaced_nhs_number() -> None:
1717
assert NHSNumberTools.spaced_nhs_number("1234567890") == "123 456 7890"
1818
assert NHSNumberTools.spaced_nhs_number(3216549870) == "321 654 9870"
19-
20-
if __name__ == "__main__":
21-
retcode = pytest.main(["-m", "utils"])

tests_utils/test_user_tools.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
import pytest
2+
import utils.user_tools
23
from utils.user_tools import UserTools, UserToolsException
4+
from pathlib import Path
35

46

57
pytestmark = [pytest.mark.utils]
68

7-
def test_nhs_number_checks() -> None:
8-
assert UserTools().retrieve_user("Example User 1")
9+
def test_retrieve_user(monkeypatch: object) -> None:
10+
monkeypatch.setattr(utils.user_tools, "USERS_FILE", Path(__file__).parent / "resources" / "test_users.json")
11+
12+
test_user = UserTools().retrieve_user("Test User")
13+
assert test_user["username"] == "TEST_USER1"
14+
assert test_user["test_key"] == "TEST A"
15+
16+
test_user2 = UserTools().retrieve_user("Test User 2")
17+
assert test_user2["username"] == "TEST_USER2"
18+
assert test_user2["test_key"] == "TEST B"
19+
20+
with pytest.raises(UserToolsException, match=r'User \[Invalid User\] is not present in users.json'):
21+
UserTools().retrieve_user("Invalid User")

0 commit comments

Comments
 (0)