Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement __eq__ for CreateFolderParent class #409

Open
supermitch opened this issue Dec 16, 2024 · 1 comment
Open

Implement __eq__ for CreateFolderParent class #409

supermitch opened this issue Dec 16, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@supermitch
Copy link

supermitch commented Dec 16, 2024

Is your feature request related to a problem? Please describe.

I'm trying to use unittest to check call args:

def test_create_folder_exists(box: BoxClient):
    with patch.object(box.folders, 'create_folder') as mock_create:
        mock_create.side_effect = [
            BoxAPIError(RequestInfo('POST', 'url', {}, {}), ResponseInfo(409, {}), '409'),
            'FolderFull',
        ]
        new_box.create_folder(
            box,
            PARENT_FOLDER_ID,
            'test_folder_829',
            increment=True,
        )
        assert mock_create.call_count == 2
        mock_create.assert_any_call(
                'test_folder_829 (1)',
                CreateFolderParent(PARENT_FOLDER_ID),  # THIS PART IS FAILING
        )

(I'm trying to check that my code increments folder names on collisions, like name (1), name (2), etc.)

Unfortunately, the assertion does NOT pass, because CreateFolderParent doesn't implement __eq__:

In [9]: from box_sdk_gen import CreateFolderParent
In [10]: a = CreateFolderParent('12')
In [11]: b = CreateFolderParent('12')
In [12]: a == b
Out[12]: False

Describe the solution you'd like

Adding basic equality check makes my tests pass:

    def __eq__(self, other):
        if isinstance(other, CreateFolderParent):
            return self.id == other.id
        return False

I guess it would be nice to implement this for all these "arg" classes in the library, as there are lots of them.

Describe alternatives you've considered

I can fix my current issues with deep assert equal of the create_folder_parent.id values.

@mwwoda
Copy link
Contributor

mwwoda commented Dec 17, 2024

Hi @supermitch

Thanks for creating this issue. I just spoke with the team and we have decided to add such features to our models. Unfortunately, I can't give you a precise timeframe for when this will happen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants