22from collections import defaultdict
33from uuid import UUID , uuid4
44
5- from sqlalchemy import Column , Enum , ForeignKey , String , or_ , select
5+ from sqlalchemy import Boolean , Column , Enum , ForeignKey , String , and_ , or_ , select
66from sqlalchemy .dialects import postgresql
77from sqlalchemy .orm import aliased
8- from sqlalchemy .sql .functions import coalesce
98
109from testgen .common .models import get_current_session
1110from testgen .common .models .entity import Entity
@@ -29,13 +28,17 @@ class TestResult(Entity):
2928
3029 test_suite_id : UUID = Column (postgresql .UUID (as_uuid = True ), ForeignKey ("test_suites.id" ), nullable = False )
3130 test_run_id : UUID = Column (postgresql .UUID (as_uuid = True ), ForeignKey ("test_runs.id" ), nullable = False )
31+
3232 test_definition_id : UUID = Column (postgresql .UUID (as_uuid = True ), ForeignKey ("test_definitions.id" ), nullable = False )
3333 test_type : str = Column (String , ForeignKey ("test_types.test_type" ), nullable = False )
34+ auto_gen : bool = Column (Boolean )
35+
36+ schema_name : str = Column (String , nullable = False )
37+ table_name : str = Column (String )
38+ column_names : str = Column (String )
3439
3540 status : TestResultStatus = Column ("result_status" , Enum (TestResultStatus ))
36- message : str = Column ("result_message" , String , nullable = False )
37- table_name : str = Column (String , nullable = False )
38- column_names : str = Column (String , nullable = False )
41+ message : str = Column ("result_message" , String )
3942
4043 # Note: not all table columns are implemented by this entity
4144
@@ -44,9 +47,27 @@ def diff(cls, test_run_id_a: UUID, test_run_id_b: UUID) -> list[TestResultDiffTy
4447 alias_a = aliased (cls )
4548 alias_b = aliased (cls )
4649 query = select (
47- alias_a .status , alias_b .status , coalesce ( alias_a . test_definition_id , alias_b .test_definition_id ) ,
50+ alias_a .status , alias_b .status , alias_b .test_definition_id ,
4851 ).join (
49- alias_b , (alias_a .test_definition_id == alias_b .test_definition_id ), isouter = True , full = True ,
52+ alias_b ,
53+ or_ (
54+ and_ (
55+ alias_a .auto_gen .is_ (True ),
56+ alias_b .auto_gen .is_ (True ),
57+ alias_a .test_suite_id == alias_b .test_suite_id ,
58+ alias_a .schema_name == alias_b .schema_name ,
59+ alias_a .table_name .isnot_distinct_from (alias_b .table_name ),
60+ alias_a .column_names .isnot_distinct_from (alias_b .column_names ),
61+ alias_a .test_type == alias_b .test_type ,
62+ ),
63+ and_ (
64+ alias_a .auto_gen .isnot (True ),
65+ alias_b .auto_gen .isnot (True ),
66+ alias_a .test_definition_id == alias_b .test_definition_id ,
67+ ),
68+ ),
69+ isouter = True ,
70+ full = True ,
5071 ).where (
5172 or_ (alias_a .test_run_id == test_run_id_a , alias_a .test_run_id .is_ (None )),
5273 or_ (alias_b .test_run_id == test_run_id_b , alias_b .test_run_id .is_ (None )),
0 commit comments