Last active
March 15, 2017 08:55
-
-
Save LiamJolly/13443e7d48833f3a897d544722b0665c to your computer and use it in GitHub Desktop.
Testing using mocks and with form.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
import mock | |
import users | |
import file_utils | |
class UsersTest(unittest.TestCase): | |
_file_path = "INSERT_PATH_HERE" | |
def test_get_users(self): | |
user = "user1" | |
with mock.patch("file_utils.read_file", return_value=user) as mock_read: | |
result = users.get_users() | |
self.assertEqual(user, result) | |
mock_read.assert_called_once_with(self._file_path) | |
def test_get_users_whoops(self): | |
print file_utils.read_file | |
if __name__ == '__main__': | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment