-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
changed inout to a classstructure (#33)
* changed inout to a classstructure * edited tests * use instant of the class for better interface * update parse to run with inouthandler class --------- Co-authored-by: Inga Ulusoy <[email protected]>
- Loading branch information
1 parent
b67c25f
commit 95c4add
Showing
3 changed files
with
108 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,51 @@ | ||
from mailcom.inout import list_of_files, get_text, get_html_text | ||
from mailcom import inout | ||
import pytest | ||
from pathlib import Path | ||
from importlib import resources | ||
import datetime | ||
|
||
pkg = resources.files("mailcom") | ||
|
||
FILE_PATH = Path(pkg / "test" / "data" / "Bonjour Agathe.eml") | ||
|
||
TEXT_REF = "J'espère que tu vas bien!" | ||
|
||
def test_list_of_files_found(tmp_path): | ||
p = tmp_path / "test.eml" | ||
p.write_text("test") | ||
assert len(list_of_files(tmp_path)) != 0 | ||
@pytest.fixture() | ||
def get_instant(tmp_path): | ||
return inout.InoutHandler(tmp_path) | ||
|
||
def test_list_of_files_empty(tmp_path): | ||
def test_list_of_files(get_instant): | ||
with pytest.raises(ValueError): | ||
list_of_files(tmp_path) | ||
|
||
def test_list_of_files_dir_not_existing(): | ||
with pytest.raises(OSError): | ||
list_of_files("nonexistingDir") | ||
|
||
def test_list_of_files_correct_format(tmp_path): | ||
p = tmp_path / "test.eml" | ||
get_instant.list_of_files() | ||
p = get_instant.directory_name / "test.eml" | ||
p.write_text("test") | ||
p = tmp_path / "test2.html" | ||
get_instant.list_of_files() | ||
assert len(get_instant.email_list) != 0 | ||
get_instant2 = inout.InoutHandler("nonexistingDir") | ||
with pytest.raises(OSError): | ||
get_instant2.list_of_files() | ||
p = get_instant.directory_name / "test2.html" | ||
p.write_text("test2") | ||
p = tmp_path / "test3.xml" | ||
p = get_instant.directory_name / "test3.xml" | ||
p.write_text("test3") | ||
assert tmp_path / "test3.xml" not in list_of_files(tmp_path) | ||
get_instant.list_of_files() | ||
assert get_instant.directory_name / "test3.xml" not in get_instant.email_list | ||
|
||
def test_get_text(tmp_path): | ||
p = tmp_path / "test.eml" | ||
def test_get_text(get_instant): | ||
p = get_instant.directory_name / "test.eml" | ||
p.write_text("test") | ||
assert get_text(p) == 'test' | ||
text = get_text(FILE_PATH) | ||
print(text[0:25]) | ||
extracted_text = get_instant.get_text(p) | ||
assert extracted_text == 'test' | ||
text = get_instant.get_text(FILE_PATH) | ||
assert text[0:25] == TEXT_REF | ||
|
||
def test_get_text_err(): | ||
assert get_instant.email_content["date"] == datetime.datetime(2024, 4, 17, 15, 13, 56, tzinfo=datetime.timezone.utc) | ||
assert get_instant.email_content["attachment"] == 2 | ||
assert get_instant.email_content["attachement type"] == ['jpg', 'jpg'] | ||
with pytest.raises(OSError): | ||
list_of_files("nonexistingDir") | ||
get_instant.get_text(get_instant.directory_name / "nonexisting.eml") | ||
|
||
def test_get_html_text(): | ||
def test_get_html_text(get_instant): | ||
html = """<html><head><title>Test</title></head></html>""" | ||
assert get_html_text(html) == 'Test' | ||
|
||
def test_get_html_text_noHtml(): | ||
assert get_instant.get_html_text(html) == 'Test' | ||
noHtml = """Test""" | ||
assert get_html_text(noHtml) == 'Test' | ||
|
||
def test_get_text_no_file(tmp_path): | ||
p = tmp_path / "test.eml" | ||
with pytest.raises(OSError): | ||
get_text(p) | ||
assert get_instant.get_html_text(noHtml) == 'Test' |