Skip to content

Commit 3a8d225

Browse files
committed
fixed broken tests
1 parent 1ff0416 commit 3a8d225

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

functions-python/tasks_executor/src/tasks/licenses/populate_licenses.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
# 4. Supports a 'dry_run' mode, which simulates the process and logs intended
1919
# actions without committing any changes to the database.
2020
# 5. Includes error handling for network issues and database transactions.
21+
from datetime import datetime
2122
import logging
2223

24+
from pytz import timezone
2325
import requests
2426
from shared.database.database import with_db_session
2527
from shared.database_gen.sqlacodegen_models import License, Rule
@@ -86,8 +88,11 @@ def populate_licenses_task(dry_run, db_session):
8688
license_object = db_session.get(License, license_id)
8789
if not license_object:
8890
license_object = License(id=license_id)
91+
license_object.created_at = datetime.now(timezone.utc)
92+
8993
license_object.is_spdx = is_spdx
9094
license_object.name = spdx_data.get("name")
95+
license_object.updated_at = datetime.now(timezone.utc)
9196
cross_ref_list = spdx_data.get("crossRef")
9297
if (
9398
cross_ref_list

functions-python/tasks_executor/tests/tasks/populate_licenses_and_rules/test_populate_licenses.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import requests
55
from sqlalchemy.dialects.postgresql import JSONB
66
from sqlalchemy.ext.compiler import compiles
7+
from sqlalchemy.sql.functions import now
78
from shared.database.database import Session
89
from shared.database_gen.sqlacodegen_models import License, Rule
910
from tasks.licenses.populate_licenses import populate_licenses_task
@@ -17,6 +18,13 @@ def compile_jsonb_for_sqlite(element, compiler, **kw):
1718
return "TEXT"
1819

1920

21+
# This compilation rule translates the PostgreSQL-specific `now()` function into
22+
# the SQLite-compatible `CURRENT_TIMESTAMP` function during test schema creation.
23+
@compiles(now, "sqlite")
24+
def compile_now_for_sqlite(element, compiler, **kw):
25+
return "CURRENT_TIMESTAMP"
26+
27+
2028
# Mock data for GitHub API responses
2129
MOCK_LICENSE_LIST = [
2230
{

0 commit comments

Comments
 (0)