From af48b7a96843aeeab28f92311fcf2c3df7ad6ed0 Mon Sep 17 00:00:00 2001 From: Samir Gupta Date: Thu, 28 Sep 2023 11:52:31 +1000 Subject: [PATCH 1/7] add option select popup --- src/popups/OptionSelectPopup.py | 19 +++++++++++++++++++ src/popups/__init__.py | 2 ++ 2 files changed, 21 insertions(+) create mode 100644 src/popups/OptionSelectPopup.py diff --git a/src/popups/OptionSelectPopup.py b/src/popups/OptionSelectPopup.py new file mode 100644 index 0000000..26ab87f --- /dev/null +++ b/src/popups/OptionSelectPopup.py @@ -0,0 +1,19 @@ +from tkinter import Misc, ttk, W +from typing import Callable, TypeVar, Generic +from popups.Popup import Popup + +_T = TypeVar("_T") + + +class OptionSelectPopup(Popup, Generic[_T]): + def __init__(self, master: Misc | None, options: list[_T], callback: Callable[[_T], None], display: Callable[[_T], str] = str) -> None: + super().__init__(master, "Select Options", height_factor=0.5, columns=2) + self.callback = callback + + for row, option in enumerate(options): + ttk.Label(self, text=display(option)).grid(column=0, row=row, sticky=W) + ttk.Button(self, text="Select", command=lambda option=option: self._select(option)).grid(column=1, row=row) + + def _select(self, option: _T) -> None: + self.callback(option) + self.destroy() diff --git a/src/popups/__init__.py b/src/popups/__init__.py index 7c7b196..7492c6f 100644 --- a/src/popups/__init__.py +++ b/src/popups/__init__.py @@ -3,3 +3,5 @@ from popups.CalibrationHelpPopup import CalibrationHelpPopup from popups.ScriptSelectionPopup import ScriptSelectionPopup from popups.TestJobPopup import TestJobPopup +from popups.JobEntryPopup import JobEntryPopup +from popups.OptionSelectPopup import OptionSelectPopup From a713a9a1735848cdbdb542fd60d37d6f20334d39 Mon Sep 17 00:00:00 2001 From: Samir Gupta Date: Thu, 28 Sep 2023 11:53:10 +1000 Subject: [PATCH 2/7] ensure multiple options are handled properly --- src/gui/__init__.py | 2 +- src/gui/db_functions.py | 32 ++++++++++++-------------------- src/pages/TestPage.py | 24 ++++++++++++++---------- src/popups/JobEntryPopup.py | 19 +++++++++++++------ testing/test_db_functions.py | 14 +++++++------- 5 files changed, 47 insertions(+), 44 deletions(-) diff --git a/src/gui/__init__.py b/src/gui/__init__.py index 85f0d9c..518749f 100644 --- a/src/gui/__init__.py +++ b/src/gui/__init__.py @@ -8,4 +8,4 @@ get_click_position, get_selected_text, ) -from gui.db_functions import get_item, get_job +from gui.db_functions import get_items, get_jobs diff --git a/src/gui/db_functions.py b/src/gui/db_functions.py index 648ad17..65daa3b 100644 --- a/src/gui/db_functions.py +++ b/src/gui/db_functions.py @@ -16,38 +16,30 @@ def _get_connection(filename: str) -> Generator[sqlite3.Connection, None, None]: connection.close() -def get_item(item_number: str) -> Item | None: +def get_items(item_number: str) -> list[Item]: with _get_connection("SCMTests") as connection: - fields = connection.execute( + item_fields = connection.execute( """ SELECT logical_name, description, model, manufacturer, serial_no_, room, last_update FROM 'devicem1_PS' - WHERE logical_name == ? + WHERE logical_name LIKE ? """, - (item_number,), - ).fetchone() + (item_number + "%",), + ).fetchall() - if fields is None: - return None + return [Item(*fields) for fields in item_fields] - return Item(*fields) - - -def get_job(job_number: str) -> Job | None: - if not job_number.startswith("PM"): - job_number = f"PM{job_number}" +def get_jobs(job_number: str) -> list[Job]: with _get_connection("SCMLookup") as connection: - fields = connection.execute( + job_fields = connection.execute( """ SELECT company, location, dept, number FROM 'probsummarym1' - WHERE number == ? + WHERE number LIKE ? OR number LIKE ? """, - (job_number,), - ).fetchone() + (f"PM{job_number}%", f"{job_number}%"), + ).fetchall() - if fields is None: - return None + return [Job(*fields) for fields in job_fields] - return Job(*fields) diff --git a/src/pages/TestPage.py b/src/pages/TestPage.py index 3cb103b..628ffe9 100644 --- a/src/pages/TestPage.py +++ b/src/pages/TestPage.py @@ -10,10 +10,11 @@ from design.Test import TEST_RESULTS, ScriptError, Test from design.TestJob import TestJob from gui.actions import complete_test, turn_off_capslock -from gui.db_functions import get_item +from gui.db_functions import get_items from pages.Page import Page from popups.ScriptSelectionPopup import ScriptSelectionPopup from popups.TestJobPopup import TestJobPopup +from popups.OptionSelectPopup import OptionSelectPopup class TestPage(Page): @@ -26,13 +27,13 @@ def setup(self): item_entry.grid(column=2, row=1, sticky="w", columnspan=2) item_entry.focus() item_entry.icursor(tkinter.END) - self.go_button = ttk.Button(self.frame, text="Go", command=lambda: self.get_item(item_number.get(), item_entry)) + self.go_button = ttk.Button(self.frame, text="Go", command=lambda: self.get_items(item_number.get(), item_entry)) item_entry.bind("", lambda _: self.go_button.invoke()) self.go_button.grid(column=0, row=2, columnspan=2) - self.choose_button = ttk.Button(self.frame, text="Choose", command=lambda: self.get_item(item_number.get(), item_entry, choose_script=True)) + self.choose_button = ttk.Button(self.frame, text="Choose", command=lambda: self.get_items(item_number.get(), item_entry, choose_script=True)) self.choose_button.grid(column=2, row=2) button_state = "normal" if item_number.get() in self.shared.item_number_to_description else "disabled" - self.edit_button = ttk.Button(self.frame, text="Edit Test", command=lambda: self.get_item(item_number.get(), item_entry, editing=True), state=button_state) + self.edit_button = ttk.Button(self.frame, text="Edit Test", command=lambda: self.get_items(item_number.get(), item_entry, editing=True), state=button_state) self.edit_button.grid(column=3, row=2) item_number.trace_add("write", lambda _, __, ___: self.edit_button_reconfigure(item_number)) @@ -41,7 +42,7 @@ def edit_button_reconfigure(self, item_number: StringVar): tested = item_number.get() in self.shared.item_number_to_description self.edit_button.configure(state=("normal" if tested else "disabled")) - def get_item(self, item_number: str, item_entry: ttk.Entry, /, *, choose_script: bool = False, editing: bool = False) -> None: + def get_items(self, item_number: str, item_entry: ttk.Entry, /, *, choose_script: bool = False, editing: bool = False) -> None: item_entry.state(["disabled"]) # type: ignore self.frame.focus() assert self.shared.job @@ -49,15 +50,18 @@ def get_item(self, item_number: str, item_entry: ttk.Entry, /, *, choose_script: if editing and item_number not in self.shared.item_number_to_description: return self.item_not_found(item_number) - item = get_item(item_number) - if item is None: + items = get_items(item_number) + if not items: return self.reset_page(item_number) - - self.shared.item_number_to_description[item_number] = item.description self.is_editing = editing - self.get_test(item, choose_script=choose_script) + if len(items) == 1: + return self.get_test(items[0], choose_script=choose_script) + + OptionSelectPopup(self.frame, items, lambda item: self.get_test(item, choose_script=choose_script)) + def get_test(self, item: Item, *, choose_script: bool = False) -> None: + self.shared.item_number_to_description[item.number] = item.description if self.is_editing: assert self.shared.job try: diff --git a/src/popups/JobEntryPopup.py b/src/popups/JobEntryPopup.py index 8e99d97..d244fcd 100644 --- a/src/popups/JobEntryPopup.py +++ b/src/popups/JobEntryPopup.py @@ -1,8 +1,9 @@ from tkinter import Misc, StringVar, ttk from typing import Callable from design.Job import Job -from gui.db_functions import get_job +from gui.db_functions import get_jobs from popups.Popup import Popup +from popups.OptionSelectPopup import OptionSelectPopup class JobEntryPopup(Popup): @@ -16,13 +17,19 @@ def __init__(self, master: Misc | None, callback: Callable[[Job], None]) -> None entry.grid(column=1, row=0) entry.focus() - add_button = ttk.Button(self, text="Add", command=lambda: self._get_job(number.get())) + add_button = ttk.Button(self, text="Add", command=lambda: self._get_jobs(number.get())) add_button.grid(column=0, row=4, columnspan=2) - entry.bind("", lambda _: self._get_job(number.get())) + entry.bind("", lambda _: self._get_jobs(number.get())) - def _get_job(self, number: str) -> None: - job = get_job(number) - if job is None: + def _get_jobs(self, number: str) -> None: + jobs = get_jobs(number) + if not jobs: return + elif len(jobs) == 1: + return self._exit(jobs[0]) + + OptionSelectPopup(self, jobs, self._exit) + + def _exit(self, job: Job) -> None: self.callback(job) self.destroy() diff --git a/testing/test_db_functions.py b/testing/test_db_functions.py index 7747d63..1c72b21 100644 --- a/testing/test_db_functions.py +++ b/testing/test_db_functions.py @@ -2,17 +2,17 @@ import pytest -from gui.db_functions import get_item, get_job +from gui.db_functions import get_items, get_jobs class JobMock: - def fetchone(self) -> tuple[str, ...]: - return ("company", "location", "dept", "number") + def fetchall(self) -> list[tuple[str, ...]]: + return [("company", "location", "dept", "number")] class ItemMock: - def fetchone(self) -> tuple[str, ...]: - return ("number", "description", "model", "manufacturer", "serial", "room", "last_update") + def fetchall(self) -> list[tuple[str, ...]]: + return [("number", "description", "model", "manufacturer", "serial", "room", "last_update")] class sql_job: @@ -69,7 +69,7 @@ def mock_connect(_: str) -> sql_item: @pytest.mark.parametrize("job_number", ("23314115", "PM1242522")) def test_get_job(job_number: str, mock_sql_job: sql_job) -> None: - job = get_job(job_number) + job = get_jobs(job_number)[0] assert job assert job.campus == "location" assert job.department == "dept" @@ -80,7 +80,7 @@ def test_get_job(job_number: str, mock_sql_job: sql_job) -> None: def test_get_item(mock_sql_item: sql_job) -> None: - item = get_item("123456") + item = get_items("123456")[0] assert item assert item.description == "description" assert item.number == "number" From a0a7306311e2de03a86a0bf880ec743aff37d42e Mon Sep 17 00:00:00 2001 From: Samir Gupta Date: Thu, 28 Sep 2023 11:55:04 +1000 Subject: [PATCH 3/7] remove unnecessary defaults and show job number --- src/design/Item.py | 4 ++-- src/design/Job.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/design/Item.py b/src/design/Item.py index 4eebb5f..069776f 100644 --- a/src/design/Item.py +++ b/src/design/Item.py @@ -8,8 +8,8 @@ class Item: model: str = field(hash=False, eq=False) manufacturer: str = field(hash=False, eq=False) serial: str = field(hash=False, eq=False) - room: str = field(hash=False, eq=False, default="") - last_update: str = field(hash=False, eq=False, default="") + room: str = field(hash=False, eq=False) + last_update: str = field(hash=False, eq=False) def __str__(self) -> str: return f"{self.number} - {self.description}" diff --git a/src/design/Job.py b/src/design/Job.py index 7dd3e6e..993ad05 100644 --- a/src/design/Job.py +++ b/src/design/Job.py @@ -17,7 +17,7 @@ class Job: company: str = field(hash=False, eq=False, converter=_job_company_converter) campus: str department: str = field(hash=False, eq=False) - number: str = field(hash=False, eq=False, default="") + number: str = field(hash=False, eq=False) tests: list[Test] = field(factory=list, init=False, hash=False, eq=False) test_breakdown: dict[str, int] = field(factory=dict, init=False, hash=False, eq=False) @@ -32,4 +32,4 @@ def remove_test(self, test: Test) -> None: del self.test_breakdown[test.script.nickname] def __str__(self) -> str: - return f"{self.campus}\n{self.company}\n{self.department}" + return f"{self.campus}\n{self.company}\n{self.number}" From a3545abfc1fcb25d18233b21633697558bb0b738 Mon Sep 17 00:00:00 2001 From: Samir Gupta Date: Thu, 28 Sep 2023 16:38:31 +1000 Subject: [PATCH 4/7] make options into treeview --- src/popups/OptionSelectPopup.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/popups/OptionSelectPopup.py b/src/popups/OptionSelectPopup.py index 26ab87f..f4708fc 100644 --- a/src/popups/OptionSelectPopup.py +++ b/src/popups/OptionSelectPopup.py @@ -1,4 +1,5 @@ -from tkinter import Misc, ttk, W +from tkinter import Misc, ttk +import tkinter from typing import Callable, TypeVar, Generic from popups.Popup import Popup @@ -7,12 +8,20 @@ class OptionSelectPopup(Popup, Generic[_T]): def __init__(self, master: Misc | None, options: list[_T], callback: Callable[[_T], None], display: Callable[[_T], str] = str) -> None: - super().__init__(master, "Select Options", height_factor=0.5, columns=2) + super().__init__(master, "Select Options", height_factor=0.75, columns=2) self.callback = callback + tree = ttk.Treeview(self, show="tree") for row, option in enumerate(options): - ttk.Label(self, text=display(option)).grid(column=0, row=row, sticky=W) - ttk.Button(self, text="Select", command=lambda option=option: self._select(option)).grid(column=1, row=row) + tree.insert("", tkinter.END, row, text=display(option), open=row == 0) + + scrollbar = ttk.Scrollbar(self, orient=tkinter.VERTICAL, command=tree.yview) # type: ignore + tree.configure(yscroll=scrollbar.set) # type: ignore + scrollbar.grid(row=0, column=2, sticky=tkinter.NS) + tree.grid(row=0, column=0, columnspan=2, sticky=tkinter.EW) + + tree.bind("", lambda _: self._select(options[int(tree.focus())])) + tree.focus_set() def _select(self, option: _T) -> None: self.callback(option) From e88b218bd193a510cb63126cc33d2c03e23a3cad Mon Sep 17 00:00:00 2001 From: Samir Gupta Date: Thu, 28 Sep 2023 16:41:42 +1000 Subject: [PATCH 5/7] reformat --- src/gui/automations.py | 1 - src/gui/db_functions.py | 1 - src/pages/TestPage.py | 3 +-- src/popups/JobEntryPopup.py | 2 +- 4 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/gui/automations.py b/src/gui/automations.py index 4f1098a..c3b447d 100644 --- a/src/gui/automations.py +++ b/src/gui/automations.py @@ -12,7 +12,6 @@ mouse = None - _RUN = True # actually run the automations or get default value (for testing) _PRINT = False # print the automations (for testing) _DELAY = 0 # delay between automations (for testing) diff --git a/src/gui/db_functions.py b/src/gui/db_functions.py index 65daa3b..e7b10f0 100644 --- a/src/gui/db_functions.py +++ b/src/gui/db_functions.py @@ -42,4 +42,3 @@ def get_jobs(job_number: str) -> list[Job]: ).fetchall() return [Job(*fields) for fields in job_fields] - diff --git a/src/pages/TestPage.py b/src/pages/TestPage.py index 628ffe9..ff0acdb 100644 --- a/src/pages/TestPage.py +++ b/src/pages/TestPage.py @@ -56,9 +56,8 @@ def get_items(self, item_number: str, item_entry: ttk.Entry, /, *, choose_script self.is_editing = editing if len(items) == 1: return self.get_test(items[0], choose_script=choose_script) - + OptionSelectPopup(self.frame, items, lambda item: self.get_test(item, choose_script=choose_script)) - def get_test(self, item: Item, *, choose_script: bool = False) -> None: self.shared.item_number_to_description[item.number] = item.description diff --git a/src/popups/JobEntryPopup.py b/src/popups/JobEntryPopup.py index d244fcd..d591bb5 100644 --- a/src/popups/JobEntryPopup.py +++ b/src/popups/JobEntryPopup.py @@ -26,7 +26,7 @@ def _get_jobs(self, number: str) -> None: if not jobs: return elif len(jobs) == 1: - return self._exit(jobs[0]) + return self._exit(jobs[0]) OptionSelectPopup(self, jobs, self._exit) From 91b031cf4a0c473e2c1c6f883e175df926bb6644 Mon Sep 17 00:00:00 2001 From: Samir Gupta Date: Thu, 28 Sep 2023 16:43:24 +1000 Subject: [PATCH 6/7] string id --- src/popups/OptionSelectPopup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/popups/OptionSelectPopup.py b/src/popups/OptionSelectPopup.py index f4708fc..86f39df 100644 --- a/src/popups/OptionSelectPopup.py +++ b/src/popups/OptionSelectPopup.py @@ -13,7 +13,7 @@ def __init__(self, master: Misc | None, options: list[_T], callback: Callable[[_ tree = ttk.Treeview(self, show="tree") for row, option in enumerate(options): - tree.insert("", tkinter.END, row, text=display(option), open=row == 0) + tree.insert("", tkinter.END, f"{row}", text=display(option), open=row == 0) scrollbar = ttk.Scrollbar(self, orient=tkinter.VERTICAL, command=tree.yview) # type: ignore tree.configure(yscroll=scrollbar.set) # type: ignore From cba88e99f79bd9ef51f4b4fa812fc821c4ac1b57 Mon Sep 17 00:00:00 2001 From: Samir Gupta Date: Thu, 28 Sep 2023 16:56:47 +1000 Subject: [PATCH 7/7] edit testing --- testing/design/test_item.py | 12 +++++----- testing/design/test_job.py | 30 ++++++++++++------------- testing/design/test_test.py | 10 ++++----- testing/design/test_test_job_manager.py | 10 ++++----- testing/test_db_functions.py | 4 ++-- 5 files changed, 34 insertions(+), 32 deletions(-) diff --git a/testing/design/test_item.py b/testing/design/test_item.py index c93c97f..498a87b 100644 --- a/testing/design/test_item.py +++ b/testing/design/test_item.py @@ -3,25 +3,27 @@ def test_item_creation_and_properties(): - item = Item(number="123", description="Test Item", model="Model123", manufacturer="Test Manufacturer", serial="ABC456") + item = Item("123", "Test Item", "Model123", "Test Manufacturer", "ABC456", "RM1", "2019") assert item.number == "123" assert item.description == "Test Item" assert item.model == "Model123" assert item.manufacturer == "Test Manufacturer" assert item.serial == "ABC456" + assert item.room == "RM1" + assert item.last_update == "2019" def test_item_string_representation(): - item = Item(number="789", description="Another Item", model="Model789", manufacturer="Another Manufacturer", serial="DEF789") + item = Item("789", "Another Item", "Model789", "Another Manufacturer", "DEF789", "RM1", "2019") assert str(item) == "789 - Another Item" def test_item_hashing_and_eq(): - item1 = Item("111", "Item A", "ModelA", "ManufacturerA", "AAA111") - item2 = Item("222", "Item B", "ModelB", "ManufacturerB", "BBB222") - item3 = Item("111", "Item C", "ModelC", "ManufacturerC", "CCC333") + item1 = Item("111", "Item A", "ModelA", "ManufacturerA", "AAA111", "RM1", "2019") + item2 = Item("222", "Item B", "ModelB", "ManufacturerB", "BBB222", "RM1", "2019") + item3 = Item("111", "Item C", "ModelC", "ManufacturerC", "CCC333", "RM1", "2019") assert len({item1, item2}) == 2 assert len({item1, item3}) == 1 diff --git a/testing/design/test_job.py b/testing/design/test_job.py index 0e713c7..7bf7bbc 100644 --- a/testing/design/test_job.py +++ b/testing/design/test_job.py @@ -8,7 +8,7 @@ def test_job_creation_and_properties(): - job = Job("CAMPEYN - ABLE VICTORIA", "CampusA", "DepartmentY") + job = Job("CAMPEYN - ABLE VICTORIA", "CampusA", "DepartmentY", "123") assert job.company == "ABLE" assert job.campus == "CampusA" @@ -17,10 +17,10 @@ def test_job_creation_and_properties(): def test_job_add_test(): - job = Job("CompanyX", "CampusA", "DepartmentY") + job = Job("CompanyX", "CampusA", "DepartmentY", "123") - test1 = Test(Item("001", "Test Item 1", "ModelX", "ManufacturerX", "XYZ001")) - test2 = Test(Item("002", "Test Item 2", "ModelY", "ManufacturerY", "XYZ002")) + test1 = Test(Item("001", "Test Item 1", "ModelX", "ManufacturerX", "XYZ001", "RM1", "2019")) + test2 = Test(Item("002", "Test Item 2", "ModelY", "ManufacturerY", "XYZ002", "RM1", "2019")) custom1 = Script("Custom1", "Custom Script", (), exact_matches=["Test Item 1"]) SCRIPTS["Custom1"] = custom1 @@ -42,9 +42,9 @@ def test_job_add_test(): def test_job_remove_test() -> None: custom1 = Script("Custom1", "Custom Script", (), exact_matches=["Test Item 1"]) SCRIPTS["Custom1"] = custom1 - test1 = Test(Item("001", "Test Item 1", "ModelX", "ManufacturerX", "XYZ001")) + test1 = Test(Item("001", "Test Item 1", "ModelX", "ManufacturerX", "XYZ001", "RM1", "2019")) test1.script = test1.determine_script() - job = Job("CompanyX", "CampusA", "DepartmentY") + job = Job("CompanyX", "CampusA", "DepartmentY", "123") job.add_test(test1) job.remove_test(test1) @@ -55,19 +55,19 @@ def test_job_remove_test() -> None: def test_job_string_representation(): - job1 = Job("CAMPEYN - YOORALLA", "CampusA", "DepartmentY") - job2 = Job("BENETAS - ST PAULS", "CampusA", "DepartmentY") - job3 = Job("JEWISH ST KILDA", "CampusA", "DepartmentY") + job1 = Job("CAMPEYN - YOORALLA", "CampusA", "DepartmentY", "123") + job2 = Job("BENETAS - ST PAULS", "CampusA", "DepartmentY", "123") + job3 = Job("JEWISH ST KILDA", "CampusA", "DepartmentY", "123") - assert str(job1) == "CampusA\nCAMPEYN\nDepartmentY" - assert str(job2) == "CampusA\nBENETAS\nDepartmentY" - assert str(job3) == "CampusA\nJEWISH CARE\nDepartmentY" + assert str(job1) == "CampusA\nCAMPEYN\n123" + assert str(job2) == "CampusA\nBENETAS\n123" + assert str(job3) == "CampusA\nJEWISH CARE\n123" def test_job_hashing_and_eq(): - job1 = Job("CompanyX", "CampusA", "DepartmentY") - job2 = Job("CompanyY", "CampusB", "DepartmentZ") - job3 = Job("CompanyZ", "CampusA", "DepartmentZ") + job1 = Job("CompanyX", "CampusA", "DepartmentY", "123") + job2 = Job("CompanyY", "CampusB", "DepartmentZ", "123") + job3 = Job("CompanyZ", "CampusA", "DepartmentZ", "123") assert len({job1, job2}) == 2 assert len({job1, job3}) == 1 assert hash(job1) != hash(job2) diff --git a/testing/design/test_test.py b/testing/design/test_test.py index 8a7a5bb..81d2124 100644 --- a/testing/design/test_test.py +++ b/testing/design/test_test.py @@ -11,7 +11,7 @@ def test_test_creation_and_properties(): - item = Item("001", "Test Item", "ModelX", "ManufacturerX", "XYZ001") + item = Item("001", "Test Item", "ModelX", "ManufacturerX", "XYZ001", "RM1", "2019") test = Test(item) with pytest.raises(ScriptError): @@ -25,7 +25,7 @@ def test_test_creation_and_properties(): def test_test_determine_script(): - item = Item("001", "Test Item", "ModelX", "ManufacturerX", "XYZ001") + item = Item("001", "Test Item", "ModelX", "ManufacturerX", "XYZ001", "RM1", "2019") test = Test(item) # Adding a custom script for testing @@ -40,7 +40,7 @@ def test_test_determine_script(): def test_test_add_testjob(): - item = Item("001", "SLING 123", "ModelX", "ManufacturerX", "XYZ001") + item = Item("001", "SLING 123", "ModelX", "ManufacturerX", "XYZ001", "RM1", "2019") test = Test(item) test.script = test.determine_script() @@ -54,7 +54,7 @@ def test_test_add_testjob(): def test_test_complete_and_full_info(): - item = Item("001", "Test Item", "ModelX", "ManufacturerX", "XYZ001") + item = Item("001", "Test Item", "ModelX", "ManufacturerX", "XYZ001", "RM1", "2019") test = Test(item) custom = Script("CustomScript", "Custom Script", (), exact_matches=["Test Item"]) @@ -74,7 +74,7 @@ def test_test_complete_and_full_info(): def test_test_item_model_property(): - item = Item("001", "Test Item", "ModelX", "ManufacturerX", "XYZ001") + item = Item("001", "Test Item", "ModelX", "ManufacturerX", "XYZ001", "RM1", "2019") test = Test(item) test.script = Script("CustomScript", "Custom Script") diff --git a/testing/design/test_test_job_manager.py b/testing/design/test_test_job_manager.py index d13aed4..fedde05 100644 --- a/testing/design/test_test_job_manager.py +++ b/testing/design/test_test_job_manager.py @@ -10,8 +10,8 @@ def test_test_job_manager_multiple_testjobs(): manager = TestJobManager() - item1 = Item("001", "Test Item 1", "ModelX", "ManufacturerX", "XYZ001") - job1 = Job("Company", "Campus", "Department") + item1 = Item("001", "Test Item 1", "ModelX", "ManufacturerX", "XYZ001", "R1", "2019") + job1 = Job("Company", "Campus", "Department", "123") testjob1 = TestJob("Quality Control", "John Doe", "Performing testing on batch 1") testjob2 = TestJob("Quality Control", "Jane Smith", "Inspection for defects") @@ -31,9 +31,9 @@ def test_test_job_manager_multiple_testjobs(): def test_test_job_manager_multiple_items(): manager = TestJobManager() - item1 = Item("001", "Test Item 1", "ModelX", "ManufacturerX", "XYZ001") - item2 = Item("002", "Test Item 2", "ModelY", "ManufacturerY", "XYZ002") - job1 = Job("Company", "Campus", "Department") + item1 = Item("001", "Test Item 1", "ModelX", "ManufacturerX", "XYZ001", "RM1", "2019") + item2 = Item("002", "Test Item 2", "ModelY", "ManufacturerY", "XYZ002", "RM1", "2019") + job1 = Job("Company", "Campus", "Department", "123") testjob1 = TestJob("Quality Control", "John Doe", "Performing testing on batch 1") manager.add_testjob(item1, job1, testjob1) diff --git a/testing/test_db_functions.py b/testing/test_db_functions.py index 1c72b21..dce7cf7 100644 --- a/testing/test_db_functions.py +++ b/testing/test_db_functions.py @@ -75,7 +75,7 @@ def test_get_job(job_number: str, mock_sql_job: sql_job) -> None: assert job.department == "dept" assert job.number == "number" assert job.company == "company" - assert mock_sql_job.called_with[0].endswith(job_number) + assert job_number in mock_sql_job.called_with[0] assert mock_sql_job.close_called @@ -89,5 +89,5 @@ def test_get_item(mock_sql_item: sql_job) -> None: assert item.model == "model" assert item.serial == "serial" assert item.room == "room" - assert mock_sql_item.called_with[0].endswith("123456") + assert "123456" in mock_sql_item.called_with[0] assert mock_sql_item.close_called