from unittest.mock import patch

from app.twitter_learning_journal.dao.os_env import os_environ


@patch('app.twitter_learning_journal.dao.os_env.os')
def test_os_environ(mock_os):
    expected_value = 'environment_value'

    mock_os.environ.__contains__.return_value = True  # patch in statement
    mock_os.environ.__getitem__.return_value = expected_value

    os_variable = os_environ('a_key')

    assert expected_value == os_variable
    mock_os.environ.__getitem__.assert_called_with('a_key')


def test_os_environ_key_missing():
    expected_value = None
    os_variable = os_environ('a_key')

    assert expected_value == os_variable


def test_os_environ_key_missing_with_default():
    expected_value = 'a_default'
    os_variable = os_environ('a_key', default=expected_value)

    assert expected_value == os_variable

[((6, 1, 6, 52), 'unittest.mock.patch', 'patch', ({(6, 7, 6, 51): '"""app.twitter_learning_journal.dao.os_env.os"""'}, {}), "('app.twitter_learning_journal.dao.os_env.os')", False, 'from unittest.mock import patch\n'), ((13, 18, 13, 37), 'app.twitter_learning_journal.dao.os_env.os_environ', 'os_environ', ({(13, 29, 13, 36): '"""a_key"""'}, {}), "('a_key')", False, 'from app.twitter_learning_journal.dao.os_env import os_environ\n'), ((21, 18, 21, 37), 'app.twitter_learning_journal.dao.os_env.os_environ', 'os_environ', ({(21, 29, 21, 36): '"""a_key"""'}, {}), "('a_key')", False, 'from app.twitter_learning_journal.dao.os_env import os_environ\n'), ((28, 18, 28, 61), 'app.twitter_learning_journal.dao.os_env.os_environ', 'os_environ', (), '', False, 'from app.twitter_learning_journal.dao.os_env import os_environ\n')]