def test_unattach_validate_invalid_type(self, mocker):
        mock_request = mocker.MagicMock(data=dict(id='foobar'))
        serializer = SubListCreateAttachDetachAPIView()

        (sub_id, res) = serializer.unattach_validate(mock_request)

        assert type(res) is Response
    def test_unattach_validate_missing_id(self, mocker):
        mock_request = mocker.MagicMock(data=dict())
        serializer = SubListCreateAttachDetachAPIView()

        (sub_id, res) = serializer.unattach_validate(mock_request)

        assert sub_id is None
        assert type(res) is Response
    def test_unattach_validate_ok(self, mocker):
        mock_request = mocker.MagicMock(data=dict(id=1))
        serializer = SubListCreateAttachDetachAPIView()

        (sub_id, res) = serializer.unattach_validate(mock_request)

        assert sub_id == 1
        assert res is None
    def test_unattach_invalid(self, mocker):
        mock_request = mocker.MagicMock()
        mock_res = mocker.MagicMock()
        view = SubListCreateAttachDetachAPIView()
        view.unattach_validate = mocker.MagicMock()
        view.unattach_by_id = mocker.MagicMock()
        view.unattach_validate.return_value = (None, mock_res)

        view.unattach(mock_request)

        view.unattach_validate.assert_called_with(mock_request)
        view.unattach_by_id.assert_not_called()
    def test_unattach_ok(self, mocker):
        mock_request = mocker.MagicMock()
        mock_sub_id = mocker.MagicMock()
        view = SubListCreateAttachDetachAPIView()
        view.unattach_validate = mocker.MagicMock()
        view.unattach_by_id = mocker.MagicMock()
        view.unattach_validate.return_value = (mock_sub_id, None)

        view.unattach(mock_request)

        view.unattach_validate.assert_called_with(mock_request)
        view.unattach_by_id.assert_called_with(mock_request, mock_sub_id)