Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion railib/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def _parse_multipart_form(
txn_file.name = name.group(1).decode()
filename = re.match(b'.*filename="(.+?)"', disposition)
if not (filename is None):
txn_file.filename = name.group(1).decode()
txn_file.filename = filename.group(1).decode()

result.append(txn_file)

Expand Down
Binary file added test/multipart.data
Binary file not shown.
39 changes: 38 additions & 1 deletion test/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from logging.config import fileConfig
from pathlib import Path
from railib import api, config

from unittest.mock import patch, MagicMock

# Get creds from env vars if exists
client_id = os.getenv("CLIENT_ID")
Expand Down Expand Up @@ -78,6 +78,43 @@ def test_v2_exec(self):
1, 8, 27, 64, 125], 'v4': [
1, 16, 81, 256, 625]}, rsp.results[0]["table"].to_pydict())

@patch('railib.rest.request')
def test_v2_exec_mocked(self, mock_urlopen):
# mock the multipart response
mocked_resp = MagicMock()
mocked_resp.headers.get.return_value = "multipart/form-data; boundary=b11385ead6144ee0a9550db3672a7ccf"
with open(os.path.join(Path(__file__).parent, "multipart.data"), "rb") as f:
mocked_resp.read.return_value = f.read()

mock_urlopen.return_value = mocked_resp

# run the current test
cmd = "x, x^2, x^3, x^4 from x in {1; 2; 3; 4; 5}"
rsp = api.exec_async(ctx, "mocked_db", "mocked_engine", cmd)

# transaction
self.assertEqual("COMPLETED", rsp.transaction["state"])

# metadata
with open(os.path.join(Path(__file__).parent, "metadata.pb"), "rb") as f:
data = f.read()
self.assertEqual(
rsp.metadata,
api._parse_metadata_proto(data)
)

# problems
self.assertEqual(0, len(rsp.problems))

# results
self.assertEqual(
{
'v1': [
1, 2, 3, 4, 5], 'v2': [
1, 4, 9, 16, 25], 'v3': [
1, 8, 27, 64, 125], 'v4': [
1, 16, 81, 256, 625]}, rsp.results[0]["table"].to_pydict())

def tearDown(self):
api.delete_engine(ctx, engine)
api.delete_database(ctx, dbname)
Expand Down