1313"""
1414
1515import os
16+ from datetime import UTC , datetime
1617
1718import pytest
1819
2223from src .core .main import _sync_creatives_impl
2324from src .core .schemas import Creative as SchemaCreative
2425from src .core .schemas import SyncCreativesRequest
26+ from src .core .tool_context import ToolContext
2527from tests .utils .database_helpers import create_tenant_with_timestamps
2628
2729# Get creative agent URL from environment (docker-compose sets this)
@@ -73,28 +75,40 @@ def test_valid_creative_with_real_agent(self, integration_db):
7375 """
7476 # Create sync request with valid creative data
7577 # NOTE: These values depend on what formats the creative agent supports
78+ now = datetime .now (UTC )
7679 request = SyncCreativesRequest (
7780 creatives = [
7881 SchemaCreative (
7982 creative_id = "test_valid_creative" ,
8083 name = "Test Display Creative" ,
8184 content_uri = "https://example.com/ad-300x250.jpg" ,
85+ principal_id = "test_advertiser" ,
86+ created_at = now ,
87+ updated_at = now ,
8288 agent_url = CREATIVE_AGENT_URL ,
8389 format_id = "display_300x250" , # Standard IAB format
84- assets = {
85- "image_url" : "https://example.com/ad-300x250.jpg" ,
86- "click_url" : "https://example.com/click" ,
87- },
90+ assets = [
91+ {
92+ "type" : "image" ,
93+ "url" : "https://example.com/ad-300x250.jpg" ,
94+ }
95+ ],
96+ click_url = "https://example.com/click" ,
8897 )
8998 ]
9099 )
91100
92101 # Execute - this will call the REAL creative agent
102+ # NOTE: context=None means it will look up tenant/principal from database using auth
103+ # For integration tests, we just pass None and it will use test data
93104 response = _sync_creatives_impl (
94- tenant_id = "creative_agent_test" ,
95- principal_id = "test_advertiser" ,
96- creatives = request .creatives ,
97- operation = "create" ,
105+ creatives = [c .model_dump () for c in request .creatives ],
106+ patch = request .patch ,
107+ assignments = request .assignments ,
108+ delete_missing = request .delete_missing ,
109+ dry_run = request .dry_run ,
110+ validation_mode = request .validation_mode ,
111+ context = None , # Tests don't have auth context
98112 )
99113
100114 # Verify: Creative accepted and preview URL populated
@@ -116,25 +130,33 @@ def test_invalid_creative_rejected_by_agent(self, integration_db):
116130 This tests validation failures that come FROM the creative agent.
117131 """
118132 # Create sync request with INVALID creative data (missing required assets)
133+ now = datetime .now (UTC )
119134 request = SyncCreativesRequest (
120135 creatives = [
121136 SchemaCreative (
122137 creative_id = "test_invalid_creative" ,
123138 name = "Test Invalid Creative" ,
124139 content_uri = "https://example.com/placeholder.jpg" ,
140+ principal_id = "test_advertiser" ,
141+ created_at = now ,
142+ updated_at = now ,
125143 agent_url = CREATIVE_AGENT_URL ,
126144 format_id = "display_300x250" ,
127- assets = {} , # Missing image_url - should fail validation
145+ assets = [] , # Empty assets - should fail validation
128146 )
129147 ]
130148 )
131149
132150 # Execute - creative agent should reject this
151+ context = ToolContext (tenant_id = "creative_agent_test" , principal_id = "test_advertiser" )
133152 response = _sync_creatives_impl (
134- tenant_id = "creative_agent_test" ,
135- principal_id = "test_advertiser" ,
136- creatives = request .creatives ,
137- operation = "create" ,
153+ creatives = [c .model_dump () for c in request .creatives ],
154+ patch = request .patch ,
155+ assignments = request .assignments ,
156+ delete_missing = request .delete_missing ,
157+ dry_run = request .dry_run ,
158+ validation_mode = request .validation_mode ,
159+ context = context ,
138160 )
139161
140162 # Verify: Creative rejected
@@ -158,25 +180,33 @@ def test_creative_agent_unavailable(self, integration_db):
158180
159181 Then run this test to verify network error handling.
160182 """
183+ now = datetime .now (UTC )
161184 request = SyncCreativesRequest (
162185 creatives = [
163186 SchemaCreative (
164187 creative_id = "test_agent_down" ,
165188 name = "Test Agent Down Creative" ,
166189 content_uri = "https://example.com/ad.jpg" ,
190+ principal_id = "test_advertiser" ,
191+ created_at = now ,
192+ updated_at = now ,
167193 agent_url = CREATIVE_AGENT_URL ,
168194 format_id = "display_300x250" ,
169- assets = { "image_url " : "https://example.com/ad.jpg" },
195+ assets = [{ "type " : "image" , "url" : " https://example.com/ad.jpg" }] ,
170196 )
171197 ]
172198 )
173199
174200 # Execute - should fail with network error
201+ context = ToolContext (tenant_id = "creative_agent_test" , principal_id = "test_advertiser" )
175202 response = _sync_creatives_impl (
176- tenant_id = "creative_agent_test" ,
177- principal_id = "test_advertiser" ,
178- creatives = request .creatives ,
179- operation = "create" ,
203+ creatives = [c .model_dump () for c in request .creatives ],
204+ patch = request .patch ,
205+ assignments = request .assignments ,
206+ delete_missing = request .delete_missing ,
207+ dry_run = request .dry_run ,
208+ validation_mode = request .validation_mode ,
209+ context = context ,
180210 )
181211
182212 # Verify: Creative rejected with retry recommendation
0 commit comments