Skip to content

Commit 43d2ebc

Browse files
authored
Merge pull request #57 from itk-dev-rpa/2.4.0
2.4.0
2 parents 6303442 + 0fb05e9 commit 43d2ebc

File tree

22 files changed

+284
-69
lines changed

22 files changed

+284
-69
lines changed

.github/workflows/Linting.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ jobs:
1919
- name: Install dependencies
2020
run: |
2121
python -m pip install --upgrade pip
22-
pip install pylint
23-
pip install flake8
2422
pip install .
23+
pip install .[dev]
2524
2625
- name: Analyzing the code with pylint
2726
run: |

changelog.md

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,30 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
89
## [Unreleased]
910

11+
### Added
12+
13+
### Changed
14+
15+
## [2.4.0] - 2024-07-30
16+
17+
### Added
18+
19+
- Caseworker for notes
20+
- Directions for setting up environment variables for test
21+
- misc.file_util: Wait for download function.
22+
23+
### Changed
24+
25+
- Changed environmental variables to use an .env file
26+
27+
### Fixed
28+
- Some SAP tests were failing due to a missing value
29+
- Changed department and security units from rules to user control
30+
- Minor doc fixes to get_drive_item.
31+
1032
## [2.3.0] - 2024-07-03
1133

1234
### Added
@@ -114,14 +136,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
114136

115137
- Initial release
116138

117-
[Unreleased] https://github.com/itk-dev-rpa/ITK-dev-shared-components/compare/2.3.0...HEAD
118-
[2.3.0] https://github.com/itk-dev-rpa/ITK-dev-shared-components/releases/tag/2.3.0
119-
[2.2.0] https://github.com/itk-dev-rpa/ITK-dev-shared-components/releases/tag/2.2.0
120-
[2.1.1] https://github.com/itk-dev-rpa/ITK-dev-shared-components/releases/tag/2.1.1
121-
[2.1.0] https://github.com/itk-dev-rpa/ITK-dev-shared-components/releases/tag/2.1.0
122-
[2.0.0] https://github.com/itk-dev-rpa/ITK-dev-shared-components/releases/tag/2.0.0
123-
[1.3.1] https://github.com/itk-dev-rpa/ITK-dev-shared-components/releases/tag/1.3.1
124-
[1.3.0] https://github.com/itk-dev-rpa/ITK-dev-shared-components/releases/tag/1.3.0
125-
[1.2.0] https://github.com/itk-dev-rpa/ITK-dev-shared-components/releases/tag/1.2.0
126-
[1.1.0] https://github.com/itk-dev-rpa/ITK-dev-shared-components/releases/tag/1.1.0
127-
[1.0.0] https://github.com/itk-dev-rpa/ITK-dev-shared-components/releases/tag/1.0.0
139+
[Unreleased]: https://github.com/itk-dev-rpa/ITK-dev-shared-components/compare/2.4.0...HEAD
140+
[2.4.0]: https://github.com/itk-dev-rpa/ITK-dev-shared-components/releases/tag/2.4.0
141+
[2.3.0]: https://github.com/itk-dev-rpa/ITK-dev-shared-components/releases/tag/2.3.0
142+
[2.2.0]: https://github.com/itk-dev-rpa/ITK-dev-shared-components/releases/tag/2.2.0
143+
[2.1.1]: https://github.com/itk-dev-rpa/ITK-dev-shared-components/releases/tag/2.1.1
144+
[2.1.0]: https://github.com/itk-dev-rpa/ITK-dev-shared-components/releases/tag/2.1.0
145+
[2.0.0]: https://github.com/itk-dev-rpa/ITK-dev-shared-components/releases/tag/2.0.0
146+
[1.3.1]: https://github.com/itk-dev-rpa/ITK-dev-shared-components/releases/tag/1.3.1
147+
[1.3.0]: https://github.com/itk-dev-rpa/ITK-dev-shared-components/releases/tag/1.3.0
148+
[1.2.0]: https://github.com/itk-dev-rpa/ITK-dev-shared-components/releases/tag/1.2.0
149+
[1.1.0]: https://github.com/itk-dev-rpa/ITK-dev-shared-components/releases/tag/1.1.0
150+
[1.0.0]: https://github.com/itk-dev-rpa/ITK-dev-shared-components/releases/tag/1.0.0

itk_dev_shared_components/graph/file.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class DriveItem:
1616
last_modified: str
1717

1818

19-
def get_drive_item(graph_access: GraphAccess, site_id: str, drive_item_path: str) -> str:
19+
def get_drive_item(graph_access: GraphAccess, site_id: str, drive_item_path: str) -> DriveItem:
2020
"""Given a site id and a drive_item_path, gets the corresponding DriveItem
2121
2222
You need to authorize against Graph to get the GraphAccess before using this function
@@ -28,7 +28,11 @@ def get_drive_item(graph_access: GraphAccess, site_id: str, drive_item_path: str
2828
graph_access: The GraphAccess object used to authenticate.
2929
site_id: The id of the site in SharePoint.
3030
drive_item_path: The path to the DriveItem in SharePoint.
31+
32+
Returns:
33+
DriveItem: A DriveItem object.
3134
"""
35+
3236
endpoint = f"https://graph.microsoft.com/v1.0/sites/{site_id}/drive/root:/{drive_item_path}"
3337
response = get_request(endpoint, graph_access)
3438
raw_response = response.json()

itk_dev_shared_components/kmd_nova/nova_cases.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,8 @@ def add_case(case: NovaCase, nova_access: NovaAccess):
338338
}
339339
},
340340
"SensitivityCtrlBy": "Bruger",
341-
"SecurityUnitCtrlBy": "Regler",
342-
"ResponsibleDepartmentCtrlBy": "Regler",
341+
"SecurityUnitCtrlBy": "Bruger",
342+
"ResponsibleDepartmentCtrlBy": "Bruger",
343343
"caseAvailability": {
344344
"unit": "År",
345345
"scale": 5

itk_dev_shared_components/kmd_nova/nova_notes.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
import requests
99

1010
from itk_dev_shared_components.kmd_nova.authentication import NovaAccess
11-
from itk_dev_shared_components.kmd_nova.nova_objects import JournalNote
11+
from itk_dev_shared_components.kmd_nova.nova_objects import JournalNote, Caseworker
1212

1313

14-
def add_text_note(case_uuid: str, note_title: str, note_text: str, approved: bool, nova_access: NovaAccess) -> str:
14+
def add_text_note(case_uuid: str, note_title: str, note_text: str, caseworker: Caseworker, approved: bool, nova_access: NovaAccess) -> str:
1515
"""Add a text based journal note to a Nova case.
1616
1717
Args:
@@ -40,6 +40,13 @@ def add_text_note(case_uuid: str, note_title: str, note_text: str, approved: boo
4040
"approved": approved,
4141
"journalNoteAttributes": {
4242
"journalNoteDate": datetime.today().isoformat(),
43+
"journalNoteAuthor": caseworker.ident,
44+
"author": {
45+
"kspIdentity": {
46+
"racfId": caseworker.ident,
47+
"fullName": caseworker.name
48+
}
49+
},
4350
"title": note_title,
4451
"journalNoteType": "Bruger",
4552
"format": "Text",
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""This module contains helper functions to do with handling files."""
2+
3+
import os
4+
import time
5+
6+
7+
def wait_for_download(folder: str, file_name: str | None, file_extension: str, timeout: int = 10) -> str:
8+
"""Wait for a file to appear in a folder.
9+
This checks the folder every second for the file.
10+
11+
Args:
12+
folder: The absolute path of the folder to monitor.
13+
file_name: The name of the file if know else None
14+
file_extension: The file extension of the file with the dot.
15+
timeout: The number of seconds to wait for the file.
16+
17+
Returns:
18+
The absolute path to the file.
19+
20+
Raises:
21+
TimeoutError: If the file didn't appear withing the given timeout.
22+
"""
23+
for _ in range(timeout):
24+
files = os.listdir(folder)
25+
for file in files:
26+
name, ext = os.path.splitext(file)
27+
28+
if file_extension == ext and (file_name is None or file_name == name):
29+
return os.path.join(folder, file)
30+
31+
time.sleep(1)
32+
33+
raise TimeoutError(f"Downloaded file didn't appear within {timeout} seconds.")

pyproject.toml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "itk_dev_shared_components"
7-
version = "2.3.0"
7+
version = "2.4.0"
88
authors = [
99
{ name="ITK Development", email="itk-rpa@mkb.aarhus.dk" },
1010
]
@@ -20,9 +20,16 @@ dependencies = [
2020
"pywin32 >= 306",
2121
"msal >= 1.24.1",
2222
"requests >= 2.31.0",
23-
"beautifulsoup4 >= 4.12.2"
23+
"beautifulsoup4 >= 4.12.2",
2424
]
2525

2626
[project.urls]
2727
"Homepage" = "https://github.com/itk-dev-rpa/itk-dev-shared-components"
2828
"Bug Tracker" = "https://github.com/itk-dev-rpa/itk-dev-shared-components/issues"
29+
30+
[project.optional-dependencies]
31+
dev = [
32+
"python-dotenv",
33+
"flake8",
34+
"pylint"
35+
]

tests/readme.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,26 @@ This bat file sets up a new virtual environment and installs the package before
77

88
Alternatively you can run each test file separately by simply running them as Python scripts.
99

10+
## Environment variables
11+
You need to setup a .env file in the root directory with the following parameters:
12+
13+
GRAPH_API = '{"client_id":"something", "tenant_id":"something", "username":"something", "password":"something"}'
14+
SAP_LOGIN = 'login;password'
15+
16+
MAIL_USER = "test@email.dk"
17+
MAIL_FOLDER1 = "Indbakke/Graph Test/Undermappe"
18+
MAIL_FOLDER2 = "Indbakke/Graph Test/Undermappe2"
19+
20+
NOVA_PARTY = '6101009805,Test Test'
21+
NOVA_DEPARTMENT = '{"id": 818485,"name": "Borgerservice","user_key": "4BBORGER"}'
22+
NOVA_CREDENTIALS = 'nova_login,nova_password'
23+
NOVA_USER = '{"name": "svcitkopeno svcitkopeno", "ident": "AZX0080", "uuid": "0bacdddd-5c61-4676-9a61-b01a18cec1d5"}'
24+
25+
NOVA_CVR_CASE = '{"cvr": "55133018", "case_title": "rpa_testcase", "case_number": "S2024-25614"}'
26+
NOVA_CPR_CASE = '{"cpr": "6101009805", "case_title": "Meget_Unik_Case_Overskrift", "case_number": "S2023-61078"}'
27+
28+
Note: The NOVA_CVR_CASE and NOVA_CPR_CASE variables require cases to be created in Nova, and the parameters set from those cases.
29+
1030
## SMTP
1131

1232
For testing SMTP you need [Mailpit](https://mailpit.axllent.org/) running on localhost.

tests/run_tests.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ if errorlevel 2 (
1818

1919
echo Installing package...
2020
pip install .
21+
pip install .[dev]
2122
)
2223

2324
echo Running unit tests...

tests/test_graph/test_mail.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,19 @@
44
import json
55
import os
66

7+
from dotenv import load_dotenv
8+
79
from itk_dev_shared_components.graph import authentication, mail
810

11+
load_dotenv()
12+
913

1014
class EmailTest(unittest.TestCase):
1115
"""Tests relating to the graph.mail module."""
1216
@classmethod
1317
def setUpClass(cls) -> None:
1418
# Get Graph credentials from the environment variables.
15-
credentials = json.loads(os.environ['GraphAPI'])
19+
credentials = json.loads(os.environ['GRAPH_API'])
1620
client_id = credentials['client_id']
1721
tenant_id = credentials['tenant_id']
1822
username = credentials['username']
@@ -21,9 +25,9 @@ def setUpClass(cls) -> None:
2125
cls.graph_access = authentication.authorize_by_username_password(username, password, tenant_id=tenant_id, client_id=client_id)
2226

2327
# Define mail user and folders
24-
cls.user = "itk-rpa@mkb.aarhus.dk"
25-
cls.folder1 = "Indbakke/Graph Test/Undermappe"
26-
cls.folder2 = "Indbakke/Graph Test/Undermappe2"
28+
cls.user = os.environ['MAIL_USER']
29+
cls.folder1 = os.environ['MAIL_FOLDER1']
30+
cls.folder2 = os.environ['MAIL_FOLDER2']
2731

2832
def test_correct_usage(self):
2933
"""Test all functions relating to the mail part of Graph.

0 commit comments

Comments
 (0)