-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from samirg1/add-tests-through-db
Add tests through db
- Loading branch information
Showing
88 changed files
with
1,566 additions
and
1,365 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1 @@ | ||
pyautogui==0.9.54 | ||
pyperclip==1.8.2 | ||
pynput==1.7.6 | ||
attrs==23.1.0 | ||
attrs==23.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
pytest==7.4.0 | ||
mypy==1.5.0 | ||
mypy==1.6.1 | ||
tox==4.8.0 | ||
black==22.10.0 | ||
black==23.10.0 | ||
pytest-cov==4.1.0 | ||
attrs==23.1.0 | ||
pyautogui==0.9.54 | ||
pyperclip==1.8.2 | ||
pynput==1.7.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from datetime import datetime, timedelta | ||
|
||
from db.get_connection import DatabaseFilenames, get_connection | ||
from db.models import JobModel, ScriptLineModel, ScriptTesterModel, TestModel | ||
from design.Problem import Problem | ||
from design.Script import ScriptLine | ||
from design.Test import Test | ||
|
||
|
||
def add_test(test: Test, problem: Problem) -> None: | ||
next_spt_date = (datetime.now() + timedelta(days=366)).strftime(r"%Y-%m-%d %H:%M:%S.%f")[:-3] | ||
|
||
with get_connection(DatabaseFilenames.TESTS, mode="rw") as connection, get_connection(DatabaseFilenames.ASSETS, mode="rw") as asset_connection: | ||
with connection, asset_connection: | ||
TestModel(test, problem).insert(connection) | ||
ScriptTesterModel(test).insert(connection) | ||
|
||
lines = test.script.lines | ||
if test.script.number == 1287: | ||
track_header_line = ScriptLine(text="Disclaimer: Tests carried out are subject to conditions, available on request", number=1) | ||
lines = (track_header_line, *lines) | ||
|
||
for line in lines: | ||
ScriptLineModel(test, line).insert(connection) | ||
|
||
for job in test.jobs: | ||
JobModel(test, problem, job).insert(connection) | ||
|
||
asset_connection.execute( | ||
""" | ||
UPDATE DEVICEA4 | ||
SET service_last = ?, service_next = ? | ||
WHERE logical_name = ? AND service_type = ?; | ||
""", | ||
(test.date, next_spt_date, test.item.number, test.script.service_type), | ||
) | ||
|
||
services: list[tuple[str, float, str, str]] = asset_connection.execute( | ||
""" | ||
SELECT service_type, service_interval, service_last, service_next | ||
FROM DEVICEA4 | ||
WHERE logical_name = ?; | ||
""", | ||
(test.item.number,), | ||
).fetchall() | ||
|
||
servicearray = "\n".join("^".join(f"{int(s) if isinstance(s, float) else s}" for s in service) + "^" for service in services) | ||
|
||
connection.execute( | ||
""" | ||
UPDATE devicem1_PS | ||
SET last_spt_date = ?, next_spt_date = ?, servicearray = ? | ||
WHERE logical_name = ?; | ||
""", | ||
(test.date, next_spt_date, servicearray, test.item.number), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
from datetime import datetime | ||
|
||
|
||
def convert_stringed_date(date_string: str) -> datetime: | ||
"""Converts date from 023-10-05 15:12:23.260 format to datetime object""" | ||
def convert_stringed_date(date_string: str | None) -> datetime | None: | ||
"""Converts date from 2023-10-05 15:12:23.260 format to datetime object""" | ||
if date_string is None: | ||
return None | ||
return datetime.strptime(date_string[:-4], r"%Y-%m-%d %H:%M:%S") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from db.get_connection import get_connection, DatabaseFilenames | ||
from db.add_test import add_test | ||
from design.Problem import Problem | ||
from design.Test import Test | ||
|
||
|
||
def edit_test(test: Test, problem: Problem, *, remove_only: bool = False) -> None: | ||
with get_connection(DatabaseFilenames.TESTS, mode="rw") as connection: | ||
with connection: | ||
connection.execute("DELETE FROM SCMobileTestsm1 WHERE test_id = ?;", (test.id,)) | ||
connection.execute("DELETE FROM SCMobileTesterNumbersm1 WHERE test_id = ?", (test.id,)) | ||
connection.execute("DELETE FROM SCMobileTestLinesm1 WHERE test_id = ?", (test.id,)) | ||
connection.execute("DELETE FROM SCMProbsUploadm1 WHERE test_id = ?", (test.id,)) | ||
|
||
if not remove_only: | ||
add_test(test, problem) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,21 @@ | ||
import os | ||
import sqlite3 | ||
from contextlib import contextmanager | ||
from enum import StrEnum | ||
from typing import Generator, Literal | ||
import sqlite3 | ||
|
||
BASE_FILE = rf"C:\Users\{os.getenv('USERNAME')}\AppData\Local\SMXMobile" | ||
|
||
|
||
_BASE_FILE = rf"C:\Users\{os.getenv('USERNAME')}\AppData\Local\SMXMobile" | ||
class DatabaseFilenames(StrEnum): | ||
TESTS = "SCMTests" | ||
ASSETS = "SCMAssets" | ||
LOOKUP = "SCMLookup" | ||
SETTINGS = "Settings" | ||
|
||
|
||
@contextmanager | ||
def get_connection(filename: str, mode: Literal["ro", "rw"] = "ro") -> Generator[sqlite3.Connection, None, None]: | ||
connection = sqlite3.connect(rf"file:{_BASE_FILE}\{filename}.sdb?mode={mode}", uri=True) | ||
def get_connection(filename: DatabaseFilenames, *, mode: Literal["ro", "rw"] = "ro") -> Generator[sqlite3.Connection, None, None]: | ||
connection = sqlite3.connect(rf"file:{BASE_FILE}\{filename}.sdb?mode={mode}", uri=True) | ||
yield connection | ||
connection.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from db.get_connection import DatabaseFilenames, get_connection | ||
from design.Item import Item | ||
|
||
|
||
def get_items(item_number: str) -> list[Item]: | ||
with get_connection(DatabaseFilenames.TESTS) as connection: | ||
item_fields = connection.execute( | ||
""" | ||
SELECT logical_name, customer_barcode, description, model, manufacturer, serial_no_, room, last_spt_date | ||
FROM devicem1_PS | ||
WHERE logical_name LIKE ?; | ||
""", | ||
(item_number + "%",), | ||
).fetchall() | ||
|
||
return [Item(*fields) for fields in item_fields] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from db.get_connection import DatabaseFilenames, get_connection | ||
|
||
|
||
class NoTestIDsError(RuntimeError): | ||
... | ||
|
||
|
||
def get_new_test_id() -> str: | ||
with get_connection(DatabaseFilenames.SETTINGS, mode="rw") as connection: | ||
res: tuple[str, int, int] | None = connection.execute( | ||
""" | ||
SELECT TABLENAME, LASTUSED, LASTRESERVED | ||
FROM SCMIDTABLE | ||
WHERE TABLENAME == 'SCMobileTestsm1' AND LASTUSED <> LASTRESERVED; | ||
""" | ||
).fetchone() | ||
|
||
if res is None: | ||
raise NoTestIDsError | ||
|
||
_, current, end = res | ||
|
||
with connection: | ||
connection.execute( | ||
""" | ||
UPDATE SCMIDTABLE | ||
SET LASTUSED = ? | ||
WHERE TABLENAME == 'SCMobileTestsm1' AND LASTRESERVED = ?; | ||
""", | ||
(current + 1, end), | ||
) | ||
|
||
return f"SMX{str(current+1).zfill(10)}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from db.get_connection import DatabaseFilenames, get_connection | ||
from design.Problem import Problem | ||
|
||
|
||
def get_problems(problem_number: str) -> list[Problem]: | ||
with get_connection(DatabaseFilenames.LOOKUP) as connection: | ||
problem_fields = connection.execute( | ||
""" | ||
SELECT company, location, dept, number, customer_no_ | ||
FROM probsummarym1 | ||
WHERE number LIKE ? OR number LIKE ?; | ||
""", | ||
(f"PM{problem_number}%", f"{problem_number}%"), | ||
).fetchall() | ||
|
||
return [Problem(*fields) for fields in problem_fields] |
Oops, something went wrong.