Compare commits
1 Commits
cpp23
...
MG_add_tes
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7ba7d77e59 |
@@ -7,6 +7,7 @@ function(copy_load_csv_e2e_files FILE_NAME)
|
||||
endfunction()
|
||||
|
||||
copy_load_csv_e2e_python_files(load_csv.py)
|
||||
copy_load_csv_e2e_python_files(content_server.py)
|
||||
copy_load_csv_e2e_files(simple.csv)
|
||||
|
||||
copy_load_csv_e2e_python_files(load_csv_nullif.py)
|
||||
|
||||
21
tests/e2e/load_csv/content_server.py
Normal file
21
tests/e2e/load_csv/content_server.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from http.server import BaseHTTPRequestHandler, HTTPServer
|
||||
|
||||
|
||||
class ContentServer:
|
||||
def __init__(self, content, compressor=None):
|
||||
content = content.encode("utf-8")
|
||||
if compressor is not None:
|
||||
content = compressor(content)
|
||||
self.content = content
|
||||
|
||||
def http_server(self):
|
||||
content = self.content
|
||||
|
||||
class Handler(BaseHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
self.send_response(200)
|
||||
self.send_header("Content-type", "text/plain")
|
||||
self.end_headers()
|
||||
self.wfile.write(content)
|
||||
|
||||
return HTTPServer(("", 0), Handler)
|
||||
@@ -9,11 +9,13 @@
|
||||
# by the Apache License, Version 2.0, included in the file
|
||||
# licenses/APL.txt.
|
||||
|
||||
import gzip
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from content_server import ContentServer
|
||||
from gqlalchemy import Memgraph
|
||||
from mgclient import DatabaseError
|
||||
|
||||
@@ -52,5 +54,43 @@ def test_given_one_row_in_db_when_load_csv_after_match_then_pass():
|
||||
assert len(list(results)) == 4
|
||||
|
||||
|
||||
def test_can_load_from_http_source():
|
||||
memgraph = Memgraph("localhost", 7687)
|
||||
|
||||
with open(get_file_path(SIMPLE_CSV_FILE), "r") as file:
|
||||
content = file.read()
|
||||
|
||||
with ContentServer(content).http_server() as server:
|
||||
host = server.server_address[0]
|
||||
port = server.server_address[1]
|
||||
endpoint = f"http://{host}:{port}"
|
||||
results = memgraph.execute_and_fetch(
|
||||
f"""LOAD CSV FROM '{endpoint}' WITH HEADER AS row
|
||||
CREATE (n:Person {{name: row.name}})
|
||||
RETURN n
|
||||
"""
|
||||
)
|
||||
assert len(list(results)) == 4
|
||||
|
||||
|
||||
def test_can_load_from_http_source_with_gzip_contents():
|
||||
memgraph = Memgraph("localhost", 7687)
|
||||
|
||||
with open(get_file_path(SIMPLE_CSV_FILE), "r") as file:
|
||||
content = file.read()
|
||||
|
||||
with ContentServer(content, gzip.compress).http_server() as server:
|
||||
host = server.server_address[0]
|
||||
port = server.server_address[1]
|
||||
endpoint = f"http://{host}:{port}"
|
||||
results = memgraph.execute_and_fetch(
|
||||
f"""LOAD CSV FROM '{endpoint}' WITH HEADER AS row
|
||||
CREATE (n:Person {{name: row.name}})
|
||||
RETURN n
|
||||
"""
|
||||
)
|
||||
assert len(list(results)) == 4
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(pytest.main([__file__, "-rA"]))
|
||||
|
||||
Reference in New Issue
Block a user