Skip to content

Commit 1c7fd29

Browse files
authored
Merge pull request #103 from itk-dev-rpa/hotfix/eflyt_read_cases
Eflyt case search now handles list of cases without a deadline
2 parents 98dd2f5 + 06e4743 commit 1c7fd29

File tree

3 files changed

+50
-29
lines changed

3 files changed

+50
-29
lines changed

changelog.md

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

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- Eflyt case search now handles list of cases without a deadline
13+
1014
## [2.11.0] - 2025-03-24
1115

1216
### Changed

itk_dev_shared_components/eflyt/eflyt_search.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,33 +58,33 @@ def extract_cases(browser: webdriver.Chrome) -> list[Case]:
5858
"""
5959
table = browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_GridViewSearchResult")
6060
rows = table.find_elements(By.TAG_NAME, "tr")
61+
headlines = rows[0].text.split(" ")
62+
6163
# Remove header row
6264
rows.pop(0)
6365
cases = []
6466
for row in rows:
65-
deadline = row.find_element(By.XPATH, "td[3]/a").text
66-
67-
# Convert deadline to date object
68-
if deadline:
69-
deadline = datetime.strptime(deadline, "%d-%m-%Y")
70-
else:
71-
deadline = None
67+
deadline = None
68+
if "Deadline" in headlines:
69+
deadline_text = row.find_element(By.XPATH, f"td[{headlines.index('Deadline') + 1}]/a").text
70+
# Convert deadline to date object
71+
if len(deadline_text) > 0:
72+
deadline = datetime.strptime(deadline_text, "%d-%m-%Y")
7273

73-
case_number = row.find_element(By.XPATH, "td[4]").text
74-
case_types_text = row.find_element(By.XPATH, "td[5]").text
74+
case_number = row.find_element(By.XPATH, f"td[{headlines.index('Sagsnr.') + 1}]").text
75+
case_types_text = row.find_element(By.XPATH, f"td[{headlines.index('Flyttetype') + 1}]").text
7576

7677
# If the case types ends with '...' we need to get the title instead
7778
if case_types_text.endswith("..."):
78-
case_types_text = row.find_element(By.XPATH, "td[5]").get_attribute("Title")
79+
case_types_text = row.find_element(By.XPATH, f"td[{headlines.index('Flyttetype') + 1}]").get_attribute("Title")
7980
case_types = case_types_text.split(", ")
8081

81-
status = row.find_element(By.XPATH, "td[6]").text
82-
cpr = row.find_element(By.XPATH, "td[7]/a").text
83-
name = row.find_element(By.XPATH, "td[8]").text
84-
case_worker = row.find_element(By.XPATH, "td[10]").text
82+
status = row.find_element(By.XPATH, f"td[{headlines.index('Status') + 1}]").text
83+
cpr = row.find_element(By.XPATH, f"td[{headlines.index('CPR-nr.') + 1}]/a").text
84+
name = row.find_element(By.XPATH, f"td[{headlines.index('Navn') + 1}]").text
85+
case_worker = row.find_element(By.XPATH, f"td[{headlines.index('Sagsbehandler') + 2}]").text # eFlyt has an additional empty column before "Sagsbehandler"
8586

86-
case = Case(case_number, deadline, case_types, status, cpr, name, case_worker)
87-
cases.append(case)
87+
cases.append(Case(case_number, deadline, case_types, status, cpr, name, case_worker))
8888

8989
return cases
9090

tests/test_eflyt/test_search.py

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,39 @@ def setUpClass(cls):
2424

2525
def test_extract_cases(self):
2626
"""Extract cases and check we found what we expected"""
27-
eflyt_search.search(self.browser, date.today() - timedelta(days=2), date.today())
27+
eflyt_search.search(self.browser, date.today() - timedelta(days=2), date.today(), case_state="Afsluttet", case_status="Godkendt")
2828
cases = eflyt_search.extract_cases(self.browser)
2929

3030
self.assertGreater(len(cases), 0)
31-
case = cases[0]
32-
33-
self.assertIsInstance(case.case_number, str)
34-
self.assertIsInstance(case.case_types, list)
35-
self.assertIsInstance(case.deadline, (date, type(None)))
36-
self.assertIsInstance(case.status, str)
37-
self.assertIsInstance(case.cpr, str)
38-
self.assertRegex(case.cpr, r"\d{6}-\d{4}")
39-
self.assertIsInstance(case.name, str)
40-
self.assertGreater(len(case.name), 0)
41-
self.assertIsInstance(case.case_worker, str)
42-
self.assertGreater(len(case.case_worker), 0)
31+
for case in cases:
32+
self.assertIsInstance(case.case_number, str)
33+
self.assertIsInstance(case.case_types, list)
34+
self.assertIsInstance(case.deadline, (date, type(None)))
35+
self.assertIsInstance(case.status, str)
36+
self.assertIsInstance(case.cpr, str)
37+
self.assertRegex(case.cpr, r"\d{6}-\d{4}")
38+
self.assertIsInstance(case.name, str)
39+
self.assertGreater(len(case.name), 0)
40+
self.assertIsInstance(case.case_worker, str)
41+
self.assertGreater(len(case.case_worker), 0)
42+
43+
def test_extract_cases_deadline(self):
44+
"""Extract cases and check we found what we expected"""
45+
eflyt_search.search(self.browser, date.today() - timedelta(days=2), date.today(), case_status="Godkendt")
46+
cases = eflyt_search.extract_cases(self.browser)
47+
48+
self.assertGreater(len(cases), 0)
49+
for case in cases:
50+
self.assertIsInstance(case.case_number, str)
51+
self.assertIsInstance(case.case_types, list)
52+
self.assertIsInstance(case.deadline, (date, type(None)))
53+
self.assertIsInstance(case.status, str)
54+
self.assertIsInstance(case.cpr, str)
55+
self.assertRegex(case.cpr, r"\d{6}-\d{4}")
56+
self.assertIsInstance(case.name, str)
57+
self.assertGreater(len(case.name), 0)
58+
self.assertIsInstance(case.case_worker, str)
59+
self.assertGreater(len(case.case_worker), 0)
4360

4461
def test_open_case(self):
4562
"""Open a case and check the browser opened the case view"""

0 commit comments

Comments
 (0)