Skip to content

Commit 4fa396e

Browse files
authored
Merge pull request #81 from itk-dev-rpa/release/2.7.0
Release/2.7.0
2 parents fba30c5 + 268bd6b commit 4fa396e

File tree

6 files changed

+127
-26
lines changed

6 files changed

+127
-26
lines changed

changelog.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [2.7.0] - 2024-09-16
11+
12+
### Added
13+
14+
- Added functionality for approving, checking approval status and noting cases
15+
1016
## [2.6.1] - 2024-09-04
1117

12-
### Fixed - 2024-09-04
18+
### Fixed
1319

1420
- Fixed column number on case_worker
1521

@@ -22,6 +28,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2228
### Changed
2329

2430
- eflyt.eflyt_case.change_tab now checks if the tab needs to be changed before doing it.
31+
- Dependenices are now only locked to major versions.
32+
- Changed test for change sap password to use dotenv.
2533

2634
## [2.5.0] - 2024-08-14
2735

@@ -160,8 +168,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
160168

161169
- Initial release
162170

163-
[Unreleased]: https://github.com/itk-dev-rpa/ITK-dev-shared-components/compare/2.6.1...HEAD
164-
[2.6.0]: https://github.com/itk-dev-rpa/ITK-dev-shared-components/releases/tag/2.6.1
171+
[Unreleased]: https://github.com/itk-dev-rpa/ITK-dev-shared-components/compare/2.7.0...HEAD
172+
[2.7.0]: https://github.com/itk-dev-rpa/ITK-dev-shared-components/releases/tag/2.7.0
173+
[2.6.1]: https://github.com/itk-dev-rpa/ITK-dev-shared-components/releases/tag/2.6.1
165174
[2.6.0]: https://github.com/itk-dev-rpa/ITK-dev-shared-components/releases/tag/2.6.0
166175
[2.5.0]: https://github.com/itk-dev-rpa/ITK-dev-shared-components/releases/tag/2.5.0
167176
[2.4.0]: https://github.com/itk-dev-rpa/ITK-dev-shared-components/releases/tag/2.4.0

itk_dev_shared_components/eflyt/eflyt_case.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from selenium import webdriver
66
from selenium.webdriver.common.by import By
7+
from selenium.webdriver.common.keys import Keys
78

89

910
@dataclass
@@ -126,3 +127,69 @@ def change_tab(browser: webdriver.Chrome, tab_index: int):
126127

127128
if current_index != tab_index:
128129
browser.execute_script(f"__doPostBack('ctl00$ContentPlaceHolder2$ptFanePerson$ImgJournalMap','{tab_index}')")
130+
131+
132+
def approve_case(browser: webdriver.Chrome):
133+
"""Approve a case, even if blocked by a note."""
134+
change_tab(browser, 0)
135+
136+
deadline_field = browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_ncPersonTab_txtDeadline")
137+
deadline_field.clear()
138+
note_field = browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_ncPersonTab_txtDeadlineNote")
139+
note_field.clear()
140+
141+
browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_stcPersonTab1_btnGodkend").click()
142+
browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_stcPersonTab1_btnApproveYes").click()
143+
144+
approve_persons_button = browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_stcPersonTab1_btnGodkendAlle")
145+
if not approve_persons_button.is_enabled():
146+
147+
person_table = browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_GridViewMovingPersons")
148+
rows = person_table.find_elements(By.TAG_NAME, "tr")
149+
rows.pop(0)
150+
151+
for row in rows:
152+
row.find_element(By.XPATH, "td[2]").click()
153+
browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_stcPersonTab1_btnGodkend").click()
154+
approve_button = browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_stcPersonTab1_btnApproveYes")
155+
if approve_button.is_displayed():
156+
approve_button.click()
157+
else:
158+
approve_persons_button.click()
159+
160+
161+
def check_all_approved(browser: webdriver.Chrome) -> bool:
162+
"""Check all inhabiatants in table have a status 'Godkendt'.
163+
"""
164+
person_table = browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_GridViewMovingPersons")
165+
rows = person_table.find_elements(By.TAG_NAME, "tr")
166+
rows.pop(0)
167+
168+
for row in rows:
169+
row_status = row.find_element(By.XPATH, "td[6]").text
170+
if row_status != "Godkendt":
171+
return False
172+
return True
173+
174+
175+
def add_note(browser: webdriver.Chrome, message: str):
176+
"""Add a note to a case."""
177+
message = f"{date.today().strftime('%Y-%m-%d')} Besked fra Robot: {message}"
178+
browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_ncPersonTab_ButtonVisOpdater").click()
179+
180+
existing_note = browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_ncPersonTab_txtVisOpdaterNote").text
181+
if len(existing_note) > 0:
182+
message = "\n\n" + message
183+
browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_ncPersonTab_txtVisOpdaterNote").send_keys(Keys.CONTROL+Keys.END)
184+
185+
browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_ncPersonTab_txtVisOpdaterNote").send_keys(message)
186+
browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_ncPersonTab_btnLongNoteUpdater").click()
187+
188+
189+
def get_note_text(browser: webdriver.Chrome) -> str:
190+
"""Read note text and close the window, returning the value.
191+
"""
192+
browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_ncPersonTab_ButtonVisOpdater").click()
193+
text = browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_ncPersonTab_txtVisOpdaterNote").text
194+
browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_ncPersonTab_btnLuk").click()
195+
return text

pyproject.toml

Lines changed: 6 additions & 6 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.6.1"
7+
version = "2.7.0"
88
authors = [
99
{ name="ITK Development", email="itk-rpa@mkb.aarhus.dk" },
1010
]
@@ -18,11 +18,11 @@ classifiers = [
1818
]
1919
dependencies = [
2020
"pywin32 >= 306",
21-
"msal >= 1.24.1",
22-
"requests >= 2.31.0",
23-
"beautifulsoup4 >= 4.12.2",
24-
"selenium==4.16.0",
25-
"uiautomation == 2.0.18"
21+
"msal == 1.*",
22+
"requests == 2.*",
23+
"beautifulsoup4 == 4.*",
24+
"selenium == 4.*",
25+
"uiautomation == 2.*"
2626
]
2727

2828
[project.urls]

tests/readme.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,15 @@ mailpit --smtp-tls-cert cert.pem --smtp-tls-key key.pem
3838
```
3939

4040
## Environment variables
41-
You need to setup a .env file in the root directory with the following parameters:
4241

42+
You need to setup a .env file in the root directory with the following parameters:
4343

4444
### SAP
4545

4646
SAP_LOGIN = 'login;password'
47+
SAP_NEW_PASSWORD = 'new password'
48+
49+
If SAP_NEW_PASSWORD is not set, the change password test is skipped.
4750

4851
### GRAPH
4952

@@ -74,4 +77,4 @@ CVR_CREDS = 'login;password'
7477
EFLYT_LOGIN = 'username,password'
7578
TEST_CPR = 'XXXXXXXXXX'
7679
TEST_CASE = '123456' # A test case with multiple current inhabitants, with relations registered
77-
TEST_CASE_NOONE = '56789' # A test case without any current inhabitants
80+
TEST_CASE_NOONE = '56789' # A test case without any current inhabitants

tests/test_eflyt/test_case.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
from dotenv import load_dotenv
88
from selenium.webdriver.common.by import By
99

10-
from itk_dev_shared_components.eflyt.eflyt_login import login
11-
from itk_dev_shared_components.eflyt.eflyt_search import open_case
12-
from itk_dev_shared_components.eflyt import eflyt_case
10+
from itk_dev_shared_components.eflyt import eflyt_case, eflyt_login, eflyt_search
1311

1412
load_dotenv()
1513

@@ -21,12 +19,12 @@ class CaseTest(unittest.TestCase):
2119
def setUpClass(cls):
2220
"""Setup test class"""
2321
eflyt_credentials = os.getenv("EFLYT_LOGIN").split(",")
24-
cls.browser = login(eflyt_credentials[0], eflyt_credentials[1])
22+
cls.browser = eflyt_login.login(eflyt_credentials[0], eflyt_credentials[1])
2523

2624
def setUp(self):
2725
"""Go to a clean case state"""
2826
test_case = os.getenv("TEST_CASE")
29-
open_case(self.browser, test_case)
27+
eflyt_search.open_case(self.browser, test_case)
3028

3129
def test_get_beboere(self):
3230
"""Test inhabitant functions"""
@@ -44,7 +42,7 @@ def test_get_beboere(self):
4442
for relation in inhabitant.relations:
4543
self.assertRegex(relation, r"\d{6}-\d{4}")
4644

47-
open_case(self.browser, test_no_inhabitants_case)
45+
eflyt_search.open_case(self.browser, test_no_inhabitants_case)
4846
inhabitants = eflyt_case.get_beboere(self.browser)
4947

5048
self.assertEqual(len(inhabitants), 0, "Some inhabitants found when none was expected")
@@ -74,6 +72,30 @@ def test_get_room_count(self):
7472
self.assertIsInstance(room_count, int, "Room count is not a number")
7573
self.assertGreater(room_count, 0, "Room count is less than 1")
7674

75+
def test_write_note(self):
76+
"""Test writing a note to a case. Check if the note is added and that the existing note is preserved.
77+
"""
78+
existing_note = eflyt_case.get_note_text(self.browser)
79+
80+
note_text = "Test"
81+
eflyt_case.add_note(self.browser, note_text)
82+
83+
new_note = eflyt_case.get_note_text(self.browser)
84+
85+
# Reset note to original text
86+
self.browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_ncPersonTab_ButtonVisOpdater").click()
87+
self.browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_ncPersonTab_txtVisOpdaterNote").clear()
88+
self.browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_ncPersonTab_txtVisOpdaterNote").send_keys(existing_note)
89+
self.browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_ncPersonTab_btnLongNoteUpdater").click()
90+
91+
self.assertNotEqual(existing_note, new_note)
92+
self.assertEqual(existing_note, new_note[:len(existing_note)])
93+
self.assertEqual(note_text, new_note[-len(note_text):])
94+
95+
@unittest.skip("No test system available for approving dummy cases.")
96+
def test_approve_case(self):
97+
"""Empty test for approve_case"""
98+
7799

78100
if __name__ == '__main__':
79101
unittest.main()

tests/test_sap/test_sap_login.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import os
44
import unittest
5-
from tkinter import simpledialog
65

76
from dotenv import load_dotenv, set_key
87

@@ -20,7 +19,6 @@ def setUpClass(cls) -> None:
2019
used in the following tests.
2120
"""
2221
cls.username, cls.password = os.environ['SAP_LOGIN'].split(';')
23-
cls.new_password = simpledialog.askstring("Enter new password", "Enter the new password to be used in testing the change SAP password function.\nRemember to write down the new password!\nLeave empty to skip test_change_password.")
2422

2523
def setUp(self) -> None:
2624
sap_login.kill_sap()
@@ -44,17 +42,19 @@ def test_change_password(self):
4442
Due to a limit in SAP you can only run this function once per day.
4543
If no new_password is entered in the setup, test is skipped.
4644
"""
47-
if not self.new_password:
48-
raise unittest.SkipTest("Test not run because new_password was missing.")
45+
new_password = os.getenv('SAP_NEW_PASSWORD')
46+
if not new_password:
47+
raise unittest.SkipTest("Test skipped because SAP_NEW_PASSWORD was missing.")
48+
49+
sap_login.change_password(self.username, self.password, new_password)
4950

50-
sap_login.change_password(self.username, self.password, self.new_password)
5151
# Change password for all coming tests
52-
self.password = self.new_password
53-
os.environ['SAP_LOGIN'] = f"{self.username};{self.password}"
54-
set_key(".env", 'SAP_LOGIN', self.password)
52+
self.password = new_password
53+
set_key(".env", 'SAP_LOGIN', f"{self.username};{self.password}")
54+
set_key(".env", 'SAP_NEW_PASSWORD', '')
5555

5656
with self.assertRaises(ValueError):
57-
sap_login.change_password(self.username, "Foo", self.new_password)
57+
sap_login.change_password(self.username, "Foo", new_password)
5858

5959
with self.assertRaises(ValueError):
6060
sap_login.change_password(self.username, self.password, "")

0 commit comments

Comments
 (0)