Skip to content

Commit

Permalink
fix(test): read csv files via csv library in sftp and ftp tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ohappykust committed Nov 19, 2024
1 parent 81d4a4f commit 486041a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
18 changes: 12 additions & 6 deletions tests/resources/ftp/ftp_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
Integration tests for FTP Network Resource.
"""

import csv
import io
from ftplib import FTP
from io import BytesIO

import pytest
from yarl import URL
Expand Down Expand Up @@ -101,14 +102,19 @@ def test_ftp_file_download(ftp_server):
"""
Test if the file exists and can be downloaded from the FTP server
"""
with BytesIO() as file_content:
with io.BytesIO() as file_content:
ftp_server.retrbinary("RETR /test.csv", file_content.write)
file_content.seek(0)
content = file_content.read()
data = file_content.read()

expected_content = (
expected_io = io.BytesIO(
b'"index","temperature","site"\r\n10.0,15.2,'
b'"Diamond_St"\r\n11.0,13.1,"Blacktail_Loop"\r\n12.0,13.3,'
b'"Platinum_St"\r\n13.0,12.1,"Kodiak_Trail"\r\n'
b'"Platinum_St"\r\n13.0,12.1,"Kodiak_Trail"\r\n',
)
assert content == expected_content
expected_csv = csv.reader(io.TextIOWrapper(expected_io, encoding="utf-8"))

result_io = io.BytesIO(data)
result_csv = csv.reader(io.TextIOWrapper(result_io, encoding="utf-8"))

assert list(expected_csv) == list(result_csv)
14 changes: 11 additions & 3 deletions tests/resources/sftp/sftp_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
Integration tests for SFTP Network Resource.
"""

import csv
import io

import pytest
from yarl import URL

Expand All @@ -26,12 +29,17 @@ def test_get_data_real(sftp_resource):
"""
data = sftp_resource.get_data()

expected_data = (
expected_io = io.BytesIO(
b'"index","temperature","site"\r\n10.0,15.2,'
b'"Diamond_St"\r\n11.0,13.1,"Blacktail_Loop"\r\n12.0,13.3,'
b'"Platinum_St"\r\n13.0,12.1,"Kodiak_Trail"\r\n'
b'"Platinum_St"\r\n13.0,12.1,"Kodiak_Trail"\r\n',
)
assert data == expected_data
expected_csv = csv.reader(io.TextIOWrapper(expected_io, encoding="utf-8"))

result_io = io.BytesIO(data)
result_csv = csv.reader(io.TextIOWrapper(result_io, encoding="utf-8"))

assert list(expected_csv) == list(result_csv)


@pytest.mark.slow_integration_test
Expand Down

0 comments on commit 486041a

Please sign in to comment.