Example #1
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
Example #2
0
def test_save_with_regex():
    with open("email.txt") as file:
        email = file.read()

    mo = mock.mock_open()
    with mock.patch("{}.open".format(builtins_name), mo):
        clingy.save(email, glob="bar*")

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

    # Output file content
    handle = mo()
    assert mock.call(b"bar") in handle.write.mock_calls