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

[((99, 150), 'unittest.mock.patch', 'patch', (['"""app.twitter_learning_journal.dao.os_env.os"""'], {}), "('app.twitter_learning_journal.dao.os_env.os')\n", (104, 150), False, 'from unittest.mock import patch\n'), ((379, 398), 'app.twitter_learning_journal.dao.os_env.os_environ', 'os_environ', (['"""a_key"""'], {}), "('a_key')\n", (389, 398), False, 'from app.twitter_learning_journal.dao.os_env import os_environ\n'), ((582, 601), 'app.twitter_learning_journal.dao.os_env.os_environ', 'os_environ', (['"""a_key"""'], {}), "('a_key')\n", (592, 601), False, 'from app.twitter_learning_journal.dao.os_env import os_environ\n'), ((745, 788), 'app.twitter_learning_journal.dao.os_env.os_environ', 'os_environ', (['"""a_key"""'], {'default': 'expected_value'}), "('a_key', default=expected_value)\n", (755, 788), False, 'from app.twitter_learning_journal.dao.os_env import os_environ\n')]