old_contents: import os.path
  import unittest
  import json
  
  import tpm
  from mock import patch
  
  class fake_req():
      links = []
      req = links
  
  def fake_request(self, path, action, data=''):
      """
      A stub urlopen() implementation that load json responses from
      the filesystem.
      """
      self.req = fake_req
      # Map path from url to a file
      resource_file = os.path.normpath('tests/resources/%s' %
                                       path)
      data_file = open(resource_file)
      data = json.load(data_file)
      # Must return a json-like object
      return data
  
  
  class ClientTestCase(unittest.TestCase):
      """Test case for the client methods."""
  
      def setUp(self):
          self.patcher = patch('tpm.TpmApiv4.request', fake_request)
          self.patcher.start()
          self.client = tpm.TpmApiv4('https://tpm.example.com', username='USER', password='PASS')
  
      def tearDown(self):
          self.patcher.stop()
  
      def test_request(self):
          """Test a list_projects."""
          response = self.client.list_projects()
          # number of projects is 5
          self.assertEqual(len(response), 5)
  
new_contents: import requests
  import requests_mock
  import unittest
  import os.path
  import tpm
  import json
  
  url = 'https://tpm.example.com/index.php/api/v4/projects.json'
  
  def fake_data(url, action, data=''):
      """
      A stub urlopen() implementation that load json responses from
      the filesystem.
      """
      # Map path from url to a file
      path_parts = url.split('/')[6:]
      path = ''
      for part in path_parts:
          path += '/' + part
      resource_file = os.path.normpath('tests/resources/%s' %
                                       path)
      data_file = open(resource_file)
      data = json.load(data_file)
      # Must return a json-like object
      return data
  
  class ClientTestCase(unittest.TestCase):
      """Test case for the client methods."""
  
  
      def setUp(self):
          self.client = tpm.TpmApiv4('https://tpm.example.com', username='USER', password='PASS')
  
      def test_request(self):
          """Test a list_projects."""
          with requests_mock.Mocker() as m:
              m.get(url, json=fake_data(url, 'post', data=''))
              response = self.client.list_projects()
          # number of projects is 5
          self.assertEqual(len(response), 5)
  
subject: change test based on requests_mock