HumanSignal / label-studio-sdk

Label Studio SDK
https://api.labelstud.io
Apache License 2.0
99 stars 61 forks source link

wondering about mocks for testing start_project #66

Closed tansaku closed 2 years ago

tansaku commented 2 years ago

I see there are a few tests in https://github.com/heartexlabs/label-studio-sdk/blob/master/tests/test_client.py for the client. I was wondering if a similar form could be used to test the start_project operation?

I had a go, but I'm not making much headway. If I use this form:

    with patch('requests.Session.request') as mocked_get:
        mocked_get.return_value.status_code = 201

I get a recursion warning:

../../../../.local/share/virtualenvs/label-studio-manager-YXK50_kR/lib/python3.10/site-packages/label_studio_sdk/project.py:107: in __getattr__
    return self._get_param(item)
../../../../.local/share/virtualenvs/label-studio-manager-YXK50_kR/lib/python3.10/site-packages/label_studio_sdk/project.py:257: in _get_param
    self.update_params()
../../../../.local/share/virtualenvs/label-studio-manager-YXK50_kR/lib/python3.10/site-packages/label_studio_sdk/project.py:342: in update_params
    self.params = self.get_params()
../../../../.local/share/virtualenvs/label-studio-manager-YXK50_kR/lib/python3.10/site-packages/label_studio_sdk/project.py:324: in get_params
    response = self.make_request('GET', f'/api/projects/{self.id}')
../../../../.local/share/virtualenvs/label-studio-manager-YXK50_kR/lib/python3.10/site-packages/label_studio_sdk/project.py:107: in __getattr__
    return self._get_param(item)
E   RecursionError: maximum recursion depth exceeded
!!! Recursion detected (same locals & position)

I can see debugging that a magic mock is returned as the response:

I thought maybe the problem what I needed to simulate the JSON returned from the server, so I ran against the real API, got the JSON and did the following: ``` with patch('requests.Session.request') as mocked_get: mocked_get.return_value.status_code = 201 mocked_get.json = JSON_RESPONSE ``` which had the same problem, but then I fixed it with this: ``` with patch('requests.Session.request') as mocked_get: mocked_get.return_value.status_code = 201 mocked_get.return_value.json.return_value = JSON_RESPONSE ``` so not an issue - just opening this issue as a record - will close as resolved