Skip to content

Commit

Permalink
feat: Kingfisher Process removes collection_file_item table
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Nov 2, 2024
1 parent 6ec837e commit 6f846d0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 42 deletions.
17 changes: 1 addition & 16 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def collection_rows(kingfisher_process_cursor):


@pytest.fixture(scope="session")
def collection_file_item(kingfisher_process_cursor, collection_rows):
def collection_file(kingfisher_process_cursor, collection_rows):
kingfisher_process_cursor.execute(
"""\
INSERT INTO collection_file (
Expand All @@ -134,21 +134,6 @@ def collection_file_item(kingfisher_process_cursor, collection_rows):
{"collection_id": collection_rows[1]},
)
kingfisher_process_cursor.execute("SELECT MAX(id) FROM collection_file")
collection_file_id = kingfisher_process_cursor.fetchone()[0]

kingfisher_process_cursor.execute(
"""\
INSERT INTO collection_file_item (
number,
collection_file_id
) VALUES (
0,
%(collection_file_id)s
)
""",
{"collection_file_id": collection_file_id},
)
kingfisher_process_cursor.execute("SELECT MAX(id) FROM collection_file_item")
return kingfisher_process_cursor.fetchone()[0]


Expand Down
34 changes: 17 additions & 17 deletions tests/dataset/test_metadata_aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,34 @@
]


def create_compiled_release(cursor, collection_id, collection_file_item_id, data_rows):
def create_compiled_release(cursor, collection_id, collection_file_id, data_rows):
min_data_id, max_data_id = data_rows

cursor.execute(
"""\
INSERT INTO compiled_release (
ocid,
collection_id,
collection_file_item_id,
collection_file_id,
data_id,
release_date
) VALUES (
'ocds-lcuori-1',
%(collection_id)s,
%(collection_file_item_id)s,
%(collection_file_id)s,
%(max_data_id)s,
'2038'
), (
'ocds-lcuori-1',
%(collection_id)s,
%(collection_file_item_id)s,
%(collection_file_id)s,
%(min_data_id)s,
'1970'
)
""",
{
"collection_id": collection_id,
"collection_file_item_id": collection_file_item_id,
"collection_file_id": collection_file_id,
"min_data_id": min_data_id,
"max_data_id": max_data_id,
},
Expand Down Expand Up @@ -121,11 +121,11 @@ def test_get_kingfisher_metadata_tree(kingfisher_process_cursor, collection_rows


def test_get_kingfisher_metadata_compiled_release(
kingfisher_process_cursor, collection_rows, collection_file_item, data_rows, caplog
kingfisher_process_cursor, collection_rows, collection_file, data_rows, caplog
):
original, compiled = collection_rows

create_compiled_release(kingfisher_process_cursor, compiled, collection_file_item, data_rows)
create_compiled_release(kingfisher_process_cursor, compiled, collection_file, data_rows)

assert get_kingfisher_metadata(kingfisher_process_cursor, compiled) == {
"collection_metadata": {
Expand All @@ -150,11 +150,11 @@ def test_get_kingfisher_metadata_compiled_release(


def test_get_kingfisher_metadata_release(
kingfisher_process_cursor, collection_rows, collection_file_item, data_rows, data_and_package_data_rows, caplog
kingfisher_process_cursor, collection_rows, collection_file, data_rows, data_and_package_data_rows, caplog
):
original, compiled = collection_rows

create_compiled_release(kingfisher_process_cursor, compiled, collection_file_item, data_rows)
create_compiled_release(kingfisher_process_cursor, compiled, collection_file, data_rows)

data_id, package_data_id = data_and_package_data_rows

Expand All @@ -164,23 +164,23 @@ def test_get_kingfisher_metadata_release(
release_id,
ocid,
collection_id,
collection_file_item_id,
collection_file_id,
data_id,
package_data_id,
release_date
) VALUES (
'1',
'ocds-lcuori-1',
%(collection_id)s,
%(collection_file_item_id)s,
%(collection_file_id)s,
%(data_id)s,
%(package_data_id)s,
''
)
""",
{
"collection_id": original,
"collection_file_item_id": collection_file_item,
"collection_file_id": collection_file,
"data_id": data_id,
"package_data_id": package_data_id,
},
Expand Down Expand Up @@ -222,11 +222,11 @@ def test_get_kingfisher_metadata_release(


def test_get_kingfisher_metadata_record(
kingfisher_process_cursor, collection_rows, collection_file_item, data_rows, data_and_package_data_rows, caplog
kingfisher_process_cursor, collection_rows, collection_file, data_rows, data_and_package_data_rows, caplog
):
original, compiled = collection_rows

create_compiled_release(kingfisher_process_cursor, compiled, collection_file_item, data_rows)
create_compiled_release(kingfisher_process_cursor, compiled, collection_file, data_rows)

data_id, package_data_id = data_and_package_data_rows

Expand All @@ -235,20 +235,20 @@ def test_get_kingfisher_metadata_record(
INSERT INTO record (
ocid,
collection_id,
collection_file_item_id,
collection_file_id,
data_id,
package_data_id
) VALUES (
'ocds-lcuori-1',
%(collection_id)s,
%(collection_file_item_id)s,
%(collection_file_id)s,
%(data_id)s,
%(package_data_id)s
)
""",
{
"collection_id": original,
"collection_file_item_id": collection_file_item,
"collection_file_id": collection_file,
"data_id": data_id,
"package_data_id": package_data_id,
},
Expand Down
12 changes: 3 additions & 9 deletions tests/fixtures/kingfisher_process.sql
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,11 @@ CREATE TABLE IF NOT EXISTS collection_file (
collection_id bigint NOT NULL
);

CREATE TABLE IF NOT EXISTS collection_file_item (
id bigserial PRIMARY KEY,
number integer NOT NULL,
collection_file_id bigint NOT NULL
);

CREATE TABLE IF NOT EXISTS compiled_release (
id bigserial PRIMARY KEY,
ocid text NOT NULL,
collection_id bigint NOT NULL,
collection_file_item_id bigint NOT NULL,
collection_file_id bigint NOT NULL,
data_id bigint NOT NULL,
release_date text NOT NULL
);
Expand All @@ -58,7 +52,7 @@ CREATE TABLE IF NOT EXISTS record (
id bigserial PRIMARY KEY,
ocid text NOT NULL,
collection_id bigint NOT NULL,
collection_file_item_id bigint NOT NULL,
collection_file_id bigint NOT NULL,
data_id bigint NOT NULL,
package_data_id bigint NOT NULL
);
Expand All @@ -68,7 +62,7 @@ CREATE TABLE IF NOT EXISTS release (
release_id text NOT NULL,
ocid text NOT NULL,
collection_id bigint NOT NULL,
collection_file_item_id bigint NOT NULL,
collection_file_id bigint NOT NULL,
data_id bigint NOT NULL,
package_data_id bigint NOT NULL,
release_date text NOT NULL
Expand Down

0 comments on commit 6f846d0

Please sign in to comment.