import unittest
from unittest.mock import patch

from concurrency.get_websites import load_url as load_url

class TestGetWebsites(unittest.TestCase):

    @patch('concurrency.get_websites.requests')
    def test_load_url(self, m):
        """ Check that we're getting the data from a request object """
        m.get = lambda req: {'text': 'foo'}
        data = load_url('fakeurl')
        self.assertEqual(data, 'foo')

if __name__ == "__main__":
    unittest.main()
import unittest
from unittest.mock import patch, MagicMock

from concurrency.get_websites import load_url as load_url

class TestGetWebsites(unittest.TestCase):

    @patch('concurrency.get_websites.requests')
    def test_load_url_returns_data(self, m):
        """ Check that we're getting the data from a request object """
        m.get = MagicMock(return_value={'text': 'foo'})
        data = data = load_url('fazzbear')
        self.assertEqual(data, 'foo')

    @patch('concurrency.get_websites.requests')
    def test_load_called_with_correct_url(self, m):
        """ Check that we're making the request with the url we pass """
        m.get = MagicMock(return_value={'text': 'foo'})
        data = load_url('fakeurl')
        m.get.assert_called_with('fakeurl')

if __name__ == "__main__":
    unittest.main()
Add a test case to see that we're making a request with the url we pass in
Add a test case to see that we're making a request with the url we pass in

  import unittest
- from unittest.mock import patch
+ from unittest.mock import patch, MagicMock
  
  from concurrency.get_websites import load_url as load_url
  
  class TestGetWebsites(unittest.TestCase):
  
      @patch('concurrency.get_websites.requests')
-     def test_load_url(self, m):
+     def test_load_url_returns_data(self, m):
          """ Check that we're getting the data from a request object """
-         m.get = lambda req: {'text': 'foo'}
+         m.get = MagicMock(return_value={'text': 'foo'})
+         data = data = load_url('fazzbear')
+         self.assertEqual(data, 'foo')
+ 
+     @patch('concurrency.get_websites.requests')
+     def test_load_called_with_correct_url(self, m):
+         """ Check that we're making the request with the url we pass """
+         m.get = MagicMock(return_value={'text': 'foo'})
          data = load_url('fakeurl')
-         self.assertEqual(data, 'foo')
+         m.get.assert_called_with('fakeurl')
  
  if __name__ == "__main__":
      unittest.main()
Add a test case to see that we're making a request with the url we pass in
## Code Before:
import unittest
from unittest.mock import patch

from concurrency.get_websites import load_url as load_url

class TestGetWebsites(unittest.TestCase):

    @patch('concurrency.get_websites.requests')
    def test_load_url(self, m):
        """ Check that we're getting the data from a request object """
        m.get = lambda req: {'text': 'foo'}
        data = load_url('fakeurl')
        self.assertEqual(data, 'foo')

if __name__ == "__main__":
    unittest.main()
## Instruction:
Add a test case to see that we're making a request with the url we pass in
## Code After:
import unittest
from unittest.mock import patch, MagicMock

from concurrency.get_websites import load_url as load_url

class TestGetWebsites(unittest.TestCase):

    @patch('concurrency.get_websites.requests')
    def test_load_url_returns_data(self, m):
        """ Check that we're getting the data from a request object """
        m.get = MagicMock(return_value={'text': 'foo'})
        data = data = load_url('fazzbear')
        self.assertEqual(data, 'foo')

    @patch('concurrency.get_websites.requests')
    def test_load_called_with_correct_url(self, m):
        """ Check that we're making the request with the url we pass """
        m.get = MagicMock(return_value={'text': 'foo'})
        data = load_url('fakeurl')
        m.get.assert_called_with('fakeurl')

if __name__ == "__main__":
    unittest.main()