diff --git a/changelog.md b/changelog.md index 5312897..d7b73d9 100644 --- a/changelog.md +++ b/changelog.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [2.11.1] - 2025-04-28 + +### Fixed + +- Eflyt case search now handles list of cases without a deadline + ## [2.11.0] - 2025-03-24 ### Changed @@ -214,7 +220,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Initial release -[Unreleased]: https://github.com/itk-dev-rpa/ITK-dev-shared-components/compare/2.11.0...HEAD +[Unreleased]: https://github.com/itk-dev-rpa/ITK-dev-shared-components/compare/2.11.1...HEAD +[2.11.1]: https://github.com/itk-dev-rpa/ITK-dev-shared-components/releases/tag/2.11.1 [2.11.0]: https://github.com/itk-dev-rpa/ITK-dev-shared-components/releases/tag/2.11.0 [2.10.0]: https://github.com/itk-dev-rpa/ITK-dev-shared-components/releases/tag/2.10.0 [2.9.0]: https://github.com/itk-dev-rpa/ITK-dev-shared-components/releases/tag/2.9.0 diff --git a/itk_dev_shared_components/eflyt/eflyt_search.py b/itk_dev_shared_components/eflyt/eflyt_search.py index b7f2268..d2cafbb 100644 --- a/itk_dev_shared_components/eflyt/eflyt_search.py +++ b/itk_dev_shared_components/eflyt/eflyt_search.py @@ -58,33 +58,33 @@ def extract_cases(browser: webdriver.Chrome) -> list[Case]: """ table = browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_GridViewSearchResult") rows = table.find_elements(By.TAG_NAME, "tr") + headlines = rows[0].text.split(" ") + # Remove header row rows.pop(0) cases = [] for row in rows: - deadline = row.find_element(By.XPATH, "td[3]/a").text - - # Convert deadline to date object - if deadline: - deadline = datetime.strptime(deadline, "%d-%m-%Y") - else: - deadline = None + deadline = None + if "Deadline" in headlines: + deadline_text = row.find_element(By.XPATH, f"td[{headlines.index('Deadline') + 1}]/a").text + # Convert deadline to date object + if len(deadline_text) > 0: + deadline = datetime.strptime(deadline_text, "%d-%m-%Y") - case_number = row.find_element(By.XPATH, "td[4]").text - case_types_text = row.find_element(By.XPATH, "td[5]").text + case_number = row.find_element(By.XPATH, f"td[{headlines.index('Sagsnr.') + 1}]").text + case_types_text = row.find_element(By.XPATH, f"td[{headlines.index('Flyttetype') + 1}]").text # If the case types ends with '...' we need to get the title instead if case_types_text.endswith("..."): - case_types_text = row.find_element(By.XPATH, "td[5]").get_attribute("Title") + case_types_text = row.find_element(By.XPATH, f"td[{headlines.index('Flyttetype') + 1}]").get_attribute("Title") case_types = case_types_text.split(", ") - status = row.find_element(By.XPATH, "td[6]").text - cpr = row.find_element(By.XPATH, "td[7]/a").text - name = row.find_element(By.XPATH, "td[8]").text - case_worker = row.find_element(By.XPATH, "td[10]").text + status = row.find_element(By.XPATH, f"td[{headlines.index('Status') + 1}]").text + cpr = row.find_element(By.XPATH, f"td[{headlines.index('CPR-nr.') + 1}]/a").text + name = row.find_element(By.XPATH, f"td[{headlines.index('Navn') + 1}]").text + case_worker = row.find_element(By.XPATH, f"td[{headlines.index('Sagsbehandler') + 2}]").text # eFlyt has an additional empty column before "Sagsbehandler" - case = Case(case_number, deadline, case_types, status, cpr, name, case_worker) - cases.append(case) + cases.append(Case(case_number, deadline, case_types, status, cpr, name, case_worker)) return cases diff --git a/pyproject.toml b/pyproject.toml index 4b122e4..6f6c3d7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "itk_dev_shared_components" -version = "2.11.0" +version = "2.11.1" authors = [ { name="ITK Development", email="itk-rpa@mkb.aarhus.dk" }, ] diff --git a/tests/test_eflyt/test_search.py b/tests/test_eflyt/test_search.py index 50a7215..8db0f2f 100644 --- a/tests/test_eflyt/test_search.py +++ b/tests/test_eflyt/test_search.py @@ -24,22 +24,39 @@ def setUpClass(cls): def test_extract_cases(self): """Extract cases and check we found what we expected""" - eflyt_search.search(self.browser, date.today() - timedelta(days=2), date.today()) + eflyt_search.search(self.browser, date.today() - timedelta(days=2), date.today(), case_state="Afsluttet", case_status="Godkendt") cases = eflyt_search.extract_cases(self.browser) self.assertGreater(len(cases), 0) - case = cases[0] - - self.assertIsInstance(case.case_number, str) - self.assertIsInstance(case.case_types, list) - self.assertIsInstance(case.deadline, (date, type(None))) - self.assertIsInstance(case.status, str) - self.assertIsInstance(case.cpr, str) - self.assertRegex(case.cpr, r"\d{6}-\d{4}") - self.assertIsInstance(case.name, str) - self.assertGreater(len(case.name), 0) - self.assertIsInstance(case.case_worker, str) - self.assertGreater(len(case.case_worker), 0) + for case in cases: + self.assertIsInstance(case.case_number, str) + self.assertIsInstance(case.case_types, list) + self.assertIsInstance(case.deadline, (date, type(None))) + self.assertIsInstance(case.status, str) + self.assertIsInstance(case.cpr, str) + self.assertRegex(case.cpr, r"\d{6}-\d{4}") + self.assertIsInstance(case.name, str) + self.assertGreater(len(case.name), 0) + self.assertIsInstance(case.case_worker, str) + self.assertGreater(len(case.case_worker), 0) + + def test_extract_cases_deadline(self): + """Extract cases and check we found what we expected""" + eflyt_search.search(self.browser, date.today() - timedelta(days=2), date.today(), case_status="Godkendt") + cases = eflyt_search.extract_cases(self.browser) + + self.assertGreater(len(cases), 0) + for case in cases: + self.assertIsInstance(case.case_number, str) + self.assertIsInstance(case.case_types, list) + self.assertIsInstance(case.deadline, (date, type(None))) + self.assertIsInstance(case.status, str) + self.assertIsInstance(case.cpr, str) + self.assertRegex(case.cpr, r"\d{6}-\d{4}") + self.assertIsInstance(case.name, str) + self.assertGreater(len(case.name), 0) + self.assertIsInstance(case.case_worker, str) + self.assertGreater(len(case.case_worker), 0) def test_open_case(self): """Open a case and check the browser opened the case view"""