Пример #1
0
def test_find_with_string():
    with open("email.txt") as file:
        attachments = clingy.find(file.read())

    assert len(attachments) == 2
    assert attachments[0].get_filename() == "foo.txt"
    assert attachments[1].get_filename() == "bar.txt"
Пример #2
0
def test_save_with_message_object():
    attachments = clingy.find("email.txt")

    mo = mock.mock_open()
    with mock.patch("{}.open".format(builtins_name), mo):
        clingy.save(attachments[0])

    # Output filenames
    assert mock.call("foo.txt", "wb") in mo.mock_calls

    # Output file content
    handle = mo()
    assert mock.call(b"foo") in handle.write.mock_calls
Пример #3
0
def test_find_with_regex():
    attachments = clingy.find("email.txt", regex=r"^foo")

    assert len(attachments) == 1
    assert attachments[0].get_filename() == "foo.txt"
Пример #4
0
def test_find_with_glob():
    attachments = clingy.find("email.txt", glob="foo*")

    assert len(attachments) == 1
    assert attachments[0].get_filename() == "foo.txt"
Пример #5
0
def test_find_with_filename():
    attachments = clingy.find("email.txt")

    assert len(attachments) == 2
    assert attachments[0].get_filename() == "foo.txt"
    assert attachments[1].get_filename() == "bar.txt"