Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get overall results from db #78

Merged
merged 4 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/db/get_items_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def get_jobs(job_number: str) -> list[Job]:
with get_connection("SCMLookup") as connection:
job_fields = connection.execute(
"""
SELECT company, location, dept, number
SELECT company, location, dept, number, customer_no_
FROM 'probsummarym1'
WHERE number LIKE ? OR number LIKE ?
""",
Expand Down
22 changes: 22 additions & 0 deletions src/db/get_overall_results.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from typing import NamedTuple
from db.get_connection import get_connection


class TestResult(NamedTuple):
nickname: str
fullname: str


def get_overall_results(customer_id: int) -> list[TestResult]:
with get_connection("SCMLookup") as connection:
results: list[tuple[str, str]] = connection.execute(
"""
SELECT overall_id, overall_text
FROM SCMobileOverallm1
WHERE (customer_id IS NULL OR customer_id = ?) AND
(exclude_customer_id IS NULL OR exclude_customer_id NOT LIKE ?)
""",
(customer_id, f"%{customer_id},%"),
).fetchall()

return [TestResult(nickname, fullname) for nickname, fullname in results]
2 changes: 1 addition & 1 deletion src/db/set_favourites.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


def set_favourites() -> None:
with get_connection("Settings") as connection:
with get_connection("Settings", mode="rw") as connection:
with connection:
connection.execute("DELETE FROM ScriptFavourites")

Expand Down
1 change: 1 addition & 0 deletions src/design/Job.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Job:
campus: str
department: str = field(hash=False, eq=False)
number: str = field(hash=False, eq=False)
customer_number: int = field(hash=False, eq=False, converter=int)
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)

Expand Down
18 changes: 0 additions & 18 deletions src/design/Test.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,9 @@
from typing import NamedTuple

from design.data import get_all_scripts
from design.Item import Item
from design.Script import Script
from design.TestJob import TestJob


class _TEST_RESULT(NamedTuple):
name: str
result: str


TEST_RESULTS = [
_TEST_RESULT("Pass", "Passed"),
_TEST_RESULT("Defect", "Passed - needs attention to minor defect"),
_TEST_RESULT("Repaired", "Passed after minor repairs"),
_TEST_RESULT("Tagged", "Failed and RED Tagged"),
_TEST_RESULT("Removed", "Failed and removed from service"),
_TEST_RESULT("Untested", "Not Tested"),
_TEST_RESULT("Fail-Unable", "Fail - Unable to Test"),
]


class ScriptError(ValueError):
...

Expand Down
2 changes: 1 addition & 1 deletion src/design/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
from design.data import get_all_scripts, SCRIPT_DOWNS
from design.Item import Item
from design.Job import Job
from design.Test import Test, ScriptError, TEST_RESULTS
from design.Test import Test, ScriptError
from design.TestJob import TestJob
from design.TestJobManager import TestJobManager
16 changes: 10 additions & 6 deletions src/pages/TestPage.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
from design.Item import Item
from design.Job import Job
from design.Script import Script
from design.Test import TEST_RESULTS, ScriptError, Test
from design.Test import ScriptError, Test
from design.TestJob import TestJob
from gui.actions import complete_test, turn_off_capslock
from db.get_items_jobs import get_items
from db.get_overall_results import get_overall_results
from pages.Page import Page
from popups.ScriptSelectionPopup import ScriptSelectionPopup
from popups.TestJobPopup import TestJobPopup
Expand Down Expand Up @@ -83,6 +84,7 @@ def get_test(self, item: Item, *, choose_script: bool = False) -> None:
script_popup.mainloop()

def display_test(self, script: Script, test: Test) -> None:
assert self.shared.job
test.script = script
self.test = test
self.choose_button.destroy()
Expand All @@ -92,7 +94,7 @@ def display_test(self, script: Script, test: Test) -> None:

# displaying the item and job
ttk.Label(self.frame, text=f"{test.item}").grid(column=0, row=3, columnspan=4)
ttk.Label(self.frame, text=f"{cast(Job, self.shared.job).campus}").grid(column=0, row=4, columnspan=4)
ttk.Label(self.frame, text=f"{self.shared.job.campus}").grid(column=0, row=4, columnspan=4)
ttk.Label(self.frame, text=f"{'-' * 50}").grid(column=0, row=5, columnspan=4)

# displaying the script
Expand Down Expand Up @@ -147,10 +149,12 @@ def display_test(self, script: Script, test: Test) -> None:
# final results
ttk.Label(self.frame, text="Result").grid(column=0, row=row, columnspan=4)
row += 1
result = tkinter.StringVar(value=self.test.final_result or TEST_RESULTS[0].result)
for i, (name, test_result) in enumerate(TEST_RESULTS):
button = ttk.Radiobutton(self.frame, text=name, variable=result, value=test_result)
button.grid(column=i % 4, row=row)
overall_results = get_overall_results(self.shared.job.customer_number)
result = tkinter.StringVar(value=self.test.final_result or overall_results[0].nickname)
for i, (nickname, fullname) in enumerate(overall_results):
button = ttk.Radiobutton(self.frame, text=nickname, variable=result, value=fullname, width=15)
Tooltip(button, fullname)
button.grid(column=i % 4, row=row, columnspan=1)
row = row + 1 if i % 4 == 3 else row
row += 1

Expand Down
3 changes: 3 additions & 0 deletions src/popups/Tooltip.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ def _calculate_position(self, label: ttk.Label) -> tuple[int, int]:
if y_delta:
y1 = mouse_y - 5 - height

if x1 + self._wraplength > s_width:
x1 = s_width - self._wraplength

return x1, max(y1, 0)

def _show(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion testing/db/test_get_items_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from db.get_items_jobs import get_items, get_jobs
from testing.conftest import MockSqlObject

job = [("company", "campus", "department", "number")]
job = [("company", "campus", "department", "number", 123)]


@pytest.mark.parametrize(("job_number", "mock_sql_connect"), (["23314115", [job]], ["PM1242522", [job]]), indirect=["mock_sql_connect"])
Expand Down
17 changes: 17 additions & 0 deletions testing/db/test_get_results.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import pytest

from db.get_overall_results import get_overall_results
from testing.conftest import MockSqlObject


@pytest.mark.parametrize("mock_sql_connect", ([[("Pass", "Passed")]],), indirect=True)
def test_get_results(mock_sql_connect: MockSqlObject) -> None:
results = get_overall_results(123)

assert len(results) == 1
assert results[0] == ("Pass", "Passed")

args = mock_sql_connect.calls[0][1]
assert len(args) == 2
assert args[0] == 123
assert "123" in args[1]
20 changes: 11 additions & 9 deletions testing/design/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@


def test_job_creation_and_properties() -> None:
job = Job("CAMPEYN - ABLE VICTORIA", "CampusA", "DepartmentY", "123")
job = Job("CAMPEYN - ABLE VICTORIA", "CampusA", "DepartmentY", "123", 123)

assert job.company == "ABLE"
assert job.campus == "CampusA"
assert job.department == "DepartmentY"
assert job.number == "123"
assert job.customer_number == 123
assert len(job.tests) == 0


def test_job_add_test(mock_sql_connect_scripts: MockSqlObject) -> None:
job = Job("CompanyX", "CampusA", "DepartmentY", "123")
job = Job("CompanyX", "CampusA", "DepartmentY", "123", 123)

test1 = Test(Item("001", "Test Item 1", "ModelX", "ManufacturerX", "XYZ001", "RM1", "2019"))
test2 = Test(Item("002", "Test Item 2", "ModelY", "ManufacturerY", "XYZ002", "RM1", "2019"))
Expand All @@ -45,7 +47,7 @@ def test_job_remove_test(mock_sql_connect_scripts: MockSqlObject) -> None:
get_all_scripts()["Custom1"] = custom1
test1 = Test(Item("001", "Test Item 1", "ModelX", "ManufacturerX", "XYZ001", "RM1", "2019"))
test1.script = test1.determine_script()
job = Job("CompanyX", "CampusA", "DepartmentY", "123")
job = Job("CompanyX", "CampusA", "DepartmentY", "123", 123)
job.add_test(test1)
job.remove_test(test1)

Expand All @@ -55,19 +57,19 @@ def test_job_remove_test(mock_sql_connect_scripts: MockSqlObject) -> None:


def test_job_string_representation() -> None:
job1 = Job("CAMPEYN - YOORALLA", "CampusA", "DepartmentY", "123")
job2 = Job("BENETAS - ST PAULS", "CampusA", "DepartmentY", "123")
job3 = Job("JEWISH ST KILDA", "CampusA", "DepartmentY", "123")
job1 = Job("CAMPEYN - YOORALLA", "CampusA", "DepartmentY", "123", 123)
job2 = Job("BENETAS - ST PAULS", "CampusA", "DepartmentY", "123", 123)
job3 = Job("JEWISH ST KILDA", "CampusA", "DepartmentY", "123", 123)

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() -> None:
job1 = Job("CompanyX", "CampusA", "DepartmentY", "123")
job2 = Job("CompanyY", "CampusB", "DepartmentZ", "123")
job3 = Job("CompanyZ", "CampusA", "DepartmentZ", "123")
job1 = Job("CompanyX", "CampusA", "DepartmentY", "123", 123)
job2 = Job("CompanyY", "CampusB", "DepartmentZ", "123", 123)
job3 = Job("CompanyZ", "CampusA", "DepartmentZ", "123", 123)
assert len({job1, job2}) == 2
assert len({job1, job3}) == 1
assert hash(job1) != hash(job2)
Expand Down
4 changes: 2 additions & 2 deletions testing/design/test_test_job_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def test_test_job_manager_multiple_testjobs() -> None:
manager = TestJobManager()

item1 = Item("001", "Test Item 1", "ModelX", "ManufacturerX", "XYZ001", "R1", "2019")
job1 = Job("Company", "Campus", "Department", "123")
job1 = Job("Company", "Campus", "Department", "123", 123)
testjob1 = TestJob("Quality Control", "John Doe", "Performing testing on batch 1")
testjob2 = TestJob("Quality Control", "Jane Smith", "Inspection for defects")

Expand All @@ -33,7 +33,7 @@ def test_test_job_manager_multiple_items() -> None:

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")
job1 = Job("Company", "Campus", "Department", "123", 123)
testjob1 = TestJob("Quality Control", "John Doe", "Performing testing on batch 1")

manager.add_testjob(item1, job1, testjob1)
Expand Down