memgraph/tests/e2e/load_csv/load_csv.py
Josipmrden 63f8298033
Fix MATCH + LOAD CSV to load CSV only once (#916)
* update profile query to use poolresource
* Optimize update of indexes
* Add ignore empty strings to load csv
* Add operator changes to support handling of nulls
* Store chunks in memory pools ordered
* Use same max block per chunks number
* Remove redundant return statement
* add hacky cached solution
* change map to set
* remove memory
* Add match load csv invalid behaviour commit
* Accept input on LOAD CSV
* Ommit changes not tied to the PR
* Add tests for match + load csv
* Add gqlalchemy installation for e2e tests
* Modify setup script to update packages
* Revert gqlalchemy to 1.3.3
* Revert gqlalchemy to 1.3.3
* Address PR review comments
* Ommit semicolon
---------

Co-authored-by: antoniofilipovic <filipovicantonio1998@gmail.com>
Co-authored-by: János Benjamin Antal <benjamin.antal@memgraph.io>
2023-06-21 11:13:40 +02:00

57 lines
1.6 KiB
Python

# Copyright 2022 Memgraph Ltd.
#
# Use of this software is governed by the Business Source License
# included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
# License, and you may not use this file except in compliance with the Business Source License.
#
# As of the Change Date specified in that file, in accordance with
# the Business Source License, use of this software will be governed
# by the Apache License, Version 2.0, included in the file
# licenses/APL.txt.
import os
import sys
from pathlib import Path
import pytest
from gqlalchemy import Memgraph
from mgclient import DatabaseError
SIMPLE_CSV_FILE = "simple.csv"
def get_file_path(file: str) -> str:
return os.path.join(Path(__file__).parent.absolute(), file)
def test_given_two_rows_in_db_when_load_csv_after_match_then_throw_exception():
memgraph = Memgraph("localhost", 7687)
with pytest.raises(DatabaseError):
next(
memgraph.execute_and_fetch(
f"""MATCH (n) LOAD CSV
FROM '{get_file_path(SIMPLE_CSV_FILE)}' WITH HEADER AS row
CREATE (:Person {{name: row.name}})
"""
)
)
def test_given_one_row_in_db_when_load_csv_after_match_then_pass():
memgraph = Memgraph("localhost", 7687)
results = memgraph.execute_and_fetch(
f"""MATCH (n {{prop: 1}}) LOAD CSV
FROM '{get_file_path(SIMPLE_CSV_FILE)}' WITH HEADER AS row
CREATE (:Person {{name: row.name}})
RETURN n
"""
)
assert len(list(results)) == 4
if __name__ == "__main__":
sys.exit(pytest.main([__file__, "-rA"]))