示例#1
0
 def test_get_unsupported(self):
     """
     Test a GET request with a resource that does not support it. Asserts that
     MethodNotSupportedException is raised.
     """
     mock_resource = MagicMock()
     mock_resource.SUPPORTED_METHODS = ()
     manager = ResourceManager(mock_resource, MagicMock())
     with pytest.raises(MethodNotSupportedException):
         manager.get(1)
示例#2
0
    def test_get(self, monkeypatch):
        """
        Test a successful GET request. Tests that manager.handle_response is being called with
        the correct Response object.
        """
        mock_resource = MagicMock()
        mock_client = MagicMock()
        mock_response = MagicMock()
        mock_client.get = MagicMock(return_value=mock_response)

        mock_resource.SUPPORTED_METHODS = ("GET",)

        manager = ResourceManager(mock_resource, mock_client)
        monkeypatch.setattr(manager, "handle_response", MagicMock())

        manager.get(1)

        # TODO test that this is called with correct path
        mock_client.get.assert_called_once()
        manager.handle_response.assert_called_once_with(mock_response)