Пример #1
0
def test_get_body_from_file_travis(mocker):
    """
    GIVEN a call to messages via the CLI
    WHEN a message is specified by filename
    THEN assert the correct file operations are called and the kwds
        dict is updated
    """
    isfile_mock = mocker.patch.object(os.path, 'isfile')
    open_mock = mocker.patch.object(builtins, 'open')
    isfile_mock.return_value = True
    kwds = {'file': 'file.txt'}
    get_body_from_file(kwds)
    assert kwds['file'] is None
    assert 'body' in kwds.keys()
Пример #2
0
def test_get_body_from_file(tmpdir):
    """
    GIVEN a call to messages via the CLI
    WHEN a message is specified by filename
    THEN assert the file contents are read and set into the message body
        * this uses the tmpdir pytest built-in fixture to create temporary
          directory and file for the test
    """
    msg_file = tmpdir.join('msg.txt')
    msg_file.write('This is the message to send!')
    kwds = {'body': None, 'file': msg_file}
    body = get_body_from_file(kwds)
    assert kwds == {'body': 'This is the message to send!', 'file': None}