@@ -34,19 +34,42 @@ def base_spec_kwargs(self) -> dict[str, Any]:
3434 def user_id (self ) -> str :
3535 return str (uuid4 ())
3636
37+ @pytest .fixture
38+ def spec_with_owner_label (
39+ self , base_spec_kwargs : dict [str , Any ], user_id : str
40+ ) -> ImageRowCreatorSpec :
41+ """Spec with owner label for USER scope."""
42+ return ImageRowCreatorSpec (
43+ ** base_spec_kwargs ,
44+ labels = {LabelName .CUSTOMIZED_OWNER : f"user:{ user_id } " },
45+ )
46+
47+ @pytest .fixture
48+ def spec_without_owner_label (self , base_spec_kwargs : dict [str , Any ]) -> ImageRowCreatorSpec :
49+ """Spec with unrelated label for GLOBAL scope."""
50+ return ImageRowCreatorSpec (
51+ ** base_spec_kwargs ,
52+ labels = {"other_label" : "value" },
53+ )
54+
55+ @pytest .fixture
56+ def spec_with_empty_labels (self , base_spec_kwargs : dict [str , Any ]) -> ImageRowCreatorSpec :
57+ """Spec with empty labels dict for GLOBAL scope."""
58+ return ImageRowCreatorSpec (** base_spec_kwargs , labels = {})
59+
60+ @pytest .fixture
61+ def spec_with_none_labels (self , base_spec_kwargs : dict [str , Any ]) -> ImageRowCreatorSpec :
62+ """Spec with None labels for GLOBAL scope."""
63+ return ImageRowCreatorSpec (** base_spec_kwargs , labels = None )
64+
3765 def test_build_with_owner_label_returns_user_scope (
3866 self ,
3967 adapter : ImageCreatorAdapter ,
40- base_spec_kwargs : dict [ str , Any ] ,
68+ spec_with_owner_label : ImageRowCreatorSpec ,
4169 user_id : str ,
4270 ) -> None :
4371 """Should return USER scope when owner label exists."""
44- spec = ImageRowCreatorSpec (
45- ** base_spec_kwargs ,
46- labels = {LabelName .CUSTOMIZED_OWNER : f"user:{ user_id } " },
47- )
48-
49- creator = adapter .build (spec )
72+ creator = adapter .build (spec_with_owner_label )
5073
5174 assert creator .scope_type == ScopeType .USER
5275 assert creator .scope_id == user_id
@@ -55,15 +78,10 @@ def test_build_with_owner_label_returns_user_scope(
5578 def test_build_without_owner_label_returns_global_scope (
5679 self ,
5780 adapter : ImageCreatorAdapter ,
58- base_spec_kwargs : dict [ str , Any ] ,
81+ spec_without_owner_label : ImageRowCreatorSpec ,
5982 ) -> None :
6083 """Should return GLOBAL scope when owner label is missing."""
61- spec = ImageRowCreatorSpec (
62- ** base_spec_kwargs ,
63- labels = {"other_label" : "value" },
64- )
65-
66- creator = adapter .build (spec )
84+ creator = adapter .build (spec_without_owner_label )
6785
6886 assert creator .scope_type == ScopeType .GLOBAL
6987 assert creator .scope_id == GLOBAL_SCOPE_ID
@@ -72,25 +90,21 @@ def test_build_without_owner_label_returns_global_scope(
7290 def test_build_with_empty_labels_returns_global_scope (
7391 self ,
7492 adapter : ImageCreatorAdapter ,
75- base_spec_kwargs : dict [ str , Any ] ,
93+ spec_with_empty_labels : ImageRowCreatorSpec ,
7694 ) -> None :
7795 """Should return GLOBAL scope when labels dict is empty."""
78- spec = ImageRowCreatorSpec (** base_spec_kwargs , labels = {})
79-
80- creator = adapter .build (spec )
96+ creator = adapter .build (spec_with_empty_labels )
8197
8298 assert creator .scope_type == ScopeType .GLOBAL
8399 assert creator .scope_id == GLOBAL_SCOPE_ID
84100
85101 def test_build_with_none_labels_returns_global_scope (
86102 self ,
87103 adapter : ImageCreatorAdapter ,
88- base_spec_kwargs : dict [ str , Any ] ,
104+ spec_with_none_labels : ImageRowCreatorSpec ,
89105 ) -> None :
90106 """Should return GLOBAL scope when labels is None."""
91- spec = ImageRowCreatorSpec (** base_spec_kwargs , labels = None )
92-
93- creator = adapter .build (spec )
107+ creator = adapter .build (spec_with_none_labels )
94108
95109 assert creator .scope_type == ScopeType .GLOBAL
96110 assert creator .scope_id == GLOBAL_SCOPE_ID
0 commit comments